mysql - php pdo对象执行预处理的时,怎么能知道影响行数?

WBOY
Release: 2016-06-06 20:08:58
Original
1033 people have browsed it

普通模式下,用 $pdo->exec($SQL); 可以返回影响行数;

如果在 预处理对象中插入删除数据的话,怎么知道影响行数?
$stmt=$pdo->prepare($SQL);
$stmt->execute();

回复内容:

普通模式下,用 $pdo->exec($SQL); 可以返回影响行数;

如果在 预处理对象中插入删除数据的话,怎么知道影响行数?
$stmt=$pdo->prepare($SQL);
$stmt->execute();

<code class="php">$stmt=$pdo->prepare($SQL);
$stmt->execute();
$count = $stmt->rowCount();//删除行数</code>
Copy after login

PDOStatement::rowCount() 返回上一个由对应的 PDOStatement 对象执行DELETE、 INSERT、或 UPDATE 语句受影响的行数。
如果上一条由相关 PDOStatement 执行的 SQL 语句是一条 SELECT 语句,有些数据可能返回由此语句返回的行数。但这种方式不能保证对所有数据有效,且对于可移植的应用不应依赖于此方式。

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!