duanbinmi8970 2012-05-26 03:58
浏览 6
已采纳

关于PHP连接对象

Could somebody explain to me why the following is wrong :

$sql='SELECT * FROM images';
$hostname ='localhost';
$username= 'root';
$password= '';
$db= 'myDB';

$numRows=new mysqli($hostname, $username, $password, $db)->query($sql)-> num_rows;

The error throws is : syntax error, unexpected T_OBJECT_OPERATOR .....

and is it possible to correct it in one statement like above ? Thank you.

  • 写回答

2条回答 默认 最新

  • doupike2351 2012-05-26 04:53
    关注

    Chain after your instantiate mysqli.

    $m = new mysqli($hostname, $username, $password, $db);
    $numrows = $m->query($sql)->num_rows;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!