Home >Backend Development >PHP Tutorial >php中mysql_query 返回值失误

php中mysql_query 返回值失误

WBOY
WBOYOriginal
2016-06-13 10:30:59930browse

php中mysql_query 返回值出错
  $conn=mysql_connect("localhost","root","root") or die("链接数据库失败");
  mysql_select_db("text");  
  $sql="SELECT * FROM mytext"; 
  $query=mysql_query($sql);
  if($query) //判断mysql_query是否成功返回
  {
  echo "true";
  $num=mysql_fetch_array($query);
  print_r($num);
  echo $num[1];
  }
  else
  echo "false";
?>
执行结:页面打印出 false

为什么$sql="SELECT * FROM mytext"这一句没有成功执行,数据库里的表都设有字段和值了??求大虾帮忙!!


------解决方案--------------------
$query=mysql_query($sql) or die(mysql_error());
这样报错了没有?

建议这样写规范点:
else{
echo "false";
}

------解决方案--------------------
数据库名是text?这是MySQL保留字哦,加反引号试试:

PHP code
mysql_select_db("`text`");<div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn