duanhuihui2705 2011-07-27 10:59
浏览 31
已采纳

基本的php问题 - 连接数据库

i literally just started looking into php, connecting to a remote database and returning data. I have been following a tutorial however when i apply the same code (as on the tutorial), i get

Server error

The website encountered an error while retrieving http://localhost:8888/file.php. It may be down for maintenance or configured incorrectly. Here are some suggestions: Reload this web page later.

This is the script - the database connection is fine, i believe its the retrieval of data that causes the error but have no idea on how to fix it ..

  <?php

   // Database credentials
   $host = "localhost"; 
   $db = "json"; 
   $uid = "json"; 
   $pwd = "json1";

    // Connect to the database server   
    $link = mysql_connect($host, $uid, $pwd) or die("Could not connect");

   //select the json database
   mysql_select_db($db) or die("Could not select database");


// Create an array to hold our results
   $arr = array();
   //Execute the query
   $rs = mysql_query("SELECT id,userid,firstname,lastname,email FROM users");

   // Add the rows to the array 
   while($obj = mysql_fetch_object($rs)) {
   $arr[] = $obj;

?>
  • 写回答

2条回答 默认 最新

  • doujiu9307 2011-07-27 11:04
    关注

    At the end of your script, you have this :

    // Add the rows to the array 
       while($obj = mysql_fetch_object($rs)) {
       $arr[] = $obj;
    
    ?>
    

    You are opening { on the while line ; but never closing it.

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

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改