Understanding fetch_assoc()

后端 未结 2 992
南旧
南旧 2021-02-02 00:20

I am trying to understand how/why fetch_assoc works the way it does. I have the following piece of code:

$results = $connectToDb->fetch(\"SELECT * FROM cust         


        
2条回答
  •  野性不改
    2021-02-02 00:52

    I think it useful:

    function get_posts(){
    $posts = array();
    if ($result = $mysqli->query("SELECT  id, post_userid, name, lang, country, post_image, post_date, post_date_updated FROM posts ORDER BY `post_date` DESC ;")) {
    
        while ($row = $result->fetch_assoc())
        {
            $posts[$row['id']] = $row ;   
        }
    } else {
        printf("Prepared Statement Error: %s\n", $mysqli->error);
    }
    return $posts;
    

    }

提交回复
热议问题