PHP array_push将相同的值放入数组中?

时间:2017-10-12 13:09:01

标签: php mysql arrays mysqli array-push

我正在尝试为MySQLi创建自己的“数据库”类,它是与数据库共存的经典类,所以在我的Web应用程序中我可以做(例如)

$user = $database->select($connection, "SELECT * FROM user");

所以我编写了函数(这是查询中没有参数的部分)

public function select($link, $query, $types, $arrayValues)
{
    $set = array(); //this is what the function will return
    $statement;

    if($types == null && $arrayValues == null)
    {
        $statement = $link->prepare($query);
        if($statement->execute())
        {
            $statement->store_result();
            $meta = $statement->result_metadata();
            $fileds = array();
            $results = array();

            //put into the array the exact number of variables for call_user_func_array
            while($field = $meta->fetch_field())
            {
                $var = $field->name;
                $$var = null;
                $fields[$var] = &$$var;
            }
            $fieldCount = $statement->field_count;
            call_user_func_array(array($statement,'bind_result'),$fields);

            while($statement->fetch())
            {
                $set[] = $fields;
            }
            echo '<pre>';
            print_r($set);
            echo '</pre>';
        }
    }
    else
    {
         part of the function where there are parameters in the query
    }

    return $set;
}

现在的问题是$ set(必须返回)是一个数组,但是数组的所有值都是相同的:我用查询提取的最后一条记录。为什么?我疯了

0 个答案:

没有答案