php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #66704 Small update needs to be made to the manual page
Submitted: 2014-02-12 23:21 UTC Modified: 2021-08-09 11:16 UTC
From: php_bugs at multiwebinc dot com Assigned: cmb (profile)
Status: Closed Package: PDO related
PHP Version: 5.6Git-2014-02-12 (Git) OS:
Private report: No CVE-ID: None
 [2014-02-12 23:21 UTC] php_bugs at multiwebinc dot com
Description:
------------
---
From manual page: http://www.php.net/pdo.query
---

From the PDO::query() and PDO::exec() manual pages it looks like they do exactly the same thing with the only difference being the return value, however reviewing the PHP source code, it appears that there is a subtle difference that I feel should be noted.

Since PDO::query() internally does a prepare() followed by an execute(), this means that the queries allowed must only contain syntax that is listed in the list of "SQL Syntax Allowed in Prepared Statements" (http://dev.mysql.com/doc/refman/5.6/en/sql-syntax-prepared-statements.html#idm46981480871472) or else you get something like:

"SQLSTATE[HY000]: General error: 2030 This command is not supported in the prepared statement protocol yet"

Test script:
---------------
<?php

// Note "USE" is not permitted in prepared statements (see the URL above)
$dbh->query("USE db_name"); // Fails
$dbh->exec("USE db_name"); // Works


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-14 15:58 UTC] cmb@php.net
-Package: Documentation problem +Package: PDO related
 [2021-08-09 11:16 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-08-09 11:16 UTC] cmb@php.net
This has recently been fixed; the docs[1] now state:

| Prepares and executes an SQL statement without placeholders

[1] <https://www.php.net/pdo.query>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 11:01:30 2024 UTC