Руководство по PHP
Пред. |  | След.

# LXIV. MaxDB PHP Extension

# Введение

The MaxDB PHP extension allows you to access the functionality provided by MaxDB 7.5.0 and above. More information about the MaxDB Database server can be found at http://www.mysql.com/products/maxdb/.

Documentation for MaxDB can be found at http://dev.mysql.com/doc/maxdb/.

# Требования

In order to have these functions available, you must compile PHP with MaxDB support. Additionally, you must have the MaxDB SQLDBC runtime library available to access the MaxDB server.

Documentation for MaxDB SQLDBC can be found at http://dev.mysql.com/doc/maxdb/.

Download the MaxDB SQLDBC package from http://dev.mysql.com/downloads/maxdb/clients.html.

# Установка

By using the --with-maxdb[=DIR] configuration option you enable PHP to access MaxDB databases. [DIR] points to the directory that contains the installed MaxDB SQLDBC package.

Windows users will need to enable `php_maxdb.dll` inside of `php.ini`.

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

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

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

Name | Default | Changeable | Changelog
--- | --- | --- | ---
maxdb.default_host | NULL | PHP_INI_ALL |
maxdb.default_db | NULL | PHP_INI_ALL |
maxdb.default_user | NULL | PHP_INI_ALL |
maxdb.default_pw | NULL | PHP_INI_ALL |
maxdb.long_readlen | "200" | PHP_INI_ALL |

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

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

maxdb.default_host string

  The default server host to use when connecting to the database server if no other host is specified.

maxdb.default_db string

  The default server database to use when connecting if no other database is specified.

maxdb.default_user string

  The default user name to use when connecting to the database server if no other name is specified.

maxdb.default_pw string

  The default password to use when connecting to the database server if no other password is specified.

maxdb.long_readlen integer

  The default maximum length of bytes that is transferred to the client if long data is retrieved from the MaxDB database server.

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

Перечисленные ниже константы определены данным расширением и могут быть доступны только в том случае, если PHP был собран с поддержкой этого расширения или же в том случае, если данное расширение подгружается во время выполнения.

The following constants to use with maxdb_options() are defined. For further description of these constants see http://dev.mysql.com/doc/maxdb/.

Таблица 2. MaxDB PHP client constants

Constant | Description
--- | ---
MAXDB_COMPNAME | The component name used to initialise the SQLDBC runtime environment.
MAXDB_APPLICATION | The application to be connected to the database.
MAXDB_APPVERSION | The version of the application.
MAXDB_SQLMODE | The SQL mode.
MAXDB_UNICODE | TRUE, if the connection is an unicode (UCS2) client or FALSE, if not.
MAXDB_TIMEOUT | The maximum allowed time of inactivity after which the connection to the database is closed by the system.
MAXDB_ISOLATIONLEVEL | Specifies whether and how shared locks and exclusive locks are implicitly requested or released.
MAXDB_PACKETCOUNT | The number of different request packets used for the connection.
MAXDB_STATEMENTCACHESIZE | The number of prepared statements to be cached for the connection for re-use.
MAXDB_CURSORPREFIX | The prefix to use for result tables that are automatically named.

The function maxdb_fetch_array() uses a constant for the different types of result arrays. The following constants are defined:

Таблица 3. MaxDB fetch constants

Constant | Description
--- | ---
MAXDB_ASSOC | Columns are returned into the array having the fieldname as the array index.
MAXDB_BOTH | Columns are returned into the array having both a numerical index and the fieldname as the array index.
MAXDB_NUM | Columns are returned into the array having a numerical index to the fields. This index starts with 0, the first field in the result.

# Примеры

All examples in the MaxDB PHP documentation use the HOTELDB demo database from MaxDB. More about this database can be found at http://dev.mysql.com/doc/maxdb/en/98/11b83fa6b33c17e10000000a114084/frameset.htm.

This simple example shows how to connect, execute a query, print resulting rows and disconnect from a MaxDB database.

Пример 1. MaxDB extension overview example
`<?php /* Connecting, selecting database */ $link = maxdb_connect("maxdb_host", "maxdb_user", "maxdb_password") or die("Could not connect : " . maxdb_connect_error()); echo "Connected successfully"; maxdb_select_db("my_database") or die("Could not select database"); /* Performing SQL query */ $query = "SELECT * FROM my_table"; $result = maxdb_query($link, $query) or die("Query failed : " . maxdb_error()); /* Printing results in HTML */ echo "<table>\n"; while ($line = maxdb_fetch_array($result, MAXDB_ASSOC)) { echo "\t<tr>\n"; foreach ($line as $col_value) { echo "\t\t<td>$col_value</td>\n"; } echo "\t</tr>\n"; } echo "</table>\n"; /* Free resultset */ maxdb_free_result($result); /* Closing connection */ maxdb_close($link); ?>`

Пред. | Начало | След.
tanh | Уровень выше | maxdb_affected_rows