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 to Win32 Users:
In order to enable this module on a Windows environment, you must copy
msql.dll
from the DLL folder of the PHP/Win32
binary package to the SYSTEM32 folder of your windows machine.
(Ex:
C:\WINNT\SYSTEM32
or
C:\WINDOWS\SYSTEM32
)
这些函数的行为受
php.ini
的影响。
表格 1. mSQL configuration options
| Name
|
Default
|
Changeable
|
Changelog
|
| msql.allow_persistent
|
"1"
|
PHP_INI_ALL
|
|
| msql.max_persistent
|
"-1"
|
PHP_INI_ALL
|
|
| msql.max_links
|
"-1"
|
PHP_INI_ALL
|
|
有关 PHP_INI_* 常量进一步的细节与定义参见
附录 G
。
以下是配置选项的简要解释。
-
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 中,或者在运行时被动态加载后才有效。
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
(
$link
));
/* 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
);
?>
|
|