1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PDO エラー Call to a member function rowCount() on null 参考サイト

Posted at

PDOでselectを実行と同時にselectされた数をrowCountでカウントする際、

レコードがnullだと

Fatal error: Call to a member function rowCount() on null

とエラーが返される

index.php
$sql =  "SELECT * FROM table";
$resolt = $pdo->query($sql);
$entry=$resolt->rowCount();

.log
PHP Fatal error:  Uncaught Error: Call to a member function rowCount() on null in /var/www/html/index.php:51

if文で$entryemptyではない場合にrowCountするように修正する。

index.php
$sql =  "SELECT * FROM table";
$resolt = $pdo->query($sql);
if(!empty($resolt)){$entry=$resolt->rowCount();}

成功!!

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?