Simple way to read single record from MySQL

后端 未结 20 1360
一整个雨季
一整个雨季 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条回答
  •  醉话见心
    2020-12-01 00:24

    First you connect to your database. Then you build the query string. Then you launch the query and store the result, and finally you fetch what rows you want from the result by using one of the fetch methods.

    $link = mysql_connect('localhost','root','yourPassword')
    mysql_select_db('database',$link);
    $sql = 'SELECT id FROM games'
    $result = mysql_query($sql,$link);
    
    $singleRow = mysql_fetch_array($result) 
    echo $singleRow;
    

    Edit: So sorry, forgot the database connection. Added it now

提交回复
热议问题