Trying to get property of non-object / Call to a member function bind_param() on boolean

前端 未结 2 1285
半阙折子戏
半阙折子戏 2021-01-17 01:08

I am aware that this question has been asked many times but the solutions doesn\'t seem to be working for me.

I am writing a simple blog and I wanted to make an arch

相关标签:
2条回答
  • 2021-01-17 01:40

    In regards to your updated status, fetch_assoc() is not a member of a mysqli statement object. However, fetch() is and is the member function you are looking for.

    You can also use bind_result() to access the data.

    So an example would look something like:

        $timestamp = time();
    
        //create select statement
        $stmt = $con->prepare("SELECT column_x, column_y, column_z FROM table_name WHERE date < ?");
    
        //bind $timestamp to the prepared statement
        $stmt->bind_param("i", $timestamp);
        $stmt->execute();
    
        //bind each selected column to a variable for iteration
        $stmt->bind_result($column_x, $column_y, $column_z);
        while($stmt->fetch())
        {
            echo $x . " " . $y . " " . $z . "\n";
        }
    

    Here is the reference link for the mysqli_stmt class

    edit: I would also like to point out that while a mysli_stmt object does have a num_rows property, it is not the same as the num_rows property on a query result.

    0 讨论(0)
  • 2021-01-17 01:43

    Have a read here: http://php.net/manual/en/mysqli.prepare.php prepare you get a false if it fails. Hence your error.

    The issue is your SQL your need to use ? in place of variable names and prepare expects the data to bind. I believe you want:

    $sql = "SELECT * FROM posts WHERE date >= ? AND date <= ? ORDER BY date DESC";
    $stmt->bind_param('ii', $from, $to);
    
    0 讨论(0)
提交回复
热议问题