#setlinebreak(on)
 * PDO::FETCH_ASSOC値を配列で取得 [#u6a9cf18]
 #htmlinsert(googleAdsense.html)
 #ref(http://dozo.rgr.jp/img/img20_file.png,right,nolink,around,PHP::PEAR)
 
 [[PECL/pdo/fetch/FETCH_ASSOC>PDO::FETCH_ASSOC]]は結果を配列で返す。
 カラム名と値のハッシュ値として値を返す
 
 **利用できるメソッド [#ad07bf63]
  PDOクラス
  query
  PDOStatementクラス
  fetch,fetchAll,fetchColumn
 
 **組み合わせ可能なFETCHパラメータ [#q979ee33]
  PDO::FETCH_GROUP
 
 **fetchメソッドサンプルコード [#p4cd0f92]
  $sql = <<<SQL
         SELECT * FROM user_table 
 SQL;
  $stmtObj = $dbObj->query( $sql );
  while ( $rowObjs = $stmtObj->fetch( PDO::FETCH_ASSOC ) )
   print_r( $rowObjs );
 
 ***結果 [#ac046449]
  Array                  
  (                      
     [users_id] => 1    
     [users_name] => TARO
     [users_email] => taro@matrix.jp
  )                      
  Array                  
  (                      
     [users_id] => 2    
     [users_name] => JIRO
     [users_email] => jiro@matrix.jp
  )                      
 
 **fetchAllメソッドサンプルコード [#qd2c0a9a]
  while ( $rowObjs = $stmtObj->fetchAll( PDO::FETCH_ASSOC ) )
   print_r( $rowObjs );
 
 ***結果 [#d8dcb9f4]
  Array                  
  (                      
     [0] => Array       
         (              
             [users_id] => 1
             [users_name] => TARO
             [users_email] => taro@matrix.jp
         )              
                        
     [1] => Array       
         (              
             [users_id] => 2
             [users_name] => JIRO
             [users_email] => jiro@matrix.jp
         )              
 
 
 **組み合わせ使用サンプルコード [#te014241]
  $sql = <<<SQL
         SELECT * FROM user_table LEFT JOIN user_homepage USING( users_id );
  SQL;
  $stmtObj = $dbObj->query( $sql );
  while ( $rowObjs = $stmtObj->fetch(PDO::FETCH_LAZY | PDO::FETCH_OBJ) )
   print_r( $rowObjs );
 
 ***結果 [#b0bcdda5]
  Array                  
  (                      
     [1] => Array       
         (              
             [0] => Array
                 (      
                     [users_name] => TARO
                     [users_email] => taro@matrix.jp
                     [homepage_id] => 1
                     [homepage_url] => TARO Homepage
                     [homepage_name] => http://taro.matrix.jp
                 )      
                        
         )              
                        
     [2] => Array       
         (              
             [0] => Array
                 (      
                     [users_name] => JIRO
                     [users_email] => jiro@matrix.jp
                     [homepage_id] => 1
                     [homepage_url] => JIRO Homepage
                     [homepage_name] => http://jiro.matrix.jp
                 )      
                        
         )              
                        
  ・・・・・
  ・・・・・
                        
     [4] => Array       
         (              
             [0] => Array
                 (      
                     [users_name] => dozo
                     [users_email] => dozo@matrix.jp
                     [homepage_id] => 1
                     [homepage_url] => dozo Homepage
                     [homepage_name] => http://dozo.matrix.jp
                 )      
                        
             [1] => Array
                 (   
                     [users_name] => dozo
                     [users_email] => dozo@matrix.jp
                     [homepage_id] => 2
                     [homepage_url] => dozo Homepage2
                     [homepage_name] => http://dozo.matrix.jp/pear/
                 )
             [2] => Array
                 (   
                     [users_name] => dozo
                     [users_email] => dozo@matrix.jp
                     [homepage_id] => 3
                     [homepage_url] => dozo Homepage3
                     [homepage_name] => http://dozo.matrix.jp/blog/
                 )
         
         )
  
  )
 
 
 
 #comment
 
 


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Third Project
証券会社ランキング比較