使用mysql检查值时,它不返回任何内容?

时间:2016-06-23 16:19:35

标签: php mysql

所以,我有一个名为“cake_users”的mysql表 这是它的样子以及它的结构

1 name1 4588yrue38r authkey114
2 name2 4o857398563 authkey124
3 name3 93784ee8753 authkey115
4 name4 12345678910 authkey164
id, name, hwid, authkey

我正在尝试运行此查询:

$hwidid = "'12345678910'";

$cakequery = mysql_query("SELECT * FROM cake_users WHERE hwid = {$hwidid}");
if(mysql_num_rows($cakequery) == 0) {
     echo 'FALSE';
} else {
    echo 'TRUE';
}

但即使数据库中有12345678910,它总是回显为假?

我做错了什么?

2 个答案:

答案 0 :(得分:2)

您好我建议您echo queryphpmyadmin进入mysql_error,或者添加function query以查看是否存在任何错误mysqli正在运行。另请使用PDOmysql_connect('localhost','root',''); $con = mysql_select_db('yourdatabasename'); if($con){ $hwidid = '12345678910'; $sql = "SELECT * FROM cake_users WHERE hwid = '$hwidid'"; //echo $sql;die; for debugging $cakequery = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($cakequery) == 0) { echo 'FALSE'; } else { echo 'TRUE'; } }else{ echo "no connection"; }

试试这个

deployment:
  production:
    branch: "master"
    commands:
      - sh ./deploy.sh

答案 1 :(得分:1)

关于使用mysqli以及更重要的PDO的其他评论是正确的,但是直接回答你的问题:我认为你的引号太多了12345678910

$hwidid = '12345678910';

$cakequery = mysql_query("SELECT * FROM cake_users WHERE hwid = '$hwidid'");
if(mysql_num_rows($cakequery) == 0) {
     echo 'FALSE';
} else {
    echo 'TRUE';
}