如何在PHP MYSQL中使用array_pop?

时间:2013-07-09 13:52:14

标签: php mysql

<?php
error_reporting(E_ALL ^ E_NOTICE);
$host    = "localhost";
$server  = "root";
$pass    = "";
$db_name = "table_name";


try {
    $dbc = new PDO("mysql:host=$host;dbname=$db_name", $server, $pass);
}
catch (PDOException $e) {
    echo $e->getMessage();
}


$query = $dbc->query("SELECT * FROM table_name ");


while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
    $q = array_pop($query);
}

我收到此错误消息Warning: array_pop() expects parameter 1 to be array

如何解决此错误?

1 个答案:

答案 0 :(得分:4)

你没有传递$row你传递$query(不是数组)。通过$row

$q = array_pop($row);