Dutch PHP Conference 2026 - Call For Papers

The Pdo\Mysql class

(PHP 8 >= 8.4.0)

Introduction

A PDO subclass representing a connection using the MySQL PDO driver.

This driver supports a dedicated SQL query parser for the MySQL dialect. It can handle the following:

  • Single and double-quoted literals with both doubling and backslash as escaping mechanisms
  • Backtick literals with doubling as escaping mechanism
  • Two-dashes, C-style comments, and Hash-comments.

Class synopsis

class Pdo\Mysql extends PDO {
/* Inherited constants */
public const int PDO::PARAM_NULL ;
public const int PDO::PARAM_BOOL = 5;
public const int PDO::PARAM_INT = 1;
public const int PDO::PARAM_STR = 2;
public const int PDO::PARAM_LOB = 3;
public const int PDO::PARAM_STMT = 4;
public const int PDO::PARAM_STR_NATL ;
public const int PDO::PARAM_STR_CHAR ;
public const int PDO::PARAM_EVT_ALLOC ;
public const int PDO::PARAM_EVT_FREE ;
public const int PDO::FETCH_DEFAULT ;
public const int PDO::FETCH_LAZY ;
public const int PDO::FETCH_ASSOC ;
public const int PDO::FETCH_NUM ;
public const int PDO::FETCH_BOTH ;
public const int PDO::FETCH_OBJ ;
public const int PDO::FETCH_BOUND ;
public const int PDO::FETCH_COLUMN ;
public const int PDO::FETCH_CLASS ;
public const int PDO::FETCH_INTO ;
public const int PDO::FETCH_FUNC ;
public const int PDO::FETCH_GROUP ;
public const int PDO::FETCH_UNIQUE ;
public const int PDO::FETCH_KEY_PAIR ;
public const int PDO::FETCH_CLASSTYPE ;
public const int PDO::FETCH_SERIALIZE ;
public const int PDO::FETCH_PROPS_LATE ;
public const int PDO::FETCH_NAMED ;
public const int PDO::ATTR_AUTOCOMMIT ;
public const int PDO::ATTR_PREFETCH ;
public const int PDO::ATTR_TIMEOUT ;
public const int PDO::ATTR_ERRMODE ;
public const int PDO::ATTR_SERVER_INFO ;
public const int PDO::ATTR_CASE ;
public const int PDO::ATTR_CURSOR_NAME ;
public const int PDO::ATTR_CURSOR ;
public const int PDO::ATTR_PERSISTENT ;
public const int PDO::ATTR_DRIVER_NAME ;
public const int PDO::ERRMODE_SILENT ;
public const int PDO::ERRMODE_WARNING ;
public const int PDO::CASE_NATURAL ;
public const int PDO::CASE_LOWER ;
public const int PDO::CASE_UPPER ;
public const int PDO::NULL_NATURAL ;
public const int PDO::NULL_TO_STRING ;
public const string PDO::ERR_NONE ;
public const int PDO::FETCH_ORI_NEXT ;
public const int PDO::FETCH_ORI_PRIOR ;
public const int PDO::FETCH_ORI_FIRST ;
public const int PDO::FETCH_ORI_LAST ;
public const int PDO::FETCH_ORI_ABS ;
public const int PDO::FETCH_ORI_REL ;
public const int PDO::CURSOR_FWDONLY ;
public const int PDO::CURSOR_SCROLL ;
/* Constants */
public const int ATTR_LOCAL_INFILE ;
public const int ATTR_INIT_COMMAND ;
public const int ATTR_MAX_BUFFER_SIZE ;
public const int ATTR_COMPRESS ;
public const int ATTR_DIRECT_QUERY ;
public const int ATTR_FOUND_ROWS ;
public const int ATTR_IGNORE_SPACE ;
public const int ATTR_MULTI_STATEMENTS ;
public const int ATTR_SSL_KEY ;
public const int ATTR_SSL_CERT ;
public const int ATTR_SSL_CA ;
public const int ATTR_SSL_CAPATH ;
public const int ATTR_SSL_CIPHER ;
/* Methods */
public getWarningCount (): int
/* Inherited methods */
public PDO::__construct (
string $dsn,
? string $username = null ,
#[\SensitiveParameter] ? string $password = null ,
? array $options = null
)
public PDO::commit (): bool
public static PDO::connect (
string $dsn,
? string $username = null ,
#[\SensitiveParameter] ? string $password = null ,
? array $options = null
): static
public PDO::errorCode (): ? string
public PDO::errorInfo (): array
public PDO::exec (string $statement): int |false
public PDO::getAttribute (int $attribute): mixed
public static PDO::getAvailableDrivers (): array
public PDO::lastInsertId (? string $name = null ): string |false
public PDO::prepare (string $query, array $options = []): PDOStatement |false
public PDO::query (string $query, ? int $fetchMode = null ): PDOStatement |false
public PDO::query (string $query, ? int $fetchMode = PDO::FETCH_COLUMN, int $colno): PDOStatement |false
public PDO::query (
string $query,
? int $fetchMode = PDO::FETCH_CLASS,
string $classname,
array $constructorArgs
): PDOStatement |false
public PDO::query (string $query, ? int $fetchMode = PDO::FETCH_INTO, object $object): PDOStatement |false
public PDO::quote (string $string, int $type = PDO::PARAM_STR): string |false
public PDO::rollBack (): bool
public PDO::setAttribute (int $attribute, mixed $value): bool
}

