[英]mysql vs mysqli error when running php code in wamp stack
(mysql vs mysqli錯誤(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>";
}
?>
有兩種方法可以解決此錯誤。
設置display_errors
使用PHP文件關閉ini_set("display_errors",0)
的PHP的開始后<?php
。
更換mysql
與mysqli
中mysql_connect
, mysql_select_db
, mysql_query
, mysql_fetch_array
。
讓我知道您是否仍然遇到任何問題,並評論您的錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.