本文實例講述了PHP提示 Deprecated: mysql_connect(): The mysql extension is deprecated的解決方法,在PHP程序開發中常會遇到這類問題。分享給大家供大家參考,具體的解決方法如下:
將下面代碼改為mysqli或PDO即可。
function connectit () { global $CFG; mysql_connect($CFG['db_host'], $CFG['db_user'], $CFG['db_pass']) or die(mysql_error()); mysql_select_db($CFG['db_name']); }
PDO:
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
MYSQLI:
$link = mysqli_connect( 'localhost', /* The host to connect to 連接MySQL地址 */ 'user', /* The user to connect as 連接MySQL用戶名 */ 'password', /* The password to use 連接MySQL密碼 */ 'world'); /* The default database to query 連接數據庫名稱*/ if (!$link) { printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error()); exit; }
希望本文所述對大家的PHP程序設計有所幫助。