drxrgundk062317205 2011-10-05 15:41
浏览 19
已采纳

为什么这个mysql连接失败了?

I am having an interesting problem with php and mysql.

I am trying to write a simple connect and query script to mysql on my localhost(same host as webserver) and am having some problems retrieving data, also anything that is below the php code disappears when you do a view source on the web site.

I am running apache2, I have installed php5 and other php commands work like echo.

Here is the php code:

<html>
<head>
<title>PHP Test</title>
</head>
<body>

<?php

  $con = mysql_connect("localhost", "user", "pass"); // corrected mysql spellings
  if(!$con)
    {
      die('could not connect to server: ' . mysql_error());
    }

  mysql_select_db("db", $con);

  $result = mysql_query("SELECT * FROM user_list");

  while($row = mysql_fetch_array($result))
  {
    echo $row['name'] . "<br />";
  }

  mysql_close($con);


  echo "hello";

?>

trying testing
</body>

</html>

Please let me know if there is anything I should check to see if my server setup is correct.

Thanks,

Andy

  • 写回答

3条回答 默认 最新

  • douzhang3356 2011-10-05 15:43
    关注

    You have written mysl_connect instead of mysql_connect on line 8.

    If you had error reporting turned on (which you should do only for development), you would have seen an error message telling you about this.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)