(mysql vs mysqli error(advait))
大家好,见代码。此代码在我的localhost WAMP Win7 php ver 5.5.12上运行,但它出错:
---
Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp\www\get_data02.php on line 9
Call Stack
# Time Memory Function Location
1 0.0010 135216 {main}( ) ..\get_data02.php:0
2 0.0010 135680 mysql_connect ( ) ..\get_data02.php:9
---
我尝试用mysqli替换mysql,但这只是给出了更多的错误。我该如何解决?谢谢,
<?php
// 1. Enter Database details
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'iamdb_copy_04';
// 2. Create a database connection
$connection = mysql_connect($dbhost,$dbuser,$dbpass);
if (!$connection) {
die("Database connection failed: " . mysql_error());
}
// 3. Select a database to use
$db_select = mysql_select_db($dbname,$connection);
if (!$db_select) {
die("Database selection failed: " . mysql_error());
}
$query = mysql_query("SELECT * FROM users WHERE city = 'city' ");
while ($rows = mysql_fetch_array($query)) {
$f_name = $rows['first_name'];
$address_01 = $rows['address_01'];
$city = $rows['city'];
echo "$f_name<br>$address_01<br>$city<br><br>";
}
?>
答案 0 :(得分:0)
有两种方法可以摆脱这个错误。
在php display_errors
启动后使用ini_set("display_errors",0)
在php文件中设置<?php
。
将mysql
替换为mysqli
,mysql_connect
,mysql_select_db
,mysql_query
中的mysql_fetch_array
。
如果您仍然遇到任何问题,请告诉我并说明您的错误。