当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > PHP MySQL

PHP
PHP Libxml
PHP Math
PHP Misc
PHP MySQL
PHP SimpleXML
PHP String
PHP XML
PHP Zip
PHP Mail
用PHP5的DirectoryIterators递归扫描目录
PHP 阻止SQL注入式攻击
PHP5面向对象 - 基础 - 类和对象
PHP5面向对象 - 基础 - 类的属性( public )
PHP5面向对象 - 基础 - 类的属性( private )
PHP5面向对象 - 基础 - 方法
PHP5面向对象 - 基础 - 对象的比较
php5面向对象 - 基础 - 构造函数
php5面向对象 - 基础 - 析构函数
用PHP控制用户的浏览器 - ob*函数的使用
PHP PDO 学习笔记

PHP MySQL


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 879 ::
收藏到网摘: n/a

PHP MySQL Introduction
PHP MySQL 函数介绍

The MySQL functions allows you to access MySQL database servers.
可以使用本类函数访问 MySQL 数据库服务器。


Installation
安装

For the MySQL functions to be available, you must compile PHP with MySQL support.
为了能够顺利的使用本类函数,必须在编译 PHP 的时候添加 MySQL 的支持。

For compiling, use --with-mysql=DIR (the optional DIR points to the MySQL directory).
编译时,只要使用 --with-mysql[=DIR] 配置选项即可,其中可选的 [DIR] 指向 MySQL 的安装目录。

Note: For full functionality of MySQL versions greater than 4.1., use the MySQLi extension instead. If you would like to install both the mysql extension and the mysqli extension you should use the same client library to avoid any conflicts.
注意:本 MySQL 扩展库不支持 MySQL 4.1.0 以上版本全部功能。对此,可用 MySQLi。如果要同时安装 mysql 扩展库和 mysqli 扩展库,必须使用同一个客户端库以避免任何冲突。

Installation on Linux Systems
Linux系统下的安装

PHP 5+: MySQL and the MySQL library is not enabled by default. Use the --with-mysql=DIR configure option to include MySQL support and download headers and libraries from www.mysql.com.
PHP 5+:MySQL 默认未启用,也没有绑定的 MySQL 库。使用 --with-mysql[=DIR] 配置选项来加入 MySQL 的支持。可以从 MySQL.COM 下载头文件和库。

Installation on Windows Systems
Windows系统下的安装

PHP 5+: MySQL is not enabled by default, so the php_mysql.dll must be enabled inside of php.ini. Also, PHP needs access to the MySQL client library. A file named libmysql.dll is included in the Windows PHP distribution, and in order for PHP to talk to MySQL this file needs to be available to the Windows systems PATH.
PHP 5+: MySQL 默认未启用,因此必须在 php.ini 中激活 php_mysql.dll 动态连接库。此外,PHP 还需要访问 MySQL 客户端连接库。 PHP 的 Windows 发行版包括了一个 libmysql.dll,为了让 PHP 能和 MySQL 对话,此文件必须放在 Windows 的系统路径 PATH 中。

To enable any PHP extension, the PHP extension_dir setting (in the php.ini file) should be set to the directory where the PHP extensions are located. An example extension_dir value is c:phpext.
要激活任何 PHP 扩展库(例如 php_mysql.dll),PHP 指令 extension_dir 要被设为 PHP 扩展库所在的目录。 PHP 5 下 extension_dir 取值的一个例子是 c:phpext。

Note: If you get the following error when starting the web server: "Unable to load dynamic library './php_mysql.dll'", this is because php_mysql.dll or libmysql.dll cannot be found by the system.
注意:如果启动 web 服务器时出现类似如下的错误:"Unable to load dynamic library './php_mysql.dll'",这是因为系统找不到 php_mysql.dll 和/或 libmysql.dll。


Runtime Configuration
运行时配置

The behavior of the MySQL functions is affected by settings in the php.ini file.
这些函数的行为受 php.ini 的影响。

MySQL configuration options:
MySQL配置选项

Name
名称
Default
默认值
Description
说明
Changeable
可修改范围
mysql.allow_persistent "1" Whether or not to allow persistent connections
是否允许 MySQL 的持久连接
PHP_INI_SYSTEM
mysql.max_persistent "-1" The maximum number of persistent connections per process
每个进程中最大的持久连接数目。
PHP_INI_SYSTEM
mysql.max_links "-1" The maximum number of connections per process (persistent connections included)
每个进程中最大的连接数,包括持久连接。
PHP_INI_SYSTEM
mysql.trace_mode "0" Trace mode. When set to "1", warnings and SQL-errors will be displayed. Available since PHP 4.3
跟踪模式。当激活 mysql.trace_mode 时,将会显示 table/index 扫描的警告,未释放的结果集以及 SQL 错误。(自PHP 4.3.0)
PHP_INI_ALL
mysql.default_port NULL The default TCP port number to use
指定默认连接数据库的 TCP 端口号。
PHP_INI_ALL
mysql.default_socket NULL The default socket name to use. Available since PHP 4.0.1
当使用本地连接的时候,默认的 socket 名称。
PHP_INI_ALL
mysql.default_host NULL The default server host to use (doesn't apply in SQL safe mode)
默认连接的数据库服务器地址。不适用于 SQL 安全模式。
PHP_INI_ALL
mysql.default_user NULL The default user name to use (doesn't apply in SQL safe mode)
默认连接数据库时使用的用户名。不适用于 SQL 安全模式。
PHP_INI_ALL
mysql.default_password NULL The default password to use (doesn't apply in SQL safe mode)
默认连接数据库时使用的密码。不适用于 SQL 安全模式。
PHP_INI_ALL
mysql.connect_timeout "60" Connection timeout in seconds
连接超时秒数。
PHP_INI_ALL

 


Resource Types
资源类型

There are two resource types used in the MySQL extension. The first one is the link_identifier for a database connection, the second is a resource which holds the result of a query.
在 MySQL 模块中使用了两种资源类型。第一种是数据库的连接句柄,第二种是 SQL 查询返回的结果集。

Note: Most MySQL functions accept link_identifier as the last optional parameter. If it is not provided, the last opened connection is used.
注意:大多数 MySQL 函数都接受 link_identifier 作为最后一个可选参数。如果未提供此参数,则使用最后一个打开的连接。


PHP MySQL Functions
PHP MySQL函数

PHP: indicates the earliest version of PHP that supports the function.
PHP:最早支持这些函数的PHP版本

Function
函数
Description
说明
PHP
mysql_affected_rows() Returns the number of affected rows in the previous MySQL operation
取得前一次 MySQL 操作所影响的记录行数
3
mysql_change_user() Deprecated. Changes the user of the current MySQL connection
不推荐。改变活动连接中登录的用户。
3
mysql_client_encoding() Returns the name of the character set for the current connection
返回字符集的名称
4
mysql_close() Closes a non-persistent MySQL connection
关闭 MySQL 连接
3
mysql_connect() Opens a non-persistent MySQL connection
打开一个到 MySQL 服务器的连接
3
mysql_create_db() Deprecated. Creates a new MySQL database. Use mysql_query() instead
不推荐。建立一个新的MySQL数据库,该函数用mysql_query() 函数来代替
3
mysql_data_seek() Moves the record pointer
移动内部结果的指针
3
mysql_db_name() Returns a database name from a call to mysql_list_dbs()
获取数据库名称(该数据库是通过请求mysql_list_dbs()函数列举的)
3
mysql_db_query() Deprecated. Sends a MySQL query. Use mysql_select_db() and mysql_query() instead
不推荐。发送一条 MySQL 查询。用mysql_select_db() 和mysql_query() 来代替
3
mysql_drop_db() Deprecated. Deletes a MySQL database. Use mysql_query() instead
不推荐。丢弃(删除)一个 MySQL 数据库。用mysql_query() 代替
3
mysql_errno() Returns the error number of the last MySQL operation
返回上一个 MySQL 操作中的错误信息的数字编码
3
mysql_error() Returns the error description of the last MySQL operation
返回上一个 MySQL 操作产生的文本错误信息
3
mysql_escape_string() Deprecated. Escapes a string for use in a mysql_query. Use mysql_real_escape_string() instead
不推荐。转义一个字符串用于 mysql_query。用mysql_real_escape_string()代替
4
mysql_fetch_array() Returns a row from a recordset as an associative array and/or a numeric array
从结果集中取得一行作为关联数组,或数字数组,或二者兼有
3
mysql_fetch_assoc() Returns a row from a recordset as an associative array
从结果集中取得一行作为关联数组
4
mysql_fetch_field() Returns column info from a recordset as an object
从结果集中取得列信息并作为对象返回
3
mysql_fetch_lengths() Returns the length of the contents of each field in a result row
取得结果集中每个输出的长度
3
mysql_fetch_object() Returns a row from a recordset as an object
从结果集中取得一行作为对象
3
mysql_fetch_row() Returns a row from a recordset as a numeric array
从结果集中取得一行作为枚举数组
3
mysql_field_flags() Returns the flags associated with a field in a recordset
从结果中取得和指定字段关联的标志
3
mysql_field_len() Returns the maximum length of a field in a recordset
返回指定字段的长度
3
mysql_field_name() Returns the name of a field in a recordset
取得结果中指定字段的字段名
3
mysql_field_seek() Moves the result pointer to a specified field
将结果集中的指针设定为制定的字段偏移量
3
mysql_field_table() Returns the name of the table the specified field is in
取得指定字段所在的表名
3
mysql_field_type() Returns the type of a field in a recordset
取得结果集中指定字段的类型
3
mysql_free_result() Free result memory
释放结果内存
3
mysql_get_client_info() Returns MySQL client info
取得 MySQL 客户端信息
4
mysql_get_host_info() Returns MySQL host info
取得 MySQL 主机信息
4
mysql_get_proto_info() Returns MySQL protocol info
取得 MySQL 协议信息
4
mysql_get_server_info() Returns MySQL server info
取得 MySQL 服务器信息
4
mysql_info() Returns information about the last query
取得最近一条查询的信息
4
mysql_insert_id() Returns the AUTO_INCREMENT ID generated from the previous INSERT operation
取得上一步 INSERT 操作产生的 ID
3
mysql_list_dbs() Lists available databases on a MySQL server
列出 MySQL 服务器中所有的数据库
3
mysql_list_fields() Deprecated. Lists MySQL table fields. Use mysql_query() instead
不推荐使用该函数。它是用来列出MySQL表字段的。我们建议使用mysql_query()函数代替。
3
mysql_list_processes() Lists MySQL processes
列出 MySQL 进程
4
mysql_list_tables() Deprecated. Lists tables in a MySQL database. Use mysql_query() instead
不推荐。列出 MySQL 数据库中的表。用mysql_query()代替
3
mysql_num_fields() Returns the number of fields in a recordset
取得结果集中字段的数目
3
mysql_num_rows() Returns the number of rows in a recordset
取得结果集中行的数目
3
mysql_pconnect() Opens a persistent MySQL connection
打开一个到 MySQL 服务器的持久连接
3
mysql_ping() Pings a server connection or reconnects if there is no connection
Ping 一个服务器连接,如果没有连接则重新连接
4
mysql_query() Executes a query on a MySQL database
发送一条 MySQL 查询
3
mysql_real_escape_string() Escapes a string for use in SQL statements
转义 SQL 语句中使用的字符串中的特殊字符,并考虑到连接的当前字符集
4
mysql_result() Returns the value of a field in a recordset
取得结果数据
3
mysql_select_db() Sets the active MySQL database
选择 MySQL 数据库
3
mysql_stat() Returns the current system status of the MySQL server
取得当前系统状态
4
mysql_tablename() Deprecated. Returns the table name of field. Use mysql_query() instead
不推荐。取得表名。用mysql_query()代替
3
mysql_thread_id() Returns the current thread ID
返回当前线程的 ID
4
mysql_unbuffered_query() Executes a query on a MySQL database (without fetching / buffering the result)
向 MySQL 发送一条 SQL 查询,并不获取和缓存结果的行
4

 


PHP MySQL Constants
PHP MySQL常量

Since PHP 4.3 it has been possible to specify additional flags for the mysql_connect() and mysql_pconnect() functions:
自PHP 4.3,可以为mysql_connect()和 mysql_pconnect()函数指定附加标志

PHP: indicates the earliest version of PHP that supports the constant.
PHP:最早支持这些常量的PHP版本

Constant
常量
Description
说明
PHP
MYSQL_CLIENT_COMPRESS Use compression protocol
使用压缩的通讯协议
4.3
MYSQL_CLIENT_IGNORE_SPACE Allow space after function names
允许在函数名后留空格位
4.3
MYSQL_CLIENT_INTERACTIVE Allow interactive timeout seconds of inactivity before closing the connection
允许设置断开连接之前所空闲等候的 interactive_timeout 时间(代替 wait_timeout)。
4.3
MYSQL_CLIENT_SSL Use SSL encryption (only available with version 4+ of the MySQL client library)
使用 SSL 加密。本标志仅在 MySQL 客户端库版本为 4.x 或更高版本时可用。
4.3

The mysql_fetch_array() function uses a constant for the different types of result arrays. The following constants are defined:
mysql_fetch_array() 函数使用一个常量来表示所返回数组的类型。下面是常量的定义:

Constant
常量
Description
说明
PHP
MYSQL_ASSOC Columns are returned into the array with the fieldname as the array index
返回的数据列使用字段名作为数组的索引名。
 
MYSQL_BOTH Columns are returned into the array having both a numerical index and the fieldname as the array index
返回的数据列使用字段名及数字索引作为数组的索引名。
 
MYSQL_NUM Columns are returned into the array having a numerical index (index starts at 0)
返回的数据列使用数字索引作为数组的索引名。索引从 0 开始,表示返回结果的第一个字段。
 

评论 (0) All

登陆 | 还没注册?