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
--- | --- | ---
maxdb.default_host | NULL | PHP_INI_ALL
maxdb.default_db | NULL | PHP_INI_ALL
maxdb.default_user | NULL | PHP_INI_ALL
maxdb.default_password | NULL | PHP_INI_ALL
maxdb.long_readlen | NULL | PHP_INI_ALL

For further details and definitions of the PHP_INI_* constants, see the 附錄 H.

這裡為簡短的結構指令說明。

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_password 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