PHP新的连接MySQL方法mysqli
1. 开启PHP的API支持
(1)首先修改您的php.ini的配置文件。
查找下面的语句:
;extension=php_mysqli.dll
将其修改为:
extension=php_mysqli.dll
(2)重新启动Apache/IIS,即可。
(3)说明:PHP需要单独的文件来支持这个扩展库,一般在PHP目录下的ext目录里能找到php_mysqli.dll文件(PHP <=5.0.2 中是libmysqli.dll),当然,在PHP的配置文件当中要有正确指向ext的信息(extension_dir)。假若您的PHP没有这个文件,您可以去下载PHP5的源码包。另外,这个API扩展,只能在PHP5以上版本使用。其它具体信息,请看下面。
2. mysqli身份证
mysqli是“MySQL, Improved”的缩写,该扩展仅适用于PHP 5。它能用于MySQL4.1.1和更高版本。该扩展完全支持MySQL5.1中采用的鉴定协议,也支持预处理语句和多语句API。此外,该扩展还提供了先进的、面向对象的编程接口。在http://php.net/mysqli上,可找到关于mysqli扩展的文档。在http://www.zend.com/php5/articles/php5-mysqli.php处,给出了一篇有用的文章。
3. mysqli预定义类
mysqli
表达了 PHP 和 MySQL 数据库之间的连接。
构造函数
mysqli - 构造一个新的 mysqli 对象
方法
autocommit - 打开或关闭自动提交的数据库选项
change_user - 改变指定的数据库连接的用户
character_set_name - 返回数据库连接的默认字符集
close - 关闭一个之前打开的连接
commit - 提交当前事务
connect - 打开一个到 MySQL 数据库服务器的新连接
debug - 执行排错操作
dump_debug_info - 取得排错信息
get_client_info - 返回客户端版本
get_host_info - 返回连接使用的类型
get_server_info - 返回 MySQL 服务器的版本
get_server_version - 返回 MySQL 服务器的版本
init - 初始化 mysqli 对象
info - 取得最近执行的查询的信息
kill - 要求服务器停止一个 mysql 线程
multi_query - 执行多个查询
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 MySQL database server
escape_string - escapes special characters in a string for use in a SQLstatement, taking into account the current charset of the connection
rollback - rolls back the current transaction
select_db - selects the default database
set_charset - sets the default client character set
ssl_set - sets ssl parameters
stat - gets the current system status
stmt_init- initializes a statement for use with mysqli_stmt_prepare
store_result - transfers a resultset from last query
thread_safe - returns whether thread safety is given or not
use_result - transfers an unbuffered resultset from last query
属性
affected_rows - gets the number of affected rows in a previous MySQL operation
client_info - returns the MySQL client version as a string
client_version - returns the MySQL 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 MySQL protocol used
server_info - returns a string that represents the server version number
server_version - returns the version number of the server as an integer
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
补充类:
mysqli_affected_rows -返回一个MySQL操作受影响的行数
mysqli_autocommit -开启或关闭 autocommit 数据库修改
mysqli_bind_param -别名mysqli_stmt_bind_param ( )
mysqli_bind_result -别名mysqli_stmt_bind_result ( )
mysqli_change_user -更改指定数据库连接的用户
mysqli_character_set_name -返回数据库连接的默认字符集
mysqli_client_encoding -别名mysqli_character_set_name ( )
mysqli_close -关闭当前打开数据库连接
mysqli_commit -当前事物
mysqli_connect_errno -返回最后一次操作的错误代码
mysqli_connect_error -返回最后一次操作的错误字符串描述
mysqli_connect -打开一个新的连接到MySQL服务器
mysqli_data_seek -在当前记录结果集中任意移动行指针
mysqli_debug -调试
mysqli_disable_reads_from_master -禁用读取主对像
mysqli_disable_rpl_parse -禁用RPL解析
mysqli_dump_debug_info -转储调试信息的日志
mysqli_embedded_connect -打开一个连接到嵌入式MySQL服务器
mysqli_enable_reads_from_master -启用内容由主
mysqli_enable_rpl_parse -启用RPL解析
mysqli_errno -返回错误代码最近函数调用
mysqli_error -返回一个字符串描述过去的错误
mysqli_escape_string -别名mysqli_real_escape_string ( )
mysqli_execute -别名mysqli_stmt_execute ( )
mysqli_fetch_array -从结果集中取得一行作为关联,数字数组,或两者兼施
mysqli_fetch_assoc -从结果集中取得一行作为关联数组
mysqli_fetch_field_direct -获取元数据的一个单一的领域
mysqli_fetch_field -返回明年领域中的结果集
mysqli_fetch_fields -返回一个数组对象代表领域的结果集
mysqli_fetch_lengths -返回长度列的当前行的结果集
mysqli_fetch_object -返回当前行的结果集作为一个对象
mysqli_fetch_row -取得结果集中取得一行作为枚举数组
mysqli_fetch -别名mysqli_stmt_fetch ( )
mysqli_field_count -返回的列数最近查询
mysqli_field_seek -设为结果指针到指定的外地抵消
mysqli_field_tell -获取当前外地抵消的结果指针
mysqli_free_result -释放内存与结果
mysqli_get_client_info -返回MySQL客户端版本作为一个字符串
mysqli_get_client_version -取得MySQL客户端信息
mysqli_get_host_info -返回一个字符串代表的连接类型使用
mysqli_get_metadata -别名mysqli_stmt_result_metadata ( )
mysqli_get_proto_info -返回版本的MySQL使用协议
mysqli_get_server_info -返回版本的MySQL服务器
mysqli_get_server_version -返回版本的MySQL服务器作为一个整数
mysqli_info -检索信息,最近执行的查询
mysqli_init -初始化MySQLi并返回一个资源使用mysqli_real_connect ( )
mysqli_insert_id -返回自动生成的编号使用最后查询
mysqli_kill -要求服务器要杀死一个MySQL线程
mysqli_master_query -强制执行查询总在主/从设置
mysqli_more_results -检查是否有任何更多的查询结果来自一个多查询
mysqli_multi_query -执行查询数据库
mysqli_next_result -准备明年的结果multi_query
mysqli_num_fields -获取的若干领域中的结果
mysqli_num_rows -获取的行数的结果
mysqli_options -设置选项
mysqli_param_count -别名mysqli_stmt_param_count ( )
mysqli_ping -的Ping一个服务器连接,或尝试重新连接,如果已下降
mysqli_prepare -准备一个SQL语句的执行
mysqli_query -执行查询数据库
mysqli_real_connect -打开一个连接到MySQL服务器
mysqli_real_escape_string -转义特殊字符的字符串,用于SQL语句,并考虑到当前的字符集的连接
mysqli_real_query -执行一个SQL查询
mysqli_report -启用或禁用内部报告功能
mysqli_rollback -回滚当前事务
mysqli_rpl_parse_enabled -检查是否启用RPL解析
mysqli_rpl_probe - RPL探针
mysqli_rpl_query_type -返回RPL查询类型
mysqli_select_db -选择的默认数据库数据库查询
mysqli_send_long_data -别名mysqli_stmt_send_long_data ( )
mysqli_send_query -发送查询并返回
mysqli_server_end -关机嵌入式服务器
mysqli_server_init -初始化嵌入式服务器
mysqli_set_charset -集的默认客户端字符集
mysqli_set_opt -别名mysqli_options ( )
mysqli_sqlstate -返回SQLSTATE错误从一个MySQL操作
mysqli_ssl_set -用于建立安全连接使用SSL
mysqli_stat -获取当前的系统状态
mysqli_stmt_affected_rows -返回总数列改变,删除或插入的最后执行的声明
mysqli_stmt_bind_param -绑定变量一份声明作为参数
mysqli_stmt_bind_result -绑定变量的一份声明中存储的结果
mysqli_stmt_close -关闭一份声明
mysqli_stmt_data_seek -寻找一个任意行声明的结果集
mysqli_stmt_errno -返回错误代码的最新声明呼吁
mysqli_stmt_error -返回一个字符串描述最后声明错误
mysqli_stmt_execute -执行一个准备查询
mysqli_stmt_fetch -获取结果一份准备好的声明中纳入约束变量
mysqli_stmt_free_result -免储存记忆的结果给予处理的声明
mysqli_stmt_init -初始化了言,并返回一个对象,用于mysqli_stmt_prepare
mysqli_stmt_num_rows -返回的行数报表结果集
mysqli_stmt_param_count -返回一些参数给定的声明
mysqli_stmt_prepare -准备一个SQL语句的执行
mysqli_stmt_reset -重置一份声明
mysqli_stmt_result_metadata -返回结果集元数据的一份书面声明
mysqli_stmt_send_long_data -发送数据块
mysqli_stmt_sqlstate -返回SQLSTATE错误行动从以往的声明
mysqli_stmt_store_result -转让的结果集由一份声明
mysqli_store_result -转让的结果集的最后查询
mysqli_thread_id -返回线程ID为当前连接
mysqli_thread_safe -返回是否线程安全考虑或不
mysqli_use_result -开创检索结果集
mysqli_warning_count -返回一些警告过去查询提供链接
英文原版:
MySQL Improved Extension
- Introduction
- Overview
- Installing/Configuring
- The mysqli Extension and Persistent Connections
- Predefined Constants
- The MySQLi Extension Function Summary
- MySQLi — The MySQLi class
- mysqli->affected_rows — Gets the number of affected rows in a previous MySQL operation
- mysqli::autocommit — Turns on or off auto-commiting database modifications
- mysqli::change_user — Changes the user of the specified database connection
- mysqli::character_set_name — Returns the default character set for the database connection
- mysqli->client_info — Returns the MySQL client version as a string
- mysqli->client_version — Get MySQL client info
- mysqli::close — Closes a previously opened database connection
- mysqli::commit — Commits the current transaction
- mysqli->connect_errno — Returns the error code from last connect call
- mysqli->connect_error — Returns a string description of the last connect error
- mysqli::__construct — Open a new connection to the MySQL server
- mysqli::debug — Performs debugging operations
- mysqli::dump_debug_info — Dump debugging information into the log
- mysqli->errno — Returns the error code for the most recent function call
- mysqli->error — Returns a string description of the last error
- mysqli->field_count — Returns the number of columns for the most recent query
- mysqli::get_charset — Returns a character set object
- mysqli->get_client_info — Returns the MySQL client version as a string
- mysqli->client_version — Get MySQL client info
- mysqli::get_connection_stats — Returns statistics about the client connection
- mysqli->host_info — Returns a string representing the type of connection used
- mysqli->protocol_version — Returns the version of the MySQL protocol used
- mysqli->server_info — Returns the version of the MySQL server
- mysqli->server_version — Returns the version of the MySQL server as an integer
- mysqli::get_warnings — Get result of SHOW WARNINGS
- mysqli->info — Retrieves information about the most recently executed query
- mysqli::init — Initializes MySQLi and returns a resource for use with mysqli_real_connect()
- mysqli->insert_id — Returns the auto generated id used in the last query
- mysqli::kill — Asks the server to kill a MySQL thread
- mysqli::more_results — Check if there are any more query results from a multi query
- mysqli::multi_query — Performs a query on the database
- mysqli::next_result — Prepare next result from multi_query
- mysqli::options — Set options
- mysqli::ping — Pings a server connection, or tries to reconnect if the connection has gone down
- mysqli::poll — Poll connections
- mysqli::prepare — Prepare a SQL statement for execution
- mysqli::query — Performs a query on the database
- mysqli::real_connect — Opens a connection to a mysql server
- mysqli::real_escape_string — Escapes special characters in a string for use in a SQL statement, taking into account the current charset of the connection
- mysqli::real_query — Execute an SQL query
- mysqli::reap_async_query — Get result from async query
- mysqli::rollback — Rolls back current transaction
- mysqli::select_db — Selects the default database for database queries
- mysqli::set_charset — Sets the default client character set
- mysqli::set_local_infile_default — Unsets user defined handler for load local infile command
- mysqli::set_local_infile_handler — Set callback function for LOAD DATA LOCAL INFILE command
- mysqli->sqlstate — Returns the SQLSTATE error from previous MySQL operation
- mysqli::ssl_set — Used for establishing secure connections using SSL
- mysqli::stat — Gets the current system status
- mysqli::stmt_init — Initializes a statement and returns an object for use with mysqli_stmt_prepare
- mysqli::store_result — Transfers a result set from the last query
- mysqli::thread_id — Returns the thread ID for the current connection
- mysqli::thread_safe — Returns whether thread safety is given or not
- mysqli::use_result — Initiate a result set retrieval
- mysqli::warning_count — Returns the number of warnings from the last query for the given link
- MySQLi_STMT — The MySQLi_STMT class
- mysqli_result->current_field — Get current field offset of a result pointer
- mysqli_result::data_seek — Adjusts the result pointer to an arbitary row in the result
- mysqli_result::fetch_all — Fetches all result rows as an associative array, a numeric array, or both
- mysqli_result::fetch_array — Fetch a result row as an associative, a numeric array, or both
- mysqli_result::fetch_assoc — Fetch a result row as an associative array
- mysqli_result::fetch_field_direct — Fetch meta-data for a single field
- mysqli_result::fetch_field — Returns the next field in the result set
- mysqli_result::fetch_fields — Returns an array of objects representing the fields in a result set
- mysqli_result::fetch_object — Returns the current row of a result set as an object
- mysqli_result::fetch_row — Get a result row as an enumerated array
- mysqli_result->field_count — Get the number of fields in a result
- mysqli_result::field_seek — Set result pointer to a specified field offset
- mysqli_result::free — Frees the memory associated with a result
- mysqli_result->lengths — Returns the lengths of the columns of the current row in the result set
- mysqli_result->num_rows — Gets the number of rows in a result
- MySQLi_Driver — The MySQLi_Driver class
- mysqli_warning::__construct — The __construct purpose
- mysqli_warning::next — The next purpose
- Aliases and deprecated Mysqli Functions <ul class="" chunklist="" chunklist_book="" "="">
- mysqli_bind_param — Alias for mysqli_stmt_bind_param
- mysqli_bind_result — Alias for mysqli_stmt_bind_result
- mysqli_client_encoding — Alias of mysqli_character_set_name
- mysqli_disable_reads_from_master — Disable reads from master
- mysqli_disable_rpl_parse — Disable RPL parse
- mysqli_enable_reads_from_master — Enable reads from master
- mysqli_enable_rpl_parse — Enable RPL parse
- mysqli_escape_string — Alias of mysqli_real_escape_string
- mysqli_execute — Alias for mysqli_stmt_execute
- mysqli_fetch — Alias for mysqli_stmt_fetch
- mysqli_get_cache_stats — Returns client Zval cache statistics
- mysqli_get_client_stats — Returns client per-process statistics
- mysqli_get_metadata — Alias for mysqli_stmt_result_metadata
- mysqli_master_query — Enforce execution of a query on the master in a master/slave setup
- mysqli_param_count — Alias for mysqli_stmt_param_count
- mysqli_report — Enables or disables internal report functions
- mysqli_rpl_parse_enabled — Check if RPL parse is enabled
- mysqli_rpl_probe — RPL probe
- mysqli_rpl_query_type — Returns RPL query type
- mysqli_send_long_data — Alias for mysqli_stmt_send_long_data
- mysqli_send_query — Send the query and return
- mysqli_set_opt — Alias of mysqli_options
- mysqli_slave_query — Force execution of a query on a slave in a master/slave setup