10

For some reason the pdo_mysql PHP extension, on our hosted server, fails to run a query that uses a MySQL view, with this error message.

SQLSTATE[HY000]: General error: 1615 Prepared statement needs to be re-prepared

(There is a discussion on Bug #42041 Prepared-Statement fails when MySQL-Server under load, as well as numerous questions on Stack Overflow.)

For some reason, the query using the view runs just fine, if we switch to using the nd_pdo_mysql extension, which is for the MySQL Native Driver (mysqlnd).

What is the difference between pdo_mysql and nd_pdo_mysql? Why would one be chosen over the other one?

Thanks.

apaderno
  • 28,547
  • 16
  • 75
  • 90
user2340816
  • 103
  • 1
  • 1
  • 5
  • 1
    This might help: https://secure.php.net/manual/en/mysqlnd.overview.php – Hayden Schiff Sep 25 '17 at 22:40
  • @HaydenSchiff, thanks, but the linked article seems not to relate to pdo drivers. Any more help out there with the differences between the pdo_mysql and nd_pdo_mysql drivers? – user2340816 Oct 02 '17 at 00:30
  • I'm not familiar with the term "nd_pdo_mysql". Backend libraries are normally compiled into PHP, it's not something you can choose in runtime. Are you using some third-party PHP distribution? – Álvaro González Oct 11 '17 at 14:24
  • 4
    To whoever Googles here: `nd_pdo_mysql` appears to be a custom plugable extension provided by the [cPanel](https://www.cpanel.com/) hosting platform in order to opt-in the MySQL Native Driver in run-time. In regular PHP setups, the MySQL driver is chosen in [compile time](https://secure.php.net/manual/en/mysqlnd.install.php) and it cannot be changed afterwards, thus `pdo_mysql` is the only extension available and doesn't imply anything about the driver. – Álvaro González Oct 13 '17 at 08:49

1 Answers1

16

To connect to your MySQL server from PHP, there are two versions of drivers:

  1. mysqlnd
  2. libmysql

In order to connect to your MySQL server using mysqlnd driver, you use the nd_pdo_mysql extension, as seen in below screenshot.

enter image description here

Since libmysql returns numeric types as strings, I use mysqlnd with nd_pdo_mysql in order to get native/strict data, so that numeric types are NOT returned as Strings.

From the MySQL official website: https://dev.mysql.com/downloads/connector/php-mysqlnd/

The MySQL native driver for PHP mysqlnd is a drop-in replacement for the MySQL Client Library libmysql for the PHP script language.

AamirR
  • 11,672
  • 4
  • 59
  • 73
  • 2
    > Since libmysql returns numeric types as strings, I use mysqlnd with nd_pdo_mysql in order to get native/strict data, so that numeric types are NOT returned as Strings. ----- I have not found this info elsewhere, and am happy now to have some understanding of why one would choose to use nd_pdo_mysql over pdo_mysql. Thank you. – user2340816 Oct 11 '17 at 18:57
  • What software does this screenshot belong to? – Álvaro González Oct 12 '17 at 08:14
  • 2
    It is from cPanel – AamirR Oct 12 '17 at 13:29
  • 1
    Very helpful answer, also do not forget to set PDO::ATTR_EMULATE_PREPARES = false and PDO::ATTR_STRINGIFY_FETCHES = false in the PDO options – user356417 Mar 25 '18 at 15:36