欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

PHP PDO 查询如何返回单挑记录

程序员文章站 2022-05-12 15:32:07
...
如: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);


活捉版主一只,以后有很多问题就找你了