我在安装lamp的时候,apache2.4,MySql57,PHP7.0都是下了压缩包到机子上源码安装的,apache和php能用,浏览器上可显示。但是运行如下例子的时候无反应
<!DOCTYPE html>
<html>
<head><title>test mysql </title>
<body>
<h1>test test fucking test</h1>
<?php
$mysqli = new mysqli("localhost", "root", "password", "dbname");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
echo $mysqli->host_info . "\n";
$mysqli = new mysqli("127.0.0.1", "root", "password", "dbname", 3306);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
echo $mysqli->host_info . "\n";
?>
</body>
</html>
我觉得是连接不上mysql的原因,且可能因为没有mysqli 扩展库,然后查阅各种方法例如如下安装
apt-get install php7.0-mysqli php7.0-mysqlnd
但是没有任何作用。
望各位大神指点迷津,我该怎么安装mysqli。谢谢!
PHP7.0自带mysqli的扩展库,叫mysqlnd。源码安装的话只要在configure的时候加上两个参数,就可以安装这个扩展。
如果你会用到PDO的话,可以将PDO也指定为mysqlnd:
这样make install之后就会有mysqli的扩展库。
不建议用apt-get来解决,如果源码安装的PHP就用源码的方式解决,如果apt-get安装的PHP就用apt-get的方式解决。