php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79808 fetch General error
Submitted: 2020-07-08 08:53 UTC Modified: 2020-07-11 19:34 UTC
From: admin at yurunsoft dot com Assigned:
Status: Not a bug Package: PDO MySQL
PHP Version: 8.0.0alpha1 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: admin at yurunsoft dot com
New email:
PHP Version: OS:

 

 [2020-07-08 08:53 UTC] admin at yurunsoft dot com
Description:
------------
The bug is only in php8

Test script:
---------------
<?php
$pdo = new PDO('mysql:host=192.168.0.222;port=3306;dbname=db_imi_test;charset=utf8', 'root', 'root');
$stmt = $pdo->query('update tb_article set id = 1 where id = 1');
var_dump($stmt);
var_dump($stmt->fetch());


Expected result:
----------------
object(PDOStatement)#2 (1) {
  ["queryString"]=>
  string(41) "update tb_article set id = 1 where id = 1"
}
bool(false)

Actual result:
--------------
object(PDOStatement)#2 (1) {
  ["queryString"]=>
  string(40) "update tb_member set id = 1 where id = 1"
}

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error in /mnt/d/projects/imi/test2.php:5
Stack trace:
#0 /mnt/d/projects/imi/test2.php(5): PDOStatement->fetch()
#1 {main}
  thrown in /mnt/d/projects/imi/test2.php on line 5

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-07-11 19:34 UTC] twosee@php.net
-Status: Open +Status: Not a bug
 [2020-07-11 19:34 UTC] twosee@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is due to the default error mode of PDO is `PDO::ERRMODE_EXCEPTION` now, see: https://wiki.php.net/rfc/pdo_default_errmode

In previous versions of PHP, you can check it by:

code:
```php
var_dump($stmt->errorCode());
var_dump($stmt->errorInfo());
```

output:
```
string(5) "HY000"
array(3) {
  [0]=>
  string(5) "HY000"
  [1]=>
  NULL
  [2]=>
  NULL
}
```

It may seem unreasonable to you, but it is as expected
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC