mysqli_query()期望参数1为mysqli,给出的数组为

时间:2017-09-13 12:24:28

标签: php mysqli

当我运行以下查询时

$sql ="SELECT * FROM user_info JOIN Notifications ON user_info.user_info_id =Notifications.Sender_id AND Notifications.STATE=0 LIMIT 1";
$query=mysqli_query($con,$sql);
$num_rows=mysqli_num_rows($query);
$message=''

if($num_rows > 0){
    $con=mysqli_fetch_assoc($query);
    switch ($con['Notification_Type']){
        case'events':
            $var="Notifications".$con['user_info_id'];
            $sql_shown="SELECT *FROMevent WHERE event.notification_shown = 0 AND event.user_info_id='$var'LIMIT 1";
            $query_vi=mysqli_query($con,$sql_shown);
            $num_rows_vi=mysqli_num_rows($query_vi);
            $message.=$con['Sender_id']."has created a Event";
            echo $message;
        break;
    }
}

我收到以下错误:

  

mysqli_query()期望参数1为mysqli,

中给出的数组

这是我的用户表:

CREATE TABLE IF NOT EXISTS user_info(
    user_info_id INT(11) NOT NULL AUTO_INCREMENT,
    u_first_name VARCHAR(255) NOT NULL,
    u_last_name VARCHAR(255) NOT NULL,
    u_email VARCHAR(255) NOT NULL,
    u_mobile VARCHAR(255) NOT NULL,
    role ENUM('1yearM','1yearN','1yearR','1yearU','1yearS','2M','2R','2N','2U','2S','3M','3R','3N','3U','3S','4M','4R','4N','4U','4S','professor','librarian','admission_department') NOT NULL,
    password VARCHAR(255) NOT NULL,
    u_ip VARCHAR(255) NOT NULL, 
    signup_date DATETIME NOT NULL,
    last_login DATETIME NOT NULL,
    act_code VARCHAR(255) NOT NULL,
    activation enum('1','0') NOT NULL DEFAULT '0',
    PRIMARY KEY (user_info_id),
    UNIQUE KEY (u_email,u_mobile)
)

这是我的事件表:

CREATE TABLE IF NOT EXISTS Event(
    Event_id INT(11) NOT NULL AUTO_INCREMENT,
    Event_Name VARCHAR(255) NOT NULL,
    Event_location VARCHAR(255) NOT NULL,
    Event_Organizer VARCHAR(255) NOT NULL,    
    Event_Date_Posted DATETIME NOT NULL,
    Event_Starting_timings DATETIME NOT NULL,
    Event_Ending_timings DATETIME NOT NULL,
    Event_Day VARCHAR(255) NOT NULL,
    Event_Description text NOT NULL,
    Event_file_name VARCHAR(255) NOT NULL,
    Event_file_path VARCHAR(255) NOT NULL,
    Event_file_size VARCHAR(255) NOT NULL,
    user_info_id INT(11) NOT NULL,
    notification_shown ENUM('1','0') NOT NULL DEFAULT '0',
    PRIMARY KEY (Event_id),
    FOREIGN KEY (user_info_id) REFERENCES user_info(user_info_id)    
)

这是我的通知表:

CREATE TABLE IF NOT EXISTS Notifications(
    Notifications_id INT(11) NOT NULL AUTO_INCREMENT,
    Notification_Type VARCHAR(255) NOT NULL,
    Notification_Content VARCHAR(255) NOT NULL,
    Notification_Created_Date DATETIME NOT NULL,
    Notification_State ENUM('read','unread') NOT NULL DEFAULT 'unread',
    Is_Notification_Delete ENUM('1','0') NOT NULL DEFAULT '0',
    Notification_Deleted_Date DATETIME NOT NULL,
    Sender_id INT(11) NOT NULL,
    STATE ENUM('1','0') NOT NULL DEFAULT '0',
    Recipient_id INT(11) NOT NULL,
    PRIMARY KEY (Notifications_id)  
)

2 个答案:

答案 0 :(得分:1)

您使用以下行覆盖$con变量:

$con=mysqli_fetch_assoc($query);

在该行之前,您的$con变量是有效的MySQLi连接句柄。在该行之后,它不是数组。因此,您的mysqli_query()来电抱怨第一个参数不再是mysqli连接/对象/句柄,而是现在是一个数组(它不应该这样)。

更改您的$con=mysqli_fetch_assoc($query);,以便它不会使用MySQLi连接/对象/句柄覆盖您的$con变量,而是将结果写入不同的变量(可能是$userinfo ?)。

答案 1 :(得分:0)

检查您的$con是否已使用正确的方法mysqli_connect('')创建。