dongqing4070
2016-10-04 15:48
浏览 55
已采纳

php数据库连接错误[关闭]

I am trying to connect my PHP code to my sql backend, and I am coming across and error saying "Warning: mysqli_query() expects parameter 1 to be mysqli, string given in - on line 23 Error querying database."

I am following this guide. https://coolestguidesontheplanet.com/how-to-connect-to-a-mysql-database-with-php/

$link = mysqli_init();
$success = mysqli_real_connect(
   $link, 
   $host,
   $user, 
   $password, 
   $db,
   $port,
   $socket
) or die("error");


$query = "select * from Account_data";
mysqli_query($db, $query) or die('Error querying database.');

The first section(up to mysqli_querry) of the code works. However the syntax of the lines appears to be correct compared to the guide.

Any ideas?

Thanks in advance.

图片转代码服务由CSDN问答提供 功能建议

我正在尝试将我的PHP代码连接到我的sql后端,我遇到并错误地说“警告: mysqli_query()期望参数1为mysqli,在第23行中给出的字符串错误查询数据库。“

我遵循本指南。 https://coolestguidesontheplanet.com/how-to- connect-to-a-mysql-database-with-php /

  $ link = mysqli_init(); 
 $ success = mysqli_real_connect(
 $ link  ,
 $ host,
 $ user,
 $ password,
 $ db,
 $ port,
 $ socket 
)或die(“error”); 
 
 
 $ query =  “select * from Account_data”; 
mysqli_query($ db,$ query)或die('Error querying database。'); 
   
 
 

第一部分(最多 mysqli_querry)代码有效。 但是,与指南相比,这些行的语法似乎是正确的。

任何想法?

提前致谢。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dsy48837 2016-10-04 15:52
    已采纳

    As the documentation indicates, in procedural style, the first parameter must be of type mysqli. That is:

    $link = mysqli_init();
    $success = mysqli_real_connect(
       $link, 
       $host,
       $user, 
       $password, 
       $db,
       $port,
       $socket
    ) or die("error");
    
    
    $query = "select * from Account_data";
    mysqli_query($link, $query) or die('Error querying database.');
    
    打赏 评论

相关推荐 更多相似问题