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

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

程序员文章站 2022-05-31 19:08:28
...
我加上了 $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
prepare("select * from test");
 $stmt->execute();
 //$myrow = mysql_fetch_row($stmt->execute());
 $res=$stmt->fetch();
 $myrow = mysql_fetch_row($res);
 print_r($myrow);
?>

回复内容:

我加上了 $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

prepare("select * from test");
 $stmt->execute();
 //$myrow = mysql_fetch_row($stmt->execute());
 $res=$stmt->fetch();
 $myrow = mysql_fetch_row($res);
 print_r($myrow);
?>

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

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

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

print_r($result);

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

echo $count;

要用while循环取吧

相关标签: php mysql