2012-04-17 90 views
-1

所以我連接到我的MySQL數據庫使用下面的代碼:mysql_connect - 拒絕訪問數據庫或數據庫不存在?

function dbConnect($h,$u,$p,$n) { 
    if (!$con = @mysql_connect($h,$u,$p)) {$err = err("There is a problem connecting to the database. ".mysql_error());} 
    else if ([email protected]_select_db($n,$con)) {$err = err("The database \"{$n}\" could not be found. Check your spelling, make sure the database exists, and that your database credentials allows you access to this database.");} 
    return (isset($err)) ? $err : ""; 
} 

問題是,如果他們把在一個錯誤的用戶名,的mysql_connect不會看到什麼毛病,並嘗試連接到數據庫,爲mysql_select_db()輸出一個錯誤。

所以我找到了this link。現在通常刪除「任何」用戶將是可行的,但我創建了一個類似phpMyAdmin的工具,並將連接到具有各種配置的不同數據庫。我怎麼知道哪個用戶名可以連接?我該如何區分數據庫名稱不存在和用戶名無法訪問?

+0

這是什麼'如果(!$ CON = @mysql_connect($ H,$ U,$ P))'? – Lion 2012-04-17 23:09:34

+0

嘗試刪除@s。你可能正在消除一個有用的錯誤。 – mqsoh 2012-04-17 23:11:07

+0

你甚至沒有關注你提到的[link](http://stackoverflow.com/questions/7312401/php-mysql-connect-not-returning-false)。 – Lion 2012-04-17 23:14:00

回答

1

使用mysql_errno()

看到錯誤代碼here

相關問題