<?php
$mysqli=new mysqli();
$mysqli->connect('localhost','root','123456','gywtest');
// 创建查询
$sqlstr='select * from student';
//发送查询给MySql
$result=$mysqli->query($sqlstr);
while($row=$result->fetch_object())
{
$name=$row->stuname;
echo $name;
}
?>
Fatal error: Class 'mysqli' not found in /home/lufangtao/Project/DB.php on line 3
解决方法:
/usr/local/php/bin/phpize 这里回车运行
出错:
Cannot find config.m4.
Make sure that you run './phpize' in the top level source directory of the module
解决方法:
PHP源码包文件夹下的EXT文件夹就是放置着目前版本的可用扩展,CD进去看看都有哪些你需要的?应该看到mysqli文件夹了吧~~~
在当前目录下执行phpize
[root@localhost mysqli]#/usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20090626
Zend Modeule Api No: 20090626
Zend Extension Api No: 220090626
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
解决方法:
yum install autoconf再次运行上面的命令即可。
[root@localhost mysqli]#./configure –prefix=/opt/mysqli –with-php-config=/opt/php/bin/php-config –with-mysqli=/opt/mysql/bin/mysql_config
[root@localhost mysqli]#make
[root@localhost mysqli]#make install
安装完成后会有提示扩展所在目录路径,如:
/opt/php/lib/php/extensions/no-debug-zts-20090626php
所需的mysqli.so便会在此目录下,接下来修改/opt/php/etc/下的php.ini文件,加入mysqli扩展,即加入如下一行:
extension=/opt/php/lib/php/extensions/no-debug-zts-20090626/mysqli.so
这里还是会出现错误:
解决不用扩展连接MySQL的方法。
最终还是没有解决MySQLi连接的问题,但是可以使用MySQL数据库了,下面是测试程序
<?php
$link=mysql_connect('localhost','root','123456');
if(!$link) echo "F!";
else echo "S!";
mysql_select_db("students") or die("Could not select database");
$query="SELECT * FROM student;";
$result=mysql_query($query) or die("Query failed");
print "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
print "\t<tr>\n";
foreach ($line as $col_value) {
print "\t\t<td>$col_value</td>\n";
}
print "\t</tr>\n"; }
print "</table>\n";
/* 释放资源 */
mysql_free_result($result);
mysql_close();
?>
~
在 CentOS 7.x / Fedora 21 上面体验 PHP 7.0
CentOS 6.3 安装LNMP (PHP 5.4,MyySQL5.6)
Ubuntu安装Nginx php5-fpm MySQL(LNMP环境搭建)