-1
所以我一直在試圖修改一些代碼,我下載了,和下面的代碼是在文件的頂部:MySQL連接和數據獲取
private $db; // Holds mysqli Variable
function __construct(){
$this->db = new mysqli('justcodeus.ipagemysql.com', 'autolike', '[my password]', 'autolike');
}
再往我創建了一個函數來獲取用戶的電子郵件:
public function get_email($username){
$query = "SELECT email FROM users WHERE username='$username'";
return mysql_result($this->db->query($query),0);
}
然後,終於,在另一個文件中,我有:
if($this->model->get_email("someuser") != null){
echo "User's email address is " . $this->model->get_email("roomzinchina");
}else{
echo "Could not find user or the function failed to run and/or turned up an error.";
}
中運行時,我得到Could not find user
消息,儘管在我的數據庫中有一個測試用戶名爲someuser
,電子郵件地址爲[email protected]
。任何想法爲什麼這可能不工作?
編輯: 在提到的第三個文件的頂部是require("model.php");
和$this->model = new Model();
。另外,如果我將return mysql_result($this->db->query($query),0);
更改爲return "test";
它可以正常工作,所以我認爲它一定是數據庫連接的問題。
你混合mysql_ *與mysqli_ *決定要使用.. – DeiForm
@DeiForm你能解釋一下我在哪裏二者混合均勻嗎? –
'new mysqli'建立一個mysqli連接。 'mysql_result'使用mysql擴展。他們不一起工作。 – deceze