也許我早已習慣於習慣於使用ORM方法從數據庫中提取數據,但我現在正在爲我的一個朋友製作一個簡單的小項目,這個項目不需要所有額外的guff MVC的,ORM的等等..下面是一個我正在建立在PHP中的類的查詢的例子。mysql意外的查詢輸出
$this->sqlstart();
$sql = "select label, setting from ".$this->_settings." where id <= 4";
$query = mysql_query($sql);
$result = array();
while($row = mysql_fetch_array($query))
{
$result[] = $row;
}
return $result;
從return $result
的輸出是:
Array
(
[0] => Array
(
[0] => Week 1 Pay
[label] => Week 1 Pay
[1] => 2995
[setting] => 2995
)
[1] => Array
(
[0] => Week 2 Pay
[label] => Week 2 Pay
[1] => 2995
[setting] => 2995
)
[2] => Array
(
[0] => Week 1 Dates
[label] => Week 1 Dates
[1] => 1-15
[setting] => 1-15
)
[3] => Array
(
[0] => Week 2 Dates
[label] => Week 2 Dates
[1] => 16-31
[setting] => 16-31
)
)
它應該是
Array
(
[0] => Array
(
[label] => Week 1 Pay
[setting] => 2995
)
[1] => Array
(
[label] => Week 2 Pay
[setting] => 2995
)
[2] => Array
(
[label] => Week 1 Dates
[setting] => 1-15
)
[3] => Array
(
[label] => Week 2 Dates
[setting] => 16-31
)
)
任何人都可以指出我在哪裏集合的附加數據是從哪裏來的?
檢查手冊'mysql_fetch_array()'。 http://php.net/manual/en/function.mysql-fetch-array.php –
@MichaelBerkowski我認爲你是對的。我應該更加努力地尋找。我可能偶然發現了答案 – chris
PS,這聽起來像是習慣於使用mysqli或PDO apis而不是obselete mysql的極好機會! –