在学习
![](/icons/99567smhl.gif)
AJAX and PHP Building Responsive Web Applications
![](/icons/99567smhr.gif)
![](/icons/99567de.gif)
时候
![](/icons/99567dou.gif)
书中
![](/icons/99567de.gif)
源代码连接MySQL数据库部分采用了mysqli
![](/icons/99567de.gif)
思路方法
![](/icons/99567dou.gif)
假若说
![](/icons/99567dou.gif)
您
![](/icons/99567de.gif)
AJAX始终不能正常显示
![](/icons/99567dou.gif)
请根据下面
![](/icons/99567de.gif)
介绍进行操作
![](/icons/99567dou.gif)
您
![](/icons/99567de.gif)
问题将很快得到解答
![](/icons/99567dou2.gif)
1. 开启PHP
![](/icons/99567de.gif)
API支持
(1)首先修改您
![](/icons/99567de.gif)
php.ini
![](/icons/99567de.gif)
配置文件
![](/icons/99567dou2.gif)
查找下面
![](/icons/99567de.gif)
语句:
;extension=php_mysqli.dll
将其修改为:
extension=php_mysqli.dll
(2)重新启动Apache/IIS
![](/icons/99567dou.gif)
即可
![](/icons/99567dou2.gif)
(3)介绍说明:PHP需要单独
![](/icons/99567de.gif)
文件来支持这个扩展库
![](/icons/99567dou.gif)
![](/icons/99567yi.gif)
般在PHP目录下
![](/icons/99567de.gif)
ext目录里能找到php_mysqli.dll文件(PHP <= 5.0.2 中是 libmysqli.dll)
![](/icons/99567dou.gif)
当然
![](/icons/99567dou.gif)
在PHP
![](/icons/99567de.gif)
配置文件当中要有正确指向ext
![](/icons/99567de.gif)
信息(extension_dir)
![](/icons/99567dou2.gif)
假若您
![](/icons/99567de.gif)
PHP没有这个文件
![](/icons/99567dou.gif)
您可以去下载PHP5
![](/icons/99567de.gif)
源码包
![](/icons/99567dou2.gif)
另外
![](/icons/99567dou.gif)
这个API扩展
![](/icons/99567dou.gif)
只能在PHP5以上版本使用
![](/icons/99567dou2.gif)
其它具体信息
![](/icons/99567dou.gif)
请看下面
![](/icons/99567dou2.gif)
2. mysqli身份证
mysqli是“MySQL, Improved”
![](/icons/99567de.gif)
缩写
![](/icons/99567dou.gif)
该扩展仅适用于PHP 5
![](/icons/99567dou2.gif)
它能用于MySQL 4.1.1和更高版本
![](/icons/99567dou2.gif)
该扩展完全支持MySQL 5.1中采用
![](/icons/99567de.gif)
鉴定协议
![](/icons/99567dou.gif)
也支持预处理语句和多语句API
![](/icons/99567dou2.gif)
此外
![](/icons/99567dou.gif)
该扩展还提供了先进
![](/icons/99567de.gif)
、面向对象
![](/icons/99567de.gif)
编程接口
![](/icons/99567dou2.gif)
在http://php.net/mysqli上
![](/icons/99567dou.gif)
可找到有关mysqli扩展
![](/icons/99567de.gif)
文档
![](/icons/99567dou2.gif)
在http://www.zend.com/php5/articles/php5-mysqli.php处
![](/icons/99567dou.gif)
给出了
![](/icons/99567yi.gif)
篇有用
![](/icons/99567de.gif)
文章
![](/icons/99567dou2.gif)
3. mysqli预定义类
mysqli
表达了 PHP 和 MySQL 数据库的间
![](/icons/99567de.gif)
连接
![](/icons/99567dou2.gif)
构造
![](/icons/99567hanshu.gif)
mysqli - 构造
![](/icons/99567yi.gif)
个新
![](/icons/99567de.gif)
mysqli 对象
思路方法
autocommit - 打开或关闭自动提交
![](/icons/99567de.gif)
数据库选项
change_user - 改变指定
![](/icons/99567de.gif)
数据库连接
![](/icons/99567de.gif)
用户
character_
![](/icons/99567set.gif)
_name - 返回数据库连接
![](/icons/99567de.gif)
默认
![](/icons/99567zifu.gif)
集
close - 关闭
![](/icons/99567yi.gif)
个的前打开
![](/icons/99567de.gif)
连接
commit - 提交当前事务
connect - 打开
![](/icons/99567yi.gif)
个到 MySQL 数据库服务器
![](/icons/99567de.gif)
新连接
debug - 执行排错操作
dump_debug_info - 取得排错信息
get_client_info - 返回客户端版本
get_host_info - 返回连接使用
![](/icons/99567de.gif)
类型
get_server_info - 返回 MySQL 服务器
![](/icons/99567de.gif)
版本
get_server_version - 返回 MySQL 服务器
![](/icons/99567de.gif)
版本
init -
![](/icons/99567chushi.gif)
化 mysqli 对象
info - 取得最近执行
![](/icons/99567de.gif)
查询
![](/icons/99567de.gif)
信息
kill - 要求服务器停止
![](/icons/99567yi.gif)
个 mysql 线程
multi_query - 执行多个查询
more_results - check
![](/icons/99567if.gif)
more results exist from currently executed multi-query
next_result - reads next result from currently executed multi-query
options -
![](/icons/99567set.gif)
options
ping - pings a server connection or reconnects
![](/icons/99567if.gif)
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_
![](/icons/99567string.gif)
- escapes special characters in a
![](/icons/99567string.gif)
for use in a SQL statement, taking
![](/icons/99567int.gif)
o account the current char
![](/icons/99567set.gif)
of the connectionrollback - rolls back the current transaction
select_db - selects the default database
![](/icons/99567set.gif)
_char
![](/icons/99567set.gif)
-
![](/icons/99567set.gif)
s the default client character
![](/icons/99567set.gif)
ssl_
![](/icons/99567set.gif)
-
![](/icons/99567set.gif)
s ssl parameters
stat - gets the current system status
stmt_init- initializes a statement for use with mysqli_stmt_prepare
store_result - transfers a result
![](/icons/99567set.gif)
from last query
thread_safe -
![](/icons/99567return.gif)
s whether thread safety is given or not
use_result - transfers an unbuffered result
![](/icons/99567set.gif)
from last query
属性
affected_rows - gets the number of affected rows in a previous MySQL operation
client_info -
![](/icons/99567return.gif)
s the MySQL client version as a
![](/icons/99567string.gif)
client_version -
![](/icons/99567return.gif)
s the MySQL client version as an
![](/icons/99567int.gif)
eger
errno -
![](/icons/99567return.gif)
s the error code for the most recent function call
error -
![](/icons/99567return.gif)
s the error
![](/icons/99567string.gif)
for the most recent function call
field_count -
![](/icons/99567return.gif)
s the number of columns for the most recent query
host_info -
![](/icons/99567return.gif)
s a
![](/icons/99567string.gif)
representing the type of connection used
info - retrieves information about the most recently executed query
insert_id -
![](/icons/99567return.gif)
s the auto generated id used in the last query
protocol_version -
![](/icons/99567return.gif)
s the version of the MySQL protocol used
server_info -
![](/icons/99567return.gif)
s a
![](/icons/99567string.gif)
that represents the server version number
server_version -
![](/icons/99567return.gif)
s the version number of the server as an
![](/icons/99567int.gif)
eger
sqlstate -
![](/icons/99567return.gif)
s a
![](/icons/99567string.gif)
containing the SQLSTATE error code for the last error
thread_id -
![](/icons/99567return.gif)
s the thread ID for the current connection
warning_count -
![](/icons/99567return.gif)
s the number of warnings generated during execution of the previous SQL statement
4. 基本语法
<?php
/* Connect to a MySQL server 连接数据库服务器 */
$link = mysqli_connect(
'localhost', /* The host to connect to 连接MySQL地址 */
'user', /* The user to connect as 连接MySQL用户名 */
'password', /* The password to use 连接MySQL密码 */
'world'); /* The default database to query 连接数据库名称*/
(! $link) {
pr
f("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error
);
exit;
}
/* Send a query to the server 向服务器发送查询请求*/
( $result = mysqli_query( $link, 'SELECT Name, Population FROM City ORDER BY Population DESC LIMIT 5')) {
pr
("Very large cities are: ");
/* Fetch the results of the query 返回查询
结果 */
while( $row = mysqli_fetch_assoc( $result) ){
pr
f("%s (%s) ", $row['Name'], $row['Population']);
}
/* Destroy the result
and free the memory used for it 结束查询释放内存 */
mysqli_free_result( $result);
}
/* Close the connection 关闭连接*/
mysqli_close( $link);
?>