2012-06-16 5 views
4
<?php 
$sth = $dbh->prepare("SELECT name, colour FROM fruit"); 
$sth->execute(); 

/* Fetch all of the remaining rows in the result set */ 
print("Fetch all of the remaining rows in the result set:\n"); 
$result = $sth->fetchAll(); 
print_r($result); 
?> 

위 예제의 출력 예시한다 :PDO :: FETCH_ASSOC PDO :: FETCH_ARRAY는 무엇입니까?

는 결과 집합에 남아있는 모든 행을 가져 오기 :

Array 
(
    [0] => Array 
     (
      [NAME] => pear 
      [0] => pear 
      [COLOUR] => green 
      [1] => green 
     ) 

    [1] => Array 
     (
      [NAME] => watermelon 
      [0] => watermelon 
      [COLOUR] => pink 
      [1] => pink 
     ) 

) 

이어야 my_sql_fetch_array 및 결과와 같은 결과를 얻을 수있는 모든 옵션 :

Array 
(
    [0] => Array 
     (

      [0] => pear 
      [1] => green 
     ) 

    [1] => Array 
     (

      [0] => watermelon    
      [1] => pink 
     ) 

) 

답변

8

http://php.net/manual/en/pdostatement.fetch.php

에서
$result = $sth->fetchAll(PDO::FETCH_NUM); 
+2

http://php.net/manual/en/pdostatement.fetchall.php 필자는 FETCH_NUM 옵션에 대해 언급하지 않았다. 어디서나 귀하의 팁과 함께 작동합니다. 감사합니다 – sophie

+0

FETCH_NUM은 fetchAll()이 아닌 fetch()에 대한 문서에 나열되어 있습니다. http://www.php.net/manual/en/pdostatement.fetch.php – Rafa

+0

@Rafa Hmm ... updated – Musa

0

시도의 사용이

$data = $sth->fetch(); 
print_r($data); 

은 당신을 도울 것입니다 바랍니다.