PHP PDO 查询如何返回单挑记录
程序员文章站
2022-05-14 11:19:01
...
如:select name from user where id = 1
如何获取 name 这个值 怎么办?只有一条数据,
活捉版主一只,以后有很多问题就找你了
如何获取 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);
活捉版主一只,以后有很多问题就找你了