Mysqli准备了语句fetch_array

时间:2013-05-20 01:06:23

标签: php prepared-statement

我正在尝试让下面的代码正常工作,但它无法正常工作并给我以下错误

Fatal error: Call to a member function bind_param() on a non-object in 

有没有办法用预处理语句获取数组?

    if (move_uploaded_file($_FILES['file_to_upload']['tmp_name'], $final_uploads_location)) 
            {
                    $stmt = $mysqli->prepare("select * from test  where `username` = ? and `age` = ? ");
                    $stmt->bind_param('ss', $username, $age);
                    $stmt->store_result();
                    $stmt->execute();

                    if($stmt->num_rows < 1)
                {
                    $insert = $mysqli->prepare("insert into `test`(`username`, `age`, ) values(?,?)");
                    $insert->bind_param('ss', $username, $age);
                    $insert->execute();

                }
                else
                {
                    $check = mysqli_fetch_array($stmt);
                     global $identity;
                    }
            }

3 个答案:

答案 0 :(得分:0)

您在准备(mysqli::prepare)后查询返回false。这意味着您的查询有错误:未定义的字段,未显示的表或其他内容。

答案 1 :(得分:0)

尝试在数据库上执行完全查询。 我认为它给你一个数据库错误。

也许您的$ mysqli-&gt; prepare返回“False”值。 通过这个你试图在不存在的布尔数据类型上调用“bind_param”函数。

答案 2 :(得分:0)

$ stmt-&gt; bind_param(“s”,$ username);

一次只尝试一个......你们一个接一个地绑定每个语句。 然后执行查询。

看这里HERE