2015-09-03 52 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)。

相关问题