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/.
The MaxDB PHP extension is compatible to the MySQL mysqli extension. There are only minor differences in the behaviour of some functions due to the differences of the underlying database servers, MaxDB and MySQL.
The main differences to mysqli are in the following functions:
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 的影响。
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 |
以下是配置选项的简要解释。
The default server host to use when connecting to the database server if no other host is specified.
The default server database to use when connecting if no other database is specified.
The default user name to use when connecting to the database server if no other name is specified.
The default password to use when connecting to the database server if no other password is specified.
The default maximum length of bytes that is transferred to the client if long data is retrieved from the MaxDB database server.
Represents a connection between PHP and a MaxDB database.
maxdb - construct a new maxdb object
autocommit - turns on or off auto-commiting database modifications
change_user - changes the user of the specified database connection
character_set_name - returns the default character set for the database connection
close - closes a previously opened connection
commit - commits the current transaction
connect - opens a new connection to MaxDB database server
debug - performs debugging operations
dump_debug_info - dumps debug information
get_client_info - returns client version
get_host_info - returns type of connection used
get_server_info - returns version of the MaxDB server
get_server_version - returns version of the MaxDB server
init - initializes maxdb object
info - retrieves information about the most recently executed query
kill - asks the server to kill a MaxDB thread
multi_query - performs multiple queries
more_results - check if more results exist from currently executed multi-query
next_result - reads next result from currently executed multi-query
options - set options
ping - pings a server connection or reconnects if there is no connection
prepare - prepares a SQL query
query - performs a query
real_connect - attempts to open a connection to MaxDB database server
escape_string - escapes special characters in a string for use in a SQL statement, taking into account the current charset of the connection
rollback - rolls back the current transaction
select_db - selects the default database
ssl_set - sets ssl parameters
stat - gets the current system status
stmt_init- initializes a statement for use with maxdb_stmt_prepare
store_result - transfers a resultset from last query
use_result - transfers an unbuffered resultset from last query
thread-safe - returns whether thread safety is given or not
affected_rows - gets the number of affected rows in a previous MaxDB operation
client_info - returns the MaxDB client version as a string
client_version - returns the MaxDB client version as an integer
errno - returns the error code for the most recent function call
error - returns the error string for the most recent function call
field_count - returns the number of columns for the most recent query
host_info - returns a string representing the type of connection used
info - retrieves information about the most recently executed query
insert_id - returns the auto generated id used in the last query
protocol_version - returns the version of the MaxDB protocol used
sqlstate - returns a string containing the SQLSTATE error code for the last error
thread_id - returns the thread ID for the current connection
warning_count - returns the number of warnings generated during execution of the previous SQL statement
Represents a prepared statement.
bind_param - binds variables to a prepared statement
bind_result - binds variables to a prepared statement for result storage
close - closes a prepared statement
data-seek - seeks to an arbitrary row in a statement result set
execute - executes a prepared statement
fetch - fetches result from a prepared statement into bound variables
free_result - frees stored result memory for the given statement handle
result_metadata - retrieves a resultset from a prepared statement for metadata information
prepare - prepares a SQL query
send_long_data - sends data in chunks
close_long_data - end sending long data
reset - resets a prepared statement
store_result - buffers complete resultset from a prepared statement
affected_rows - returns affected rows from last statement execution
errno - returns errorcode for last statement function
errno - returns errormessage for last statement function
param_count - returns number of parameter for a given prepare statement
sqlstate - returns a string containing the SQLSTATE error code for the last statement function
Represents the result set obtained from a query against the database.
close - closes resultset
data_seek - moves internal result pointer
fetch_field - gets column information from a resultset
fetch_fields - gets information for all columns from a resulset
fetch_field_direct - gets column information for specified column
fetch_array - fetches a result row as an associative array, a numeric array, or both.
fetch_assoc - fetches a result row as an associative array
fetch_object - fetches a result row as an object
fetch_row - gets a result row as an enumerated array
close - frees result memory
field_seek - set result pointer to a specified field offset
current_field - returns offset of current fieldpointer
field_count - returns number of fields in resultset
lengths - returns an array of columnlengths
num_rows - returns number of rows in resultset
This extension defines resources.
以下常量由本扩展模块定义,因此只有在本扩展模块被编译到 PHP 中,或者在运行时被动态加载后才有效。
The following constants to use with maxdb_options() are defined. For further description of these constants see » http://dev.mysql.com/doc/maxdb/.
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:
Constant | Description |
---|---|
MAXDB_ASSOC | Columns are returned into the array having the fieldname as the array index. |
MAXDB_ASSOC_UPPER | Columns are returned into the array having the upper case fieldname as the array index. |
MAXDB_ASSOC_LOWER | Columns are returned into the array having the lower case 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.
To use the examples in the MaxDB PHP documentation, you have to load the tutorial data into your database. Then you have to set maxdb.default_db in php.ini to the database that contains the tutorial data.
This simple example shows how to connect, execute a query, print resulting rows and disconnect from a MaxDB database.
Example#1 MaxDB extension overview example
<?php
$link = maxdb_connect("localhost", "MONA", "RED", "DEMODB");
/* check connection */
if (maxdb_connect_errno()) {
printf("Connect failed: %s\n", maxdb_connect_error());
exit();
}
/* Performing SQL query */
$query = "SELECT * FROM hotel.city";
$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 " <tr>\n";
foreach ($line as $col_value) {
echo " <td>$col_value</td>\n";
}
echo " </tr>\n";
}
echo "</table>\n";
/* Free resultset */
maxdb_free_result($result);
/* Closing connection */
maxdb_close($link);
?>
The following example shows how to bind variables to a SELECT INTO statement.
Example#2 Example for use of SELECT INTO statements
<?php
$link = maxdb_connect("localhost", "MONA", "RED", "DEMODB");
/* check connection */
if (!$link) {
printf("Connect failed: %s\n", maxdb_connect_error());
exit();
}
/* Performing SQL query */
$stmt = maxdb_prepare ($link, "SELECT percentage INTO ? FROM hotel.countrylanguage where language = ?");
if (!$stmt) {
printf ("Prepare failed: %s\n", maxdb_error($link));
}
$name = "Mbundu";
maxdb_stmt_bind_param($stmt, 'ds', $percentage, $name);
maxdb_stmt_execute($stmt);
printf ("%f\n", $percentage);
maxdb_stmt_close ($stmt);
?>
The following example shows how to use MaxDB database procedures.
Example#3 Example fore using database procedures
<?php
$link = maxdb_connect("localhost", "MONA", "RED", "DEMODB");
/* check connection */
if (!$link) {
printf("Connect failed: %s\n", maxdb_connect_error());
exit();
}
maxdb_report (MAXDB_REPORT_OFF);
maxdb_query($link,"DROP DBPROC test_proc");
maxdb_report (MAXDB_REPORT_ERROR);
$query = "create dbproc test_proc (INOUT e_text char(72)) AS select * from SYSDBA.DUAL; fetch into :e_text;";
maxdb_query($link, $query);
/* Performing SQL query */
$stmt = maxdb_prepare ($link, "CALL test_proc (?)");
if (!$stmt) {
printf ("Prepare failed: %s\n", maxdb_error($link));
}
maxdb_stmt_bind_param($stmt, 's', $result);
maxdb_stmt_execute($stmt);
printf ("%s\n", $result);
maxdb_stmt_close ($stmt);
?>