mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc… expects parameter 1 to be resource

后端 未结 30 2728
鱼传尺愫
鱼传尺愫 2020-11-21 06:25

I am trying to select data from a MySQL table, but I get one of the following error messages:

mysql_fetch_array() expects parameter 1 to be resource,

30条回答
  •  逝去的感伤
    2020-11-21 06:56

    Don't use the depricated mysql_* function (depricated in php 5.5 will be removed in php 7). and you can make this with mysqli or pdo

    here is the complete select query

    connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } 
    
    $sql = "SELECT id, firstname, lastname FROM MyGuests";
    $result = $conn->query($sql);
    
    if ($result->num_rows > 0) {
        // output data of each row
        while($row = $result->fetch_assoc()) {
            // code here 
        }
    } else {
        echo "0 results";
    }
    $conn->close();
    ?>
    

提交回复
热议问题