今天使用php7版本开发,使用mysql_connect连接数据库时
提示:Fatal error: Uncaught Error: Call to undefined function mysql_connect()
查了下手册发现是php7已经彻底移除了mysql扩展,同时删除的扩展和sapi还有:
sapi/aolserver
sapi/apache
sapi/apache_hooks
sapi/apache2filter
sapi/caudium
sapi/continuity
sapi/isapi
sapi/milter
sapi/nsapi
sapi/phttpd
sapi/pi3web
sapi/roxen
sapi/thttpd
sapi/tux
sapi/webjames
ext/mssql
ext/sybase_ct
ext/ereg
如果项目从php5.x升级到php7,得检查下是否使用到了上面的扩展
php连接mysql可以使用mysqli和pdo,推荐使用pdo方式
<?php
$pdo = new PDO('mysql:host=localhost;dbname=big;port=3306','root','123456');
$pdo->exec('set names utf8');
$stmt = $pdo->prepare("select * from ih_goods where goods_id =:id");
$stmt->bindValue(':id',1,PDO::PARAM_INT);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
print_r($rows);exit;