我想用php7连接到旧的mysql服务器(服务器是4.0.20标准)。升级mysql服务器或降级php不是一个选项。
我正在做这个:$conn = mysqli_connect($local,$user,$pwd,$db,$port);,但是我得到了这个错误:Warning: mysqli_connect(): Connecting to 3.22, 3.23 & 4.0 is not supported. Server is 4.0.20-standard。这是可能的吗?
发布于 2021-08-18 06:04:29
mysql原生客户端(Mysqlnd)自php 5.4以来一直是默认的mysql驱动程序,它不支持旧的mysql服务器,如果你仍然想连接到旧版本的mysql服务器,你应该使用另一个mysql驱动程序libmysqlclient,这需要用php编译。
下面是这两个驱动程序的介绍:
https://dev.mysql.com/doc/apis-php/en/apis-php-mysqlinfo.library.choosing.html
我建议您使用libmysqlclient构建您的mysqli,使用官方推荐的默认版本mysqlnd构建您的pdo,这样您就可以连接到两个版本的mysql服务器。
发布于 2017-08-28 07:00:46
解决方案(教育解决方案,请勿在生产环境中使用此解决方案):
步骤1:在php7机器上安装putty.exe + plink.exe。步骤2:我创建了these methods来为您/我做所有的工作。Example1:
$query = "SELECT * FROM user";
$rs = select($query);
if($rs)
for($index = 0; $index < count($rs);$index++){
//ALWAYS use this. Now u can use that array like a normal resultset $rs["lalala"]
$row1 = $rs[$index];
//use this like usual
echo $rs["username"];
}Example2:
$query = "SELECT * FROM user";
$rs = select($query);
if($rs)
for($index = 0; $index < count($rs);$index++){
//ALWAYS use this. Now u can use that array like a normal resultset $rs["lalala"]
//$row1 = $rs[$index];
//now you didn't the line above...
echo $rs[$index]["username"];//you'll need something like $rs[0]["username"]
}对于update/delete/insert,您可以使用与insert方法类似的方法。示例3:
if(m_insert("insert into user (name,pwd,email) values ('kkk', 'hahaha', 'email@lala.com');")){
echo "</br>true</br>";
} else {
echo "</br>false</br>";
}Remember1:您需要更改方法变量(主机、数据库、用户名、密码等)...mysql :更改此行$commands[0] = 'mysql -u username -pPASSWORD...'的Remember2凭据
https://stackoverflow.com/questions/45900523
复制相似问题