0

我想运行我认为将是一个简单的查询。我想以写入 $data[i][k] 的相同 2D 样式返回一个数据库表(仅返回值)

我正在使用 PHP 的 PDO,我能得到的最接近的是:

$result=$database->query("SELECT * FROM `garage_statistics`",$bind = null,$fetch = 'FETCH_COLUMN');
$this->statement = $this->pdo->prepare($query);
$result = $this->statement->fetchAll(PDO::FETCH_COLUMN,1);

哪个返回

0 => string 'Garage2' (length=1)
1 => string 'Garage3' (length=7)
2 => string 'Garage4' (length=7)
3 => string 'Garage6' (length=7)
4 => string 'Garage7' (length=7)

但是我不能让它循环所有的列。我尝试了 fetchall 并返回:

array (size=10)
0 => 
array (size=14)
  'name' => string 't' (length=1)
  0 => string 't' (length=1)
  'tablename' => string 't' (length=1)
  1 => string 't' (length=1)
  'numfloors' => string '3' (length=1)
  2 => string '3' (length=1)
  'status' => string '4' (length=1)
  3 => string '4' (length=1)
  'numspots' => string '0' (length=1)
  4 => string '0' (length=1)
  'spotsinuse' => string '0' (length=1)
  5 => string '0' (length=1)
  'time' => string '2012-12-07 13:47:13' (length=19)
  6 => string '2012-12-07 13:47:13' (length=19)
1 => 
array (size=14)
  'name' => string 'Garage 3' (length=8)
  0 => string 'Garage 3' (length=8)
  'tablename' => string 'Garage3' (length=7)
  1 => string 'Garage3' (length=7)
  'numfloors' => string '2' (length=1)
  2 => string '2' (length=1)
  'status' => string '3' (length=1)
  3 => string '3' (length=1)
  'numspots' => string '0' (length=1)
  4 => string '0' (length=1)
  'spotsinuse' => string '0' (length=1)
  5 => string '0' (length=1)
  'time' => string '2012-12-07 13:49:46' (length=19)
   6 => string '2012-12-07 13:49:46' (length=19)

虽然这确实包含所有数据,但它有很多我不想要的东西。

有没有一种简单的方法可以使用 PDO 获取表的基本二维数组?

4

1 回答 1

0

$result = $this->statement->fetchAll(PDO::FETCH_NUM);

返回正确的类型

于 2012-12-07T20:39:32.143 回答