mSQL

目录

These functions allow you to access mSQL database servers. More information about mSQL can be found at » http://www.hughes.com.au/.

安装/配置

目录

需求

构建此扩展不需要其他扩展。

安装

In order to have these functions available, you must compile PHP with msql support by using the --with-msql[=DIR] option. DIR is the mSQL base install directory, defaults to /usr/local/msql3.

Note: Note to Win32 Users

为了使此扩展生效, DLL 文件必须能在 Windows 系统的 PATH 指示的路径下找到。如何操作的信息,请参见题为“如何在 Windows 中将 PHP 目录加到 PATH 中”的FAQ。虽然将 DLL 文件从 PHP 文件夹复制到 Windows 系统目录也行,但不建议这样做。 此扩展需要下列文件在 PATH 路径中: msql.dll

运行时配置

这些函数的行为受 php.ini 中的设置影响。

名字默认可修改范围更新日志
msql.allow_persistent"1"PHP_INI_ALL 
msql.max_persistent"-1"PHP_INI_ALL 
msql.max_links"-1"PHP_INI_ALL 

有关 PHP_INI_* 样式的更多详情与定义,见 配置可被设定范围

这是配置指令的简短说明。

msql.allow_persistent boolean
Whether to allow persistent mSQL connections.

msql.max_persistent integer
The maximum number of persistent mSQL connections per process.

msql.max_links integer
The maximum number of mSQL connections per process, including persistent connections.

资源类型

There are two resource types used in the mSQL module. The first one is the link identifier for a database connection, the second a resource which holds the result of a query.

预定义常量

下列常量由此扩展定义,且仅在此扩展编译入 PHP 或在运行时动态载入时可用。

MSQL_ASSOC (integer)

MSQL_NUM (integer)

MSQL_BOTH (integer)

范例

目录

Basic usage

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

示例 #1 mSQL usage example

<?php
/* Connecting, selecting database */
$link = msql_connect('localhost', 'username', 'password')
    or die('Could not connect : ' . msql_error($link));

msql_select_db('database', $link)
    or die('Could not select database');

/* Issue SQL query */
$query = 'SELECT * FROM my_table';
$result = msql_query($query, $link) or die('Query failed : ' . msql_error());

/* Printing results in HTML */
echo "<table>\n";
while ($row = msql_fetch_array($result, MSQL_ASSOC)) {
    echo "\t<tr>\n";
    foreach ($row as $col_value) {
        echo "\t\t<td>$col_value</td>\n";
    }
    echo "\t</tr>\n";
}
echo "</table>\n";

/* Free result set */
msql_free_result($result);

/* Close connection */
msql_close($link);
?>

msql_affected_rows

Returns number of affected rows

说明

int msql_affected_rows ( resource $result )

Returns number of affected rows by the last SELECT, UPDATE or DELETE query associated with result.

参数

result
resource 型的结果集。此结果集来自对 msql_query 的调用。

返回值

Returns the number of affected rows on success, or FALSE on error.

参见

  • msql_query

msql_close

Close mSQL connection

说明

bool msql_close ([ resource $link_identifier ] )

msql_close closes the non-persistent connection to the mSQL server that's associated with the specified link identifier.

Using msql_close isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution. See also freeing resources.

参数

link_identifier
mSQL 连接。如果不指定,则使用由 msql_connect 最近打开的连接。如果没有找到该连接,函数会尝试通过调用 msql_connect 建立连接并使用它。

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

参见

  • msql_connect
  • msql_pconnect

msql_connect

Open mSQL connection

说明

resource msql_connect ([ string $hostname ] )

msql_connect establishes a connection to a mSQL server.

If a second call is made to msql_connect with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned.

The link to the server will be closed as soon as the execution of the script ends, unless it's closed earlier by explicitly calling msql_close.

参数

hostname
The hostname can also include a port number. e.g. hostname,port.

If not specified, the connection is established by the means of a Unix domain socket, being then more efficient then a localhost TCP socket connection.

Note:

While this function will accept a colon (:) as a host/port separator, a comma (,) is the preferred method.

返回值

Returns a positive mSQL link identifier on success, or FALSE on error.

