wamp64 mysql更改端口号后网页中无法访问数据库


前言

上篇文章更改完mysql的端口号后网页无法连接数据库,按提示查看文档 “帮助->MatiaDB-MySQL",即点击下图中的“帮助->MatiaDB-MySQL"

在这里插入图片描述
在这里插入图片描述


文档说明

第二项说明“The default Database manager port is 3306. Connections that do not specify the port number will always be on the default port.”,意为默认连接数据库的端口号为3306

在这里插入图片描述

The default Database manager port is 3306. Connections that do not specify the port number will always be on the default port.
If the database manager (MySQL or MariaDB) you want to use is not the default one, it is therefore imperative to specify the port number in connection requests since it will not be using the default port 3306. We repeat, without specifying the port, it will be the default port that will be used, so 3306.
Normally, connection scripts do not mention the port to use. For example:
$mysqli = new mysqli('127.0.0.1', 'user', 'password', 'database');
or, in procedural :
$mysqli = mysqli_connect('127.0.0.0.1', 'user', 'password', 'database');

So, to connect with a manager that doesn't use port 3306, you have to specify the port number on the connection request:
$mysqli = new mysqli('127.0.0.1', 'user', 'password', 'database', '3307');
or, procedurally:
$mysqli = mysqli_connect('127.0.0.0.1', 'user', 'password', 'database', '3307');

To check the connections on the MySQL or MariaDB database manager, use the script:
wamp(64)\www\testmysql.php
by putting 'http://localhost/testmysql.php' in the browser address bar having first modified the script according to your parameters.

当你使用以下代码,即省略了端口号的方式连接数据库时,程序会以3306访问数据库

$mysqli = new mysqli('127.0.0.1', 'user', 'password', 'database');

或者

$mysqli = mysqli_connect('127.0.0.0.1', 'user', 'password', 'database');

解决方法

将网页文件中连接数据库的语句加上目前mysql或MariaDB使用的端口号即可

$mysqli = new mysqli('127.0.0.1', 'user', 'password', 'database', '3307');

或者

$mysqli = mysqli_connect('127.0.0.0.1', 'user', 'password', 'database', '3307');
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值