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

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

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?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();
?>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?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);
?>
Share

Random Posts

0 Responses to “从PHP获得更快、更安全的Msyql链接?”


  • No Comments

Leave a Reply