dsbgltg159136540 2014-08-24 00:52
浏览 33

mySQL无法建立与php的连接[重复]

I created a very simple database on mySQL using phpMyAdmin. Now I want to connect my database through php file so that I can manipulate data in DB, i.e. inserting, deleting, showing, updating data. I wrote the code:

index.php file:

    <?php
include 'includes/connection.php';
$query="SELECT * FROM people";
$result=mysql_query($query);
while($person= mysql_fetch_array($result)){
echo "<h3>". $person['name']."</h3>";

}
?>

connection.php file:

    <?php
$dbhost='localhost';
$dbuser='root';
$dbpass='';
$db='mysql_tut';
$conn=mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($db);

?>

But it shows the following error in the browser window:

 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\phpMyAdmin\index.php on line 5
</div>
  • 写回答

1条回答 默认 最新

  • dongzhan2029 2014-08-24 00:56
    关注

    You gotta pass two parameters to the function. The database name and the query.

    $conn = mysqli_connect($query, $query);
    

    I use mysqli_connect instead of mysql_connect becaouse mysql is deprecated.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看