Checking if mysql_query returned anything or not

前端 未结 5 2130
天命终不由人
天命终不由人 2021-02-18 16:56
$query = \"SELECT * FROM `table`\";
$results = mysql_query($query, $connection);

If \'table\' has no rows. whats the easiest way to check for this.?

5条回答
  •  孤独总比滥情好
    2021-02-18 17:33

    Alternatively you can simply check if the result of mysql_fetch_assoc is false.

    $query = "SELECT * FROM `table`";
    $results = mysql_query($query, $connection);
    $Row = mysql_fetch_assoc($results);
    if ($Row == false)
    {
      $Msg = 'Table is empty';
    }
    

提交回复
热议问题