Rumah >pembangunan bahagian belakang >tutorial php >PHP PDO 查询如何返回单挑记录
如:select name from user where id = 1
如何获取 name 这个值 怎么办?只有一条数据,
$conn = mysql_connect("localhost","root","");mysql_select_db("mydatabases",$conn);$result = mysql_query("select name from user where id = 1");while ($row = mysql_fetch_array($result)){ echo $row['name'];}
$db = new PDO($dsn, $user, $pass);$rs = $db->query($sql);$a = $rs->fetch(PDO::FETCH_ASSOC);
$db = new PDO($dsn, $user, $pass);$rs = $db->query($sql);$a = $rs->fetch(PDO::FETCH_ASSOC);