怎么样获取一行数据呢和所有的数据的行数呢?

WBOY
풀어 주다: 2016-06-06 20:20:30
원래의
1258명이 탐색했습니다.

我加上了 $myrow = mysql_fetch_row($res);这一句想获取一行数据 为什么获取不到一行 提示这个 ( ! ) Warning: mysql_fetch_row() expects parameter 1 to be resource, array given in D:\wamp\www\chaxun.php on line 7

<code><?php $pdo=new PDO("mysql:host=localhost;dbname=t1","root","");
 $stmt=$pdo->prepare("select * from test");
 $stmt->execute();
 //$myrow = mysql_fetch_row($stmt->execute());
 $res=$stmt->fetch();
 $myrow = mysql_fetch_row($res);
 print_r($myrow);
?>
</code>
로그인 후 복사
로그인 후 복사

回复内容:

我加上了 $myrow = mysql_fetch_row($res);这一句想获取一行数据 为什么获取不到一行 提示这个 ( ! ) Warning: mysql_fetch_row() expects parameter 1 to be resource, array given in D:\wamp\www\chaxun.php on line 7

<code><?php $pdo=new PDO("mysql:host=localhost;dbname=t1","root","");
 $stmt=$pdo->prepare("select * from test");
 $stmt->execute();
 //$myrow = mysql_fetch_row($stmt->execute());
 $res=$stmt->fetch();
 $myrow = mysql_fetch_row($res);
 print_r($myrow);
?>
</code>
로그인 후 복사
로그인 후 복사

PDOStatement::rowCount — 返回受上一个 SQL 语句影响的行数

PDOStatement::fetch — 从结果集中获取下一行

<code><?php $pdo = new PDO('mysql:host=127.0.0.1;dbname=test;charset=utf8', 'root', 'root');

$query = $pdo->query('SELECT * from users');
//获取一行
$result=$query->fetch();

print_r($result);

$total = $pdo->query('SELECT * from test');
//统计条数
$count=$total->rowCount();

echo $count;</code>
로그인 후 복사

要用while循环取吧

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!