создание и продвижение сайта (вбиваю в ТОП-10, как гвозди)Настройка и сопровождение платной рекламы яндекс.директ

PHP. Руководство по PHP. 2005

PDO Functions

Пред.

След.

CIV. PDO Functions

Введение

Внимание. Это расширение является ЭКСПЕРИМЕНТАЛЬНЫМ. Поведение этого расширения, включая имена его функций и относящуюся к нему документацию, может измениться в последующих версиях PHP без уведомления. Используйте это расширение на свой страх и риск.

The PHP Data Objects (PDO) extension defines a lightweight, consistent interface for accessing databases in PHP. Each database driver that implements the PDO interface can expose database-specific features as regular extension functions. Note that you cannot perform any database functions using the PDO extension by itself; you must use a database-specific PDO driver to access a database server.

Установка

Windows

Follow the same steps to install and enable the PDO drivers of your choice.

  1. Windows users can download the extension DLL php_pdo.dll as part of the PECL collection binaries from http://php.net/downloads.php or a more recent version from a PHP5 PECL Snapshot.
  2. To enable the PDO extension on Windows operating systems, you must add the following line to php.ini:
    extension=php_pdo.dll
    
  3. Next, choose the other DB specific DLL files and either use dl() to load them at runtime, or enable them in php.ini below php_pdo.dll. For example:
    extension=php_pdo.dll
    

    extension=php_pdo_firebird.dll

    extension=php_pdo_mssql.dll

    extension=php_pdo_mysql.dll

    extension=php_pdo_oci.dll

    extension=php_pdo_oci8.dll

    extension=php_pdo_odbc.dll

    extension=php_pdo_pgsql.dll

    extension=php_pdo_sqlite.dll

    These DLL's should exist in the systems extension_dir.

Linux and UNIX

Due to a bug in the pear installer you should install the PDO package manually using the following steps:

Follow the same steps to install and enable the PDO drivers of your choice.

  1. Download the PDO package to your local machine:
    bash$ wget http://pecl.php.net/get/PDO
    
  2. Determine your PHP bin directory. If your PHP5 CLI binary lives at /usr/local/php5/bin/php then the bin dir is /usr/local/php5/bin.
  3. Set your path so that your PHP bin directory is at the front:
    export PATH="/usr/local/php5/bin:$PATH"
    
  4. Manually build and install the PDO extension:
    bash$ tar xzf PDO-0.2.tgz
    

    bash$ cd PDO-0.2

    bash$ phpize

    bash$ ./configure

    bash$ make

    bash$ sudo -s

    bash# make install

    bash# echo extension=pdo.so>> /usr/local/php5/lib/php.ini

Настройка во время выполнения

-Поведение этих функций зависит от установок в php.ini.

Таблица 1. PDO Configuration Options

NameDefaultChangeableChangelog
pdo.dsn.*php.ini only
pdo_odbc.connection_pooling"strict"PHP_INI_ALL

Для подробного описания констант

PHP_INI_*, обратитесь к документации функции ini_set().

Краткое разъяснение конфигурационных

директив.

pdo.dsn.* string

Defines DSN alias. See PDO::__construct for thorough explanation.

pdo_odbc.connection_pooling string

Whether to pool ODBC connections. Can be one of "strict", "relaxed" or "off" (equals to "").

PDO Drivers

The following drivers currently implement the PDO interface:

Driver nameSupported databases
PDO_DBLIBFreeTDS / Microsoft SQL Server / Sybase
PDO_FIREBIRDFirebird/Interbase 6
PDO_MYSQLMySQL 3.x/4.0
PDO_OCIOracle Call Interface
PDO_ODBCODBC v3 (IBM DB2, unixODBC and win32 ODBC)
PDO_PGSQLPostgreSQL
PDO_SQLITESQLite 3.x
sqliteSQLite 2.x (PHP5.1 and up)

Предопределенные классы

PDO

Represents a connection between PHP and a database server.

