Home >Backend Development >PHP Tutorial >PHP PDO 查询如何返回单挑记录

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

WBOY
WBOYOriginal
2016-06-23 14:38:48894browse

如: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);


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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn