Friday, January 13, 2006

从PHP获得更快、更安全的Msyql链接?

今天在 apache 2.2 + PHP5.1.1 + MySQL 5.0.1 的环境上编译了PHP支持 mysqli() 的MySQL的功能,的确不错,链接速度提高了很多;想使用mysqli()需要在 PHP编译配置时加上到 MySQL 的 mysql_config 可执行文件的路径,比如我的就是

#./configure --with-mysqli=/opt/MySQL5/bin/mysql_config --enable-xslt --with-xslt-sablot --with-apxs=/opt/apache/bin/apxs --with-gd --with-zlib --with-pgsql=/opt/pgsql



mysqli() 同时提供 面向对象面向过程 的两种链接方式

< ?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

printf("Host information: %s\n", $mysqli->host_info);

/* close connection */
$mysqli->close();
?>



< ?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");

/* check connection */
if (!$link) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

printf("Host information: %s\n", mysqli_get_host_info($link));

/* close connection */
mysqli_close($link);
?>

No comments:

Post a Comment