2015-09-03 49 views
1

我已經經歷了與這個錯誤有關的所有問題,並做了相應的更改,但錯誤未得到解決。數據庫連接沒有錯誤連接到mysql但在查詢數據庫時出錯。 該錯誤是mysqli_query()預計參數1是mysqli的,在線路中/Applications/MAMP/htdocs/NuSS_address_api/DB_Functions.php給定對象36 的代碼是下面mysqli_query()期望參數1是mysqli,給出的對象

private $con; 

//put your code here 
// constructor 
function __construct() { 

    require_once('DB_Connect.php'); 
    // connecting to database 
    $this->con = new DB_Connect(); 
    $this->con->connect(); 
} 

// destructor 
function __destruct() { 

} 

public function isUserExisted($email) { 

    $con = $this->con; 

    $sql = "SELECT email from users WHERE email = '$email'"; 

    $result = mysqli_query($con, $sql); //getting error in this line 
    if (!mysqli_query($con, $sql)) { 
     echo("Error description: " . mysqli_error($con)); 
    } 

    $no_of_rows = mysqli_num_rows($result); 
    echo $no_of_rows; 
    if ($no_of_rows > 0) { 
     // user existed 
     return true; 
    } else { 
     // user not existed 
     return false; 
    } 
} 

僅「錯誤說明:「被顯示,但錯誤沒有得到顯示

請幫助。

在此先感謝

+0

給我你的'DB_Connect()'內容 –

+0

是'mysqli_error()'還是'mysqli_query()'拋出錯誤?請將標題與您的問題進行比較並修正。 –

+0

如果你要打印錯誤,然後使用'mysqli_error()'方法 –

回答

2

因爲沒有什麼$sql可變

$sql = "SELECT email from users WHERE email = '$email'"; 

這意味着沒有數據從數據庫或$email值檢索是空

+0

如果這個幫助請** [ACCEPT ** it](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) –

0

您提供的連接變量作爲對象,但以程序方式查詢數據庫。做這樣的事情:

$result = $con->query($sql); 

相反:

$result = mysqli_query($con,$sql); 

或者連接到程序的方式你的數據庫了。

1

因爲mysqli_query需要一個mysqli對象的第一個參數,而是你給它一個db_connect對象,我認爲是你設置並保存mysqli一個作爲屬性。如果對象是私人的,請創建一個獲取者來檢索它($this->con->getRealCon()),或者如果是公共的,則只需檢索它($this->con->mysqli)。

相關問題