开发者

Cannot select from database?

开发者 https://www.devze.com 2023-03-23 01:27 出处:网络
I\'m trying to select from my MySQL database, from the table Lines. I made it really simple, it should simply show all rows in the database. However I\'m getting an error on line 16 (I put an * next t

I'm trying to select from my MySQL database, from the table Lines. I made it really simple, it should simply show all rows in the database. However I'm getting an error on line 16 (I put an * next to it) that says: "mysql_fetch_array(): supplied argument is not a valid MySQL result resource"

$con = mysql_connect("...","...","mypass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  mysql_select_db("dbname", $con);
  $result = mysql_que开发者_StackOverflow社区ry("SELECT * FROM Lines");
  while($row = mysql_fetch_array( $result )) ***************
  { 
  echo $row['Text'];
  echo "<br />";
  } 
  mysql_close($con);

What am I doing wrong? Thanks


Lines is a reserved word in MySQL. Use backticks.

SELECT * FROM `Lines`


Add mysql_error() after mysql_query() to see if there's any error, I'm guessing table Lines doesn't exist:

$con = mysql_connect("copoetry.db.6945202.hostedresource.com","dbname","mypass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  mysql_select_db("dbname", $con);
  $result = mysql_query("SELECT * FROM Lines");
  echo mysql_error(); die;
  while($row = mysql_fetch_array( $result )) ***************
  { 
  echo $row['Text'];
  echo "<br />";
  } 
  mysql_close($con);
0

精彩评论

暂无评论...
验证码 换一张
取 消