Simple way to read single record from MySQL

后端 未结 20 1356
一整个雨季
一整个雨季 2020-11-30 23:46

What\'s the best way with PHP to read a single record from a MySQL database? E.g.:

SELECT id FROM games

I was trying to find an answer in t

20条回答
  •  旧时难觅i
    2020-12-01 00:34

    mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
    $db = new mysqli('localhost', 'tmp', 'tmp', 'your_db');  
    $db->set_charset('utf8mb4');
    
    if($row = $db->query("SELECT id FROM games LIMIT 1")->fetch_row()) { //NULL or array
        $id = $row[0];
    }
    

提交回复
热议问题