標籤:
在php+mysql開發過程中,遇到如下提示:
Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead;
開發環境方面,Apach,PHP,Mysql為單獨安裝,未使用Integration Environment,版本如下:
PHP——5.6.3;
MySql——5.6.21-log;
使用mysqli替代mysql,代碼如下。
原有mysql部分代碼:
1 // 串連資料庫 2 $connection = mysql_connect("127.0.0.1:3306", "root", "root") or die("Can not connnect" . mysql_errno()); 3 4 // 設定編碼格式,防止頁面顯示亂碼 5 //mysql_query(‘set names utf8‘, $connection); 6 7 // 選擇資料庫 8 mysql_select_db("my_wiki", $connection); 9 10 // 查詢資料庫11 $sql = "select * from category";12 $result = mysql_query($sql);
對應的mysqli代碼:
1 // 串連資料庫2 $connection = new mysqli("172.25.5.79:3306", "root", "root","discuz");3 4 // 設定編碼格式,防止頁面顯示亂碼5 $connection->query("SET NAMES utf8");6 7 //查詢資料庫8 $sql = "select * from category";9 $result = $connection->query($sql);
PHP開發使用mysqli替代mysql