如何将PHP变量传递给SQL Select查询

时间:2016-11-18 05:37:28

标签: php mysql sql mysqli

main.php文件中的功能

public function get_email_details($email, $table_name)
{
    $query_verify_email = "SELECT * FROM $table_name where u_email='$email'";
    $result = mysqli_query($this->connection,$query_verify_email) or die(mysql_error());
    return $result;
}

我正在使用此

来调用它
$result_get_email_details = $Object->get_email_details($email, $table_name);
$rows=mysql_fetch_array($result_get_email_details); // It is showing me error on this line
  

错误:mysql_fetch_assoc()期望参数1是资源,在我评论之后的上一行给出的对象。

请帮我解决这个SQL查询中的错误

6 个答案:

答案 0 :(得分:5)

您正在使用mysql_fetch_query ...

不应该是mysqli_fetch_query。请注意mysql中缺少 i

答案 1 :(得分:0)

使用此,

$result_get_email_details = $Object->get_email_details($email, $table_name);
$rows=mysqli_fetch_array($result_get_email_details); 

答案 2 :(得分:0)

尝试使用foreach($rows as $row),因为$ rows是数组的集合。它不是一个字符串。

答案 3 :(得分:0)

请使用 mysqli_fetch_query 代替 mysql_fetch_query

您的代码中错过了。请改变它。

答案 4 :(得分:-1)

mysqli_fetch_array()需要两个参数,尝试插入连接和查询对象

mysql_fetch_array($this->connection, $result_get_email_details);

答案 5 :(得分:-2)

$query = "SELECT * FROM " .$table_name. " where u_email=".$email;
$result = mysqli_query($connection_variable, $query);
mysqli_fetch_array($result ,MYSQL_ASSOC);
相关问题