XAMPP控制面板无报错但MySQL无法启动,PHP路由捕获异常的问题求助
XAMPP控制面板无报错但MySQL无法启动,PHP路由捕获异常的问题求助
Hey 各位大佬,我最近在学PHP,用XAMPP搭MySQL环境做第二个跟着教程走的项目,结果碰到个头疼的问题,想请大家帮忙分析分析!
情况是这样的:XAMPP控制面板里所有服务看起来都正常启动了,但MySQL就是连不上,我在index.php里写的路由try-catch块直接捕获到了错误。我已经试过几种调整方法了:
- 在XAMPP的「Config -> Service and Port Settings」里修改了MySQL的默认端口,同时把Apache的80端口改成了8080
- 也手动修改了
my.ini里的MySQL端口配置
但不管怎么改,问题还是一模一样,完全没变化。对了,这个路由是我自己写的学习用的,不是生产环境的,就是想搞懂路由的工作原理,没想到卡在数据库连接这儿了。
下面是我的index.php代码,麻烦大家帮我看看有没有哪里不对:
require __DIR__ . '/../../vendor/autoload.php'; use App\View; session_start(); define('STORAGE_PATH', __DIR__ . '/../storage'); define('VIEW_PATH', __DIR__ . '/../views'); try { $router = new App\Exceptions\Router(); $router ->get('/', [App\Controllers\HomeController::class, 'index']) ->post('/upload', [App\Controllers\HomeController::class, 'upload']) ->get('/invoices', [App\Controllers\InvoiceController::class, 'index']) ->get('/invoices/create', [App\Controllers\InvoiceController::class, 'create']) ->post('/invoices/create', [App\Controllers\InvoiceController::class, 'store']); echo $router->resolve($_SERVER['REQUEST_URI'], strtolower($_SERVER['REQUEST_METHOD'])); } catch (\App\Exceptions\RouteNotFoundException $e) { // header('HTTP/1.1 404 Not found'); http_response_code(404); echo View::make('error/404'); }
有没有大佬能给点排查思路或者解决方案?万分感谢!
备注:内容来源于stack exchange,提问作者Gad Ashell
相关产品推荐
相关产品推荐

