2017-07-19 17 views
-4

這是我的config.php我在這段代碼(mysql和php)中有錯誤?

<?php mysql_connect('localhost', 'id2266180_test', 'testtest'); mysql_select_db ('id2266180_test');?> 

,這是錯誤

Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /storage/ssd2/180/2266180/public_html/config.php:9 Stack trace: #0 /storage/ssd2/180/2266180/public_html/index.php(3): include() #1 {main} thrown in /storage/ssd2/180/2266180/public_html/config.php on line 9

+2

'mysql_ *'功能也會被刪除PHP7的。而是使用'mysqli_ *'函數。 – MrDarkLynx

+0

謝謝@ MrDarkLynx –

+0

MySQL不見了,如果你想使用它,你需要降級到PHP 5.6 – HoogleyBoogley

回答

0

您也可以嘗試這樣的:

<?php mysqli_connect('localhost','id2266180_test','testtest','id2266180_test');?> 
+0

我在'index.html'中有這個警告,如果我改變了'Warning:mysqli_query()期望至少有2個參數, 1 /storage/ssd2/180/2266180/public_html/index.php給定線70上 警告:mysqli_num_rows()預計參數1被mysqli_result,在/存儲/ SSD2 /二百二十六萬六千一百八十零分之一百八十〇/的public_html /索引零給出。對行PHP 71 警告:mysqli_fetch_array()預計參數1被mysqli_result,空上線/storage/ssd2/180/2266180/public_html/index.php給出72' –

+0

請告訴我整個代碼 –

+0

看起來像你的連接沒有建立..! –

0

的第一件事是mysql_select_db是depcated。 使用此代碼:

<?php 
$con=mysqli_connect("localhost","my_user","my_password","my_db"); 
// Check connection 
if (mysqli_connect_errno()) 
    { 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
    } 

// ...some PHP code for database "my_db"... 

// Change database to "test" 
mysqli_select_db($con,"test"); 

// ...some PHP code for database "test"... 

mysqli_close($con); 
?> 
+0

如果我更改了'index.html',我會發出此警告警告: mysqli_query()需要至少2個參數,第1行在/storage/ssd2/180/2266180/public_html/index.php中給出1 012xx 警告:mysqli_num_rows()期望參數1爲mysqli_result,null在/ storage/ssd2中給出/180/2266180/public_html/index.php on line 71 警告:mysqli_fetch_array()期望參數1爲mysqli_result,null在第72行的/storage/ssd2/180/2266180/public_html/index.php中給出' –

+0

已有你在mysqli_query()中傳遞連接對象? –

0

你應該檢查,如果mysql模塊被加載。嘗試找出有:

<?php 
    phpinfo(); 
?> 

如果沒有加載它,你必須編輯php.ini,通過加載mysql的模塊。但請注意,mysql擴展名是已棄用,因爲從PHP 7.0開始PHP 5.5和已刪除。所以請嘗試使用mysqli,就像其他人已經說過的一樣。

0

下面的代碼,你可以嘗試:

<?php 
$con = mysqli_connect("localhost","my_user","my_password","my_db"); 

// Check connection 
if (mysqli_connect_errno()) 
    { 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
    } 
?>