Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have the following code :

$sql = 'select count(*) from match as count where match_status != :status';
      $query = $con->prepare($sql);
      $query->bindValue(':status',LOST,PDO::PARAM_INT);
      $query->execute();
      $row = $query->fetch(PDO::FETCH_ASSOC);

      if(!empty($row))
        $row_count = $row['count'];
      else
        $row_count = 0;

I am getting Notice: Undefined index: count

What's the mistake?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
360 views
Welcome To Ask or Share your Answers For Others

1 Answer

You created the alias for the wrong thing. This should work:

SELECT count(*) as count FROM `match` WHERE match_status != :status
                 //^^^^^ Alias for 'count(*)' NOT for your table name

Also you have to put ` around keywords/Mysql reserved words e.g. match: http://dev.mysql.com/doc/refman/5.6/en/reserved-words.html

And if you turn on error mode then you also get an error for this, just put it right after your connection:

$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);  

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...