2013-08-20 102 views
0

我有一個selet函數,我傳遞兩個變量。表和地方。傳遞兩個變量

然而,無論我把爲它始終顯示ID = 1

難道這是因爲它認識到,ID有一個值,並將它設置爲1,還是我完全離開這裏的標誌?

功能如下:

public function select($table, $where){ 
    $sql = "SELECT * FROM $table WHERE $where"; 
    $result = mysql_query($sql); 
    if(mysql_num_rows($result) == 1){ 
     return $this->processRowSet($result, true); 
    } 
    return $this->processRowSet($result); 
} 

給函數的調用是:

$rowSet = $db->select('users','username = wayne'); 

或者是我的參數設置用戶名的方式嗎?

+2

的'mysql_ *'功能**不再維護**,不應在任何新的代碼庫中。它正逐漸被淘汰,轉而採用更新的API。相反,您應該使用[PDO](http://php.net/pdo)或[MySQLi]([**準備好的語句**])(https://www.youtube.com/watch?v=nLinqtCfhKY)( http://php.net/msqli)。 –

+0

同時使用'mysql_error()'來找出錯誤。然後將SQL字符串值用適當的引號括起來。 – mario

+0

'return $ this-> processRowSet($ result,mysql_num_rows($ result)== 1);'會保存在線。 – Niklas

回答

0

的用戶名是一個字符串,則有必要寫

$rowSet = $db->select('users','username = "wayne"');