参见

  • msql_pconnect
  • msql_close

msql_create_db

Create mSQL database

说明

bool msql_create_db ( string $database_name [, resource $link_identifier ] )

msql_create_db attempts to create a new database on the mSQL server.

参数

database_name
The name of the mSQL database.

link_identifier
mSQL 连接。如果不指定,则使用由 msql_connect 最近打开的连接。如果没有找到该连接,函数会尝试通过调用 msql_connect 建立连接并使用它。

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

参见

  • msql_drop_db

msql_createdb

别名 msql_create_db

说明

此函数是该函数的别名: msql_create_db.

msql_data_seek

Move internal row pointer

说明

bool msql_data_seek ( resource $result , int $row_number )

msql_data_seek moves the internal row pointer of the mSQL result associated with the specified query identifier to point to the specified row number. The next call to msql_fetch_row would return that row.

参数

result
resource 型的结果集。此结果集来自对 msql_query 的调用。

row_number
The seeked row number.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

参见

  • msql_fetch_array
  • msql_fetch_object
  • msql_fetch_row
  • msql_result

msql_db_query

Send mSQL query

说明

resource msql_db_query ( string $database , string $query [, resource $link_identifier ] )

msql_db_query selects a database and executes a query on it.

参数

database
The name of the mSQL database.

query
The SQL query.

link_identifier
mSQL 连接。如果不指定,则使用由 msql_connect 最近打开的连接。如果没有找到该连接,函数会尝试通过调用 msql_connect 建立连接并使用它。

返回值

Returns a positive mSQL query identifier to the query result, or FALSE on error.

参见

  • msql_query

msql_dbname

别名 msql_result

说明

此函数是该函数的别名: msql_result.

msql_drop_db

Drop (delete) mSQL database

说明

bool msql_drop_db ( string $database_name [, resource $link_identifier ] )

msql_drop_db attempts to drop (remove) a database from the mSQL server.

参数

database_name
The name of the database.

link_identifier
mSQL 连接。如果不指定,则使用由 msql_connect 最近打开的连接。如果没有找到该连接,函数会尝试通过调用 msql_connect 建立连接并使用它。

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

参见

  • msql_create_db

msql_error

Returns error message of last msql call

说明

string msql_error ( void )

msql_error returns the last issued error by the mSQL server. Note that only the last error message is accessible with msql_error.

返回值

The last error message or an empty string if no error was issued.

msql_fetch_array

Fetch row as array

说明

array msql_fetch_array ( resource $result [, int $result_type ] )

msql_fetch_array is an extended version of msql_fetch_row. In addition to storing the data in the numeric indices of the result array, it also stores the data in associative indices, using the field names as keys.

An important thing to note is that using msql_fetch_array is NOT significantly slower than using msql_fetch_row, while it provides a significant added value.

参数

result
resource 型的结果集。此结果集来自对 msql_query 的调用。

result_type
A constant that can take the following values: MSQL_ASSOC, MSQL_NUM, and MSQL_BOTH with MSQL_BOTH being the default.

返回值

Returns an array that corresponds to the fetched row, or FALSE if there are no more rows.

范例

示例 #1 msql_fetch_array example

<?php
$con = msql_connect();
if (!$con) {
    die('Server connection problem: ' . msql_error());
}

if (!msql_select_db('test', $con)) {
    die('Database connection problem: ' . msql_error());
}

$result = msql_query('SELECT id, name FROM people', $con);
if (!$result) {
    die('Query execution problem: ' . msql_error());
}

while ($row = msql_fetch_array($result, MSQL_ASSOC)) {
    echo $row['id'] . ': ' . $row['name'] . "\n";
}

msql_free_result($result);
?>

更新日志

版本说明
5.0.4A bug was fixed when retrieving data from columns containing NULL values. Such columns were not placed into the resulting array.

参见

  • msql_fetch_row
  • msql_fetch_object
  • msql_data_seek
  • msql_result

msql_fetch_field

Get field information

说明

object msql_fetch_field ( resource $result [, int $field_offset = 0 ] )

msql_fetch_field can be used in order to obtain information about fields in a certain query result.

参数

result
resource 型的结果集。此结果集来自对 msql_query 的调用。

field_offset
The field offset. If not specified, the next field that wasn't yet retrieved by msql_fetch_field is retrieved.

返回值

Returns an object containing field information. The properties of the object are:

  • name - column name

  • table - name of the table the column belongs to

  • not_null - 1 if the column cannot be NULL

  • unique - 1 if the column is a unique key

  • type - the type of the column

参见

  • msql_field_seek

msql_fetch_object

Fetch row as object

说明

object msql_fetch_object ( resource $result )

msql_fetch_object is similar to msql_fetch_array, with one difference - an object is returned, instead of an array. Indirectly, that means that you can only access the data by the field names, and not by their offsets (numbers are illegal property names).

Speed-wise, the function is identical to msql_fetch_array, and almost as quick as msql_fetch_row (the difference is insignificant).

参数

result
resource 型的结果集。此结果集来自对 msql_query 的调用。

返回值

Returns an object with properties that correspond to the fetched row, or FALSE if there are no more rows.

范例

示例 #1 msql_fetch_object example

<?php
$con = msql_connect();
if (!$con) {
    die('Server connection problem: ' . msql_error());
}

if (!msql_select_db('test', $con)) {
    die('Database connection problem: ' . msql_error());
}

$result = msql_query('SELECT id, name FROM people', $con);
if (!$result) {
    die('Query execution problem: ' . msql_error());
}

while ($row = msql_fetch_object($result, MSQL_ASSOC)) {
    echo $row->id . ': ' . $row->name . "\n";
}

msql_free_result($result);
?>

更新日志

版本说明
5.0.4A bug was fixed when retrieving data from columns containing NULL values. Such columns were not placed into the resulting array.

参见

  • msql_fetch_array
  • msql_fetch_row
  • msql_data_seek
  • msql_result

msql_fetch_row

Get row as enumerated array

说明

array msql_fetch_row ( resource $result )

msql_fetch_row fetches one row of data from the result associated with the specified query identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.

Subsequent call to msql_fetch_row would return the next row in the result set, or FALSE if there are no more rows.

参数

result
resource 型的结果集。此结果集来自对 msql_query 的调用。

返回值

Returns an array that corresponds to the fetched row, or FALSE if there are no more rows.

范例

示例 #1 msql_fetch_row example

<?php
$con = msql_connect();
if (!$con) {
    die('Server connection problem: ' . msql_error());
}

if (!msql_select_db('test', $con)) {
    die('Database connection problem: ' . msql_error());
}

$result = msql_query('SELECT id, name FROM people', $con);
if (!$result) {
    die('Query execution problem: ' . msql_error());
}

while ($row = msql_fetch_row($result)) {
    echo $row[0] . ': ' . $row[1] . "\n";
}

msql_free_result($result);
?>

更新日志

版本说明
5.0.4A bug was fixed when retrieving data from columns containing NULL values. Such columns were not placed into the resulting array.

参见

  • msql_fetch_array
  • msql_fetch_object
  • msql_data_seek
  • msql_result

msql_field_flags

Get field flags

说明

string msql_field_flags ( resource $result , int $field_offset )

msql_field_flags returns the field flags of the specified field.

参数

result
resource 型的结果集。此结果集来自对 msql_query 的调用。

field_offset
数值型字段偏移量。 field_offset1 开始。

返回值

Returns a string containing the field flags of the specified key. This can be: primary key not null, not null, primary key, unique not null or unique.

msql_field_len

Get field length

说明

int msql_field_len ( resource $result , int $field_offset )

msql_field_len returns the length of the specified field.

参数

result
resource 型的结果集。此结果集来自对 msql_query 的调用。

field_offset
数值型字段偏移量。 field_offset1 开始。

返回值

Returns the length of the specified field or FALSE on error.

msql_field_name

Get the name of the specified field in a result

说明

string msql_field_name ( resource $result , int $field_offset )

msql_field_name gets the name of the specified field index.

参数

result
resource 型的结果集。此结果集来自对 msql_query 的调用。

field_offset
数值型字段偏移量。 field_offset1 开始。

返回值

The name of the field 或者在失败时返回 FALSE.

参见

  • msql_field_len

msql_field_seek

Set field offset

说明

bool msql_field_seek ( resource $result , int $field_offset )

Seeks to the specified field offset. If the next call to msql_fetch_field won't include a field offset, this field would be returned.

参数

result
resource 型的结果集。此结果集来自对 msql_query 的调用。

field_offset
数值型字段偏移量。 field_offset1 开始。

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

参见

  • msql_fetch_field

msql_field_table

Get table name for field

说明

int msql_field_table ( resource $result , int $field_offset )

Returns the name of the table that the specified field is in.

参数

result
resource 型的结果集。此结果集来自对 msql_query 的调用。

field_offset
数值型字段偏移量。 field_offset1 开始。

返回值

The name of the table on success 或者在失败时返回 FALSE.

msql_field_type

Get field type

说明

string msql_field_type ( resource $result , int $field_offset )

msql_field_type gets the type of the specified field index.

参数

result
resource 型的结果集。此结果集来自对 msql_query 的调用。

field_offset
数值型字段偏移量。 field_offset1 开始。

返回值

The type of the field. One of int, char, real, ident, null or unknown. This functions will return FALSE on failure.

msql_fieldflags

Alias of msql_field_flags

说明

此函数是该函数的别名: msql_field_flags.

msql_fieldlen

Alias of msql_field_len

说明

此函数是该函数的别名: msql_field_len.

msql_fieldname

Alias of msql_field_name

说明

此函数是该函数的别名: msql_field_name.

msql_fieldtable

Alias of msql_field_table

说明

此函数是该函数的别名: msql_field_table.

msql_fieldtype

Alias of msql_field_type

说明

此函数是该函数的别名: msql_field_type.

msql_free_result

Free result memory

说明

bool msql_free_result ( resource $result )

msql_free_result frees the memory associated with query_identifier. When PHP completes a request, this memory is freed automatically, so you only need to call this function when you want to make sure you don't use too much memory while the script is running.

参数

result
resource 型的结果集。此结果集来自对 msql_query 的调用。

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

msql_list_dbs

List mSQL databases on server

说明

resource msql_list_dbs ([ resource $link_identifier ] )

msql_list_tables lists the databases available on the specified link_identifier.

参数

link_identifier
mSQL 连接。如果不指定,则使用由 msql_connect 最近打开的连接。如果没有找到该连接,函数会尝试通过调用 msql_connect 建立连接并使用它。

返回值

Returns a result set which may be traversed with any function that fetches result sets, such as msql_fetch_array. On failure, this function will return FALSE.

参见

  • msql_list_tables
  • msql_list_fields

msql_list_fields

List result fields

说明

resource msql_list_fields ( string $database , string $tablename [, resource $link_identifier ] )

msql_list_fields returns information about the given table.

参数

database
The name of the database.

tablename
The name of the table.

link_identifier
mSQL 连接。如果不指定,则使用由 msql_connect 最近打开的连接。如果没有找到该连接,函数会尝试通过调用 msql_connect 建立连接并使用它。

返回值

Returns a result set which may be traversed with any function that fetches result sets, such as msql_fetch_array. On failure, this function will return FALSE.

参见

  • msql_list_tables
  • msql_list_dbs

msql_list_tables

List tables in an mSQL database

说明

resource msql_list_tables ( string $database [, resource $link_identifier ] )

msql_list_tables lists the tables on the specified database.

参数

database
The name of the database.

link_identifier
mSQL 连接。如果不指定,则使用由 msql_connect 最近打开的连接。如果没有找到该连接,函数会尝试通过调用 msql_connect 建立连接并使用它。

返回值

Returns a result set which may be traversed with any function that fetches result sets, such as msql_fetch_array. On failure, this function will return FALSE.

参见

  • msql_list_fields
  • msql_list_dbs

msql_num_fields

Get number of fields in result

说明

int msql_num_fields ( resource $result )

msql_num_fields returns the number of fields in a result set.

参数

result
resource 型的结果集。此结果集来自对 msql_query 的调用。

返回值

Returns the number of fields in the result set.

参见

  • msql_query
  • msql_fetch_field
  • msql_num_rows

msql_num_rows

Get number of rows in result

说明

int msql_num_rows ( resource $query_identifier )

msql_num_rows returns the number of rows in a result set.

参数

result
resource 型的结果集。此结果集来自对 msql_query 的调用。

返回值

Returns the number of rows in the result set.

参见

  • msql_num_fields

msql_numfields

Alias of msql_num_fields

说明

此函数是该函数的别名: msql_num_fields.

msql_numrows

Alias of msql_num_rows

说明

此函数是该函数的别名: msql_num_rows.

msql_pconnect

Open persistent mSQL connection

说明

resource msql_pconnect ([ string $hostname ] )

msql_pconnect acts very much like msql_connect with two major differences.

First, when connecting, the function would first try to find a (persistent) link that's already open with the same host. If one is found, an identifier for it will be returned instead of opening a new connection.

Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (msql_close will not close links established by this function).

参数

hostname
The hostname can also include a port number. e.g. hostname,port.

If not specified, the connection is established by the means of a Unix domain socket, being more efficient than a localhost TCP socket connection.

Note: While this function will accept a colon (:) as a host/port separator, a comma (,) is the preferred method.

返回值

Returns a positive mSQL link identifier on success, or FALSE on error.

参见

  • msql_connect
  • msql_close

msql_query

Send mSQL query

说明

resource msql_query ( string $query [, resource $link_identifier ] )

msql_query sends a query to the currently active database on the server that's associated with the specified link identifier.

参数

query
The SQL query.

link_identifier
mSQL 连接。如果不指定,则使用由 msql_connect 最近打开的连接。如果没有找到该连接,函数会尝试通过调用 msql_connect 建立连接并使用它。

返回值

Returns a positive mSQL query identifier on success, or FALSE on error.

范例

示例 #1 msql_query example

<?php 
$link = msql_connect("dbserver")
   or die("unable to connect to msql server: " . msql_error());
msql_select_db("db", $link)
   or die("unable to select database 'db': " . msql_error());

$result = msql_query("SELECT * FROM table WHERE id=1", $link);
if (!$result) {
   die("query failed: " . msql_error());
}

while ($row = msql_fetch_array($result)) {
    echo $row["id"];
}
?>

参见

  • msql_db_query
  • msql_select_db
  • msql_connect

msql_regcase

Alias of sql_regcase

说明

此函数是该函数的别名: sql_regcase.

msql_result

Get result data

说明

string msql_result ( resource $result , int $row [, mixed $field ] )

msql_result returns the contents of one cell from a mSQL result set.

When working on large result sets, you should consider using one of the functions that fetch an entire row (specified below). As these functions return the contents of multiple cells in one function call, they are often much quicker than msql_result.

Recommended high-performance alternatives: msql_fetch_row, msql_fetch_array, and msql_fetch_object.

参数

result
resource 型的结果集。此结果集来自对 msql_query 的调用。

row
The row offset.

field
Can be the field's offset, or the field's name, or the field's table dot field's name (tablename.fieldname.). If the column name has been aliased ('select foo as bar from ...'), use the alias instead of the column name.

Note:

Specifying a numeric field offset is much quicker than specifying a fieldname or tablename.fieldname.

返回值

Returns the contents of the cell at the row and offset in the specified mSQL result set.

msql_select_db

Select mSQL database

说明

bool msql_select_db ( string $database_name [, resource $link_identifier ] )

msql_select_db sets the current active database on the server that's associated with the specified link_identifier.

Subsequent calls to msql_query will be made on the active database.

参数

database_name
The database name.

link_identifier
mSQL 连接。如果不指定,则使用由 msql_connect 最近打开的连接。如果没有找到该连接,函数会尝试通过调用 msql_connect 建立连接并使用它。

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

参见

  • msql_connect
  • msql_pconnect
  • msql_query

msql_tablename

Alias of msql_result

说明

此函数是该函数的别名: msql_result.

msql

Alias of msql_db_query

说明

此函数是该函数的别名: msql_db_query.

目录