Конструктор

  • PDO - constructs a new PDO object

    Методы

  • beginTransaction - begins a transaction
  • commit - commits a transaction
  • exec - issues an SQL statement and returns the number of affected rows
  • errorCode - retrieves an error code, if any, from the database
  • errorInfo - retrieves an array of error information, if any, from the database
  • getAttribute - retrieves a database connection attribute
  • lastInsertId - retrieves the value of the last row that was inserted into a table
  • prepare - prepares an SQL statement for execution
  • query - issues an SQL statement and returns a result set
  • quote - returns a quoted version of a string for use in SQL statements
  • rollBack - roll back a transaction
  • setAttribute - sets a database connection attribute

    PDOStatement

    Represents a prepared statement and, after the statement is executed, an associated result set.

    Методы

  • bindColumn - binds a PHP variable to an output column in a result set
  • bindParam - binds a PHP variable to a parameter in the prepared statement
  • closeCursor - closes the cursor, allowing the statement to be executed again
  • columnCount - returns the number of columns in the result set
  • errorCode - retrieves an error code, if any, from the statement
  • errorInfo - retrieves an array of error information, if any, from the statement
  • execute - executes a prepared statement
  • fetch - fetches a row from a result set
  • fetchAll - fetches an array containing all of the rows from a result set
  • fetchColumn - returns the data from a single column in a result set
  • getAttribute - retrieves a PDOStatement attribute
  • getColumnMeta - retrieves metadata for a column in the result set
  • nextRowset - retrieves the next rowset (result set)
  • rowCount - returns the number of rows that were affected by the execution of an SQL statement
  • setAttribute - sets a PDOStatement attribute
  • setFetchMode - sets the fetch mode for a PDOStatement

    Предопределенные константы

    -Перечисленные ниже константы определены данным расширением и могут быть

    доступны только в том случае, если PHP был собран с

    поддержкой этого расширения или же в том случае, если

    данное расширение подгружается во время выполнения.

    PDO_PARAM_NULL (integer)

    Represents the SQL NULL data type.

    PDO_PARAM_INT (integer)

    Represents the SQL INTEGER data type.

    PDO_PARAM_STR (integer)

    Represents the SQL CHAR, VARCHAR, or other string data type.

    PDO_PARAM_LOB (integer)

    Represents the SQL large object data type.

    PDO_PARAM_STMT (integer)

    PDO_PARAM_INPUT_OUTPUT (integer)

    Specifies that the parameter is an INOUT parameter for a stored procedure. You must bitwise-OR this value with an explicit PDO_PARAM_* data type.

    PDO_FETCH_LAZY (integer)

    Specifies that the fetch method shall return each row as an object with variable names that correspond to the column names returned in the result set. PDO_FETCH_LAZY creates the object variable names as they are accessed.

    PDO_FETCH_ASSOC (integer)

    Specifies that the fetch method shall return each row as an array indexed by column name as returned in the corresponding result set. If the result set contains multiple columns with the same name, PDO_FETCH_ASSOC returns only a single value per column name.

    PDO_FETCH_NAMED (integer)

    Specifies that the fetch method shall return each row as an array indexed by column name as returned in the corresponding result set. If the result set contains multiple columns with the same name, PDO_FETCH_NAMED returns an array of values per column name.

    PDO_FETCH_NUM (integer)

    Specifies that the fetch method shall return each row as an array indexed by column number as returned in the corresponding result set, starting at column 0.

    PDO_FETCH_BOTH (integer)

    Specifies that the fetch method shall return each row as an array indexed by both column name and number as returned in the corresponding result set, starting at column 0.

    PDO_FETCH_OBJ (integer)

    Specifies that the fetch method shall return each row as an object with property names that correspond to the column names returned in the result set.

    PDO_FETCH_BOUND (integer)

    Specifies that the fetch method shall return TRUE and assign the values of the columns in the result set to the PHP variables to which they were bound with the PDOStatement::bindParam() or PDOStatement::bindColumn() methods.

    PDO_FETCH_COLUMN (integer)

    Specifies that the fetch method shall return only a single requested column from the next row in the result set.

    PDO_FETCH_CLASS (integer)

    Specifies that the fetch method shall return a new instance of the requested class, mapping the columns to named properties in the class.

    PDO_FETCH_INTO (integer)

    Specifies that the fetch method shall update an existing instance of the requested class, mapping the columns to named properties in the class.

    PDO_FETCH_FUNC (integer)

    PDO_FETCH_GROUP (integer)

    PDO_FETCH_UNIQUE (integer)

    PDO_FETCH_CLASSTYPE (integer)

    PDO_ATTR_AUTOCOMMIT (integer)

    If this value is FALSE, PDO attempts to disable autocommit so that the connection begins a transaction.

    PDO_ATTR_PREFETCH (integer)

    Setting the prefetch size allows you to balance speed against memory usage for your application. Not all database/driver combinations support setting of the prefetch size.

    PDO_ATTR_TIMEOUT (integer)

    Sets the timeout value in seconds for communications with the database.

    PDO_ATTR_ERRMODE (integer)

    PDO_ATTR_SERVER_VERSION (integer)

    PDO_ATTR_CLIENT_VERSION (integer)

    PDO_ATTR_SERVER_INFO (integer)

    PDO_ATTR_CONNECTION_STATUS (integer)

    PDO_ATTR_CASE (integer)

    Force column names to a specific case specified by the PDO_CASE_* constants.

    PDO_ATTR_CURSOR_NAME (integer)

    PDO_ATTR_CURSOR (integer)

    PDO_ATTR_DRIVER_NAME (string)

    Returns the name of the driver.

    PDO_ATTR_ORACLE_NULLS (integer)

    Convert empty strings to SQL NULL values.

    PDO_ATTR_PERSISTENT (integer)

    Request a persistent connection, rather than creating a new connection.

    PDO_ATTR_FETCH_CATALOG_NAMES (integer)

    Prepend the containing catalog name to each column name returned in the result set. The catalog name and column name are separated by a decimal (.) character.

    PDO_ATTR_FETCH_TABLE_NAMES (integer)

    Prepend the containing table name to each column name returned in the result set. The table name and column name are separated by a decimal (.) character.

    PDO_ERRMODE_SILENT (integer)

    Do not raise an error or exception if an error occurs. The developer is expected to explicitly check for errors. This is the default mode.

    PDO_ERRMODE_WARNING (integer)

    Issue a PHP E_WARNING message if an error occurs.

    PDO_ERRMODE_EXCEPTION (integer)

    Throw a PDOException if an error occurs.

    PDO_CASE_NATURAL (integer)

    Leave column names as returned by the database driver.

    PDO_CASE_LOWER (integer)

    Force column names to lower case.

    PDO_CASE_UPPER (integer)

    Force column names to upper case.

    PDO_FETCH_ORI_NEXT (integer)

    Fetch the next row in the result set. Valid only for scrollable cursors.

    PDO_FETCH_ORI_PRIOR (integer)

    Fetch the previous row in the result set. Valid only for scrollable cursors.

    PDO_FETCH_ORI_FIRST (integer)

    Fetch the first row in the result set. Valid only for scrollable cursors.

    PDO_FETCH_ORI_LAST (integer)

    Fetch the last row in the result set. Valid only for scrollable cursors.

    PDO_FETCH_ORI_ABS (integer)

    Fetch the requested row by row number from the result set. Valid only for scrollable cursors.

    PDO_FETCH_ORI_REL (integer)

    Fetch the requested row by relative position from the current position of the cursor in the result set. Valid only for scrollable cursors.

    PDO_CURSOR_FWDONLY (integer)

    Create a PDOStatement object with a forward-only cursor. This may improve the performance of your application but restricts your PDOStatement object to fetching one row at a time from the result set in a forward direction.

    PDO_CURSOR_SCROLL (integer)

    Create a PDOStatement object with a scrollable cursor. Pass the PDO_FETCH_ORI_* constants to control the rows fetched from the result set.

    PDO_ERR_CANT_MAP (integer)

    PDO_ERR_SYNTAX (integer)

    PDO_ERR_CONSTRAINT (integer)

    PDO_ERR_NOT_FOUND (integer)

    PDO_ERR_ALREADY_EXISTS (integer)

    PDO_ERR_NOT_IMPLEMENTED (integer)

    PDO_ERR_MISMATCH (integer)

    PDO_ERR_TRUNCATED (integer)

    PDO_ERR_DISCONNECTED (integer)

    PDO_ERR_NO_PERM (integer)

    PDO_ERR_NONE (string)

    Corresponds to SQLSTATE '00000', meaning that the SQL statement was successfully issued with no errors or warnings.

    Содержание

    PDO::beginTransaction -- Initiates a transaction

    PDO::commit -- Commits a transaction

    PDO::__construct -- Creates a PDO instance representing a connection to a database

    PDO::errorCode -- Fetch the SQLSTATE associated with the last operation on the database handle

    PDO::errorInfo -- Fetch extended error information associated with the last operation on the database handle

    PDO::exec -- Execute an SQL statement and return the number of affected rows

    PDO::getAttribute -- Retrieve a database connection attribute

    PDO::lastInsertId -- Returns the ID of the last inserted row or sequence value

    PDO::prepare -- Prepares a statement for execution and returns a statement object

    PDO::query -- Executes an SQL statement, returning a result set as a PDOStatement object

    PDO::quote -- Quotes a string for use in a query.

    PDO::rollBack -- Rolls back a transaction

    PDO::setAttribute -- Set an attribute

    PDOStatement::bindColumn -- Bind a column to a PHP variable

    PDOStatement::bindParam -- Binds a parameter to the specified variable name

    PDOStatement::closeCursor -- Closes the cursor, enabling the statement to be executed again.

    PDOStatement::columnCount -- Returns the number of columns in the result set

    PDOStatement::errorCode -- Fetch the SQLSTATE associated with the last operation on the statement handle

    PDOStatement::errorInfo -- Fetch extended error information associated with the last operation on the statement handle

    PDOStatement::execute -- Executes a prepared statement

    PDOStatement::fetch -- Fetches the next row from a result set

    PDOStatement::fetchAll -- Returns an array containing all of the result set rows

    PDOStatement::fetchColumn -- Returns a single column from the next row of a result set

    PDOStatement::getAttribute -- Retrieve a statement attribute

    PDOStatement::getColumnMeta -- Returns metadata for a column in a result set

    PDOStatement::nextRowset -- Advances to the next rowset in a multi-rowset statement handle

    PDOStatement::rowCount -- Returns the number of rows affected by the last SQL statement

    PDOStatement::setAttribute -- Set a statement attribute

    PDOStatement::setFetchMode -- Set the default fetch mode for this statement

    pdo_drivers -- Return an array of available PDO drivers

    Пред.

    Начало

    След.

    pdf_translate

    Уровень выше

    PDO::beginTransaction

  • Отвечу на любые вопросы. С уважением, Дмитрий Владимирович.

    Ваше письмо×
    Free Web Hosting