Predefined Constants

Pdo\Mysql::ATTR_USE_BUFFERED_QUERY
By default all statements are executed in buffered mode. If this attribute is set to false on a Pdo\Mysql object, the MySQL driver will use the unbuffered mode.

Example #1 Setting MySQL unbuffered mode

<?php
$pdo
= new Pdo\Mysql("mysql:host=localhost;dbname=world", 'my_user', 'my_password');
$pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);

$unbufferedResult = $pdo->query("SELECT Name FROM City");
foreach (
$unbufferedResult as $row) {
echo
$row['Name'] . PHP_EOL;
}
?>
Pdo\Mysql::ATTR_LOCAL_INFILE
Enable LOAD LOCAL INFILE.

Note: Can only be used in the driver_options array when constructing a new database handle.

Pdo\Mysql::ATTR_LOCAL_INFILE_DIRECTORY
Allows restricting LOCAL DATA loading to files located in this designated directory.

Note: Can only be used in the driver_options array when constructing a new database handle.

Pdo\Mysql::ATTR_INIT_COMMAND
Command to execute when connecting to the MySQL server. Will automatically be re-executed when reconnecting.

Note: Can only be used in the driver_options array when constructing a new database handle.

Pdo\Mysql::ATTR_READ_DEFAULT_FILE
Read options from the named option file instead of from my.cnf.

Note: This option is not available if mysqlnd is used, because mysqlnd does not read the mysql configuration files.

Pdo\Mysql::ATTR_READ_DEFAULT_GROUP
Read options from the named group from my.cnf or the file specified with Pdo\Mysql::ATTR_READ_DEFAULT_FILE .

Note: This option is not available if mysqlnd is used, because mysqlnd does not read the mysql configuration files.

Pdo\Mysql::ATTR_COMPRESS
Enable network communication compression.
Pdo\Mysql::ATTR_DIRECT_QUERY
Alias of PDO::ATTR_EMULATE_PREPARES .
Pdo\Mysql::ATTR_FOUND_ROWS
Return the number of found (matched) rows, not the number of changed rows.

Note: Can only be used in the driver_options array when constructing a new database handle.

Pdo\Mysql::ATTR_IGNORE_SPACE
Permit spaces after SQL function names. Makes all SQL functions names reserved words.

Note: Can only be used in the driver_options array when constructing a new database handle.

Pdo\Mysql::ATTR_MAX_BUFFER_SIZE
Maximum buffer size. Defaults to 1 MiB.

Note: This constant is not supported when compiled against mysqlnd.

Pdo\Mysql::ATTR_MULTI_STATEMENTS
Disables multi query execution in both PDO::prepare() and PDO::query() when set to false .

Note: Can only be used in the driver_options array when constructing a new database handle.

Pdo\Mysql::ATTR_SERVER_PUBLIC_KEY
RSA public key file used with the SHA-256 based authentication.

Note: Can only be used in the driver_options array when constructing a new database handle.

Pdo\Mysql::ATTR_SSL_KEY
The file path to the SSL key.

Note: Can only be used in the driver_options array when constructing a new database handle.

Pdo\Mysql::ATTR_SSL_CERT
The file path to the SSL certificate.

Note: Can only be used in the driver_options array when constructing a new database handle.

Pdo\Mysql::ATTR_SSL_CA
The file path to the SSL certificate authority.

Note: Can only be used in the driver_options array when constructing a new database handle.

Pdo\Mysql::ATTR_SSL_CAPATH
The file path to the directory that contains the trusted SSL CA certificates, which are stored in PEM format.

Note: Can only be used in the driver_options array when constructing a new database handle.

Pdo\Mysql::ATTR_SSL_CIPHER
A list of one or more permissible ciphers to use for SSL encryption, in a format understood by OpenSSL. For example: DHE-RSA-AES256-SHA:AES128-SHA

Note: Can only be used in the driver_options array when constructing a new database handle.

Pdo\Mysql::ATTR_SSL_VERIFY_SERVER_CERT
Provides a way to disable verification of the server SSL certificate.

Note: This option is available only with mysqlnd.

Note: Can only be used in the driver_options array when constructing a new database handle.

Table of Contents

Found A Problem?

Learn How To Improve This PageSubmit a Pull RequestReport a Bug
+add a note

User Contributed Notes

There are no user contributed notes for this page.

AltStyle によって変換されたページ (->オリジナル) /