duanmiyang6201 2017-07-11 16:05
浏览 70
已采纳

mysql请求用PHP 7.1返回null,而5.3用ok

I'm facing a weird trouble.

I just installed a new virtual server with apache / php 7.1 in order to prepare the migration of my old virtual webserver running php 5.3.3. The reason is I need to install prestashop that requires php 5.4 (minimum requirement).

Both virtual servers are running centos 6 on the same HN.

PHP 7.1 comes from remi repos.

I ran this code on both VMs (CLI):

<?php
$mysql = new mysqli($mysql_adress, $mysql_login, $mysql_pwd, $mysql_database);
if($mysql->connect_error){
    echo 'connect error : '.$mysql->connect_error;
} else {
    $return = $mysql->query("SELECT DATABASE()");
    $row = mysqli_fetch_array($return, MYSQL_ASSOC);
    var_dump($row);
}
?>

My 'old' server returns the name of the database i am connected to (it is the expected result) but the new server returns NULL !

I suspect the mysqlnd client to be responsible for this behaviour but not sure.

Any idea appreciated !

  • 写回答

1条回答 默认 最新

  • dongtuji0992 2017-07-11 17:18
    关注

    Problem solved ! Thank to @yanman1234.

    MYSQL_ASSOC used to work with a mysqli object in the previous versions of php . This time is over and i should now use MYSQLI_ASSOC instead.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置