web/lib/Zend/Amf/Parse/Resource/MysqliResult.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_Amf
       
    17  * @subpackage Parse
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: MysqliResult.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    21  */
       
    22 
       
    23 /**
       
    24  * This class will convert mysql result resource to array suitable for passing
       
    25  * to the external entities.
       
    26  *
       
    27  * @package    Zend_Amf
       
    28  * @subpackage Parse
       
    29  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    30  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    31  */
       
    32 class Zend_Amf_Parse_Resource_MysqliResult
       
    33 {
       
    34 
       
    35     /**
       
    36      * mapping taken from http://forums.mysql.com/read.php?52,255868,255895#msg-255895
       
    37      */
       
    38     static public $mysqli_type = array(
       
    39         0 => "MYSQLI_TYPE_DECIMAL",
       
    40         1 => "MYSQLI_TYPE_TINYINT",
       
    41         2 => "MYSQLI_TYPE_SMALLINT",
       
    42         3 => "MYSQLI_TYPE_INTEGER",
       
    43         4 => "MYSQLI_TYPE_FLOAT",
       
    44         5 => "MYSQLI_TYPE_DOUBLE",
       
    45         7 => "MYSQLI_TYPE_TIMESTAMP",
       
    46         8 => "MYSQLI_TYPE_BIGINT",
       
    47         9 => "MYSQLI_TYPE_MEDIUMINT",
       
    48         10 => "MYSQLI_TYPE_DATE",
       
    49         11 => "MYSQLI_TYPE_TIME",
       
    50         12 => "MYSQLI_TYPE_DATETIME",
       
    51         13 => "MYSQLI_TYPE_YEAR",
       
    52         14 => "MYSQLI_TYPE_DATE",
       
    53         16 => "MYSQLI_TYPE_BIT",
       
    54         246 => "MYSQLI_TYPE_DECIMAL",
       
    55         247 => "MYSQLI_TYPE_ENUM",
       
    56         248 => "MYSQLI_TYPE_SET",
       
    57         249 => "MYSQLI_TYPE_TINYBLOB",
       
    58         250 => "MYSQLI_TYPE_MEDIUMBLOB",
       
    59         251 => "MYSQLI_TYPE_LONGBLOB",
       
    60         252 => "MYSQLI_TYPE_BLOB",
       
    61         253 => "MYSQLI_TYPE_VARCHAR",
       
    62         254 => "MYSQLI_TYPE_CHAR",
       
    63         255 => "MYSQLI_TYPE_GEOMETRY",
       
    64     );
       
    65 
       
    66     // Build an associative array for a type look up
       
    67     static $mysqli_to_php = array(
       
    68         "MYSQLI_TYPE_DECIMAL"     => 'float',
       
    69         "MYSQLI_TYPE_NEWDECIMAL"  => 'float',
       
    70         "MYSQLI_TYPE_BIT"         => 'integer',
       
    71         "MYSQLI_TYPE_TINYINT"     => 'integer',
       
    72         "MYSQLI_TYPE_SMALLINT"    => 'integer',
       
    73         "MYSQLI_TYPE_MEDIUMINT"   => 'integer',
       
    74         "MYSQLI_TYPE_BIGINT"      => 'integer',
       
    75         "MYSQLI_TYPE_INTEGER"     => 'integer',
       
    76         "MYSQLI_TYPE_FLOAT"       => 'float',
       
    77         "MYSQLI_TYPE_DOUBLE"      => 'float',
       
    78         "MYSQLI_TYPE_NULL"        => 'null',
       
    79         "MYSQLI_TYPE_TIMESTAMP"   => 'string',
       
    80         "MYSQLI_TYPE_INT24"       => 'integer',
       
    81         "MYSQLI_TYPE_DATE"        => 'string',
       
    82         "MYSQLI_TYPE_TIME"        => 'string',
       
    83         "MYSQLI_TYPE_DATETIME"    => 'string',
       
    84         "MYSQLI_TYPE_YEAR"        => 'string',
       
    85         "MYSQLI_TYPE_NEWDATE"     => 'string',
       
    86         "MYSQLI_TYPE_ENUM"        => 'string',
       
    87         "MYSQLI_TYPE_SET"         => 'string',
       
    88         "MYSQLI_TYPE_TINYBLOB"    => 'object',
       
    89         "MYSQLI_TYPE_MEDIUMBLOB"  => 'object',
       
    90         "MYSQLI_TYPE_LONGBLOB"    => 'object',
       
    91         "MYSQLI_TYPE_BLOB"        => 'object',
       
    92         "MYSQLI_TYPE_CHAR"        => 'string',
       
    93         "MYSQLI_TYPE_VARCHAR"     => 'string',
       
    94         "MYSQLI_TYPE_GEOMETRY"    => 'object',
       
    95         "MYSQLI_TYPE_BIT"         => 'integer',
       
    96     );
       
    97 
       
    98     /**
       
    99      * Parse resource into array
       
   100      *
       
   101      * @param resource $resource
       
   102      * @return array
       
   103      */
       
   104     public function parse($resource) {
       
   105 
       
   106         $result = array();
       
   107         $fieldcnt = mysqli_num_fields($resource);
       
   108 
       
   109 
       
   110         $fields_transform = array();
       
   111 
       
   112         for($i=0;$i<$fieldcnt;$i++) {
       
   113             $finfo = mysqli_fetch_field_direct($resource, $i);
       
   114 
       
   115             if(isset(self::$mysqli_type[$finfo->type])) {
       
   116                 $fields_transform[$finfo->name] = self::$mysqli_to_php[self::$mysqli_type[$finfo->type]];
       
   117             }
       
   118         }
       
   119 
       
   120         while($row = mysqli_fetch_assoc($resource)) {
       
   121             foreach($fields_transform as $fieldname => $fieldtype) {
       
   122                settype($row[$fieldname], $fieldtype);
       
   123             }
       
   124             $result[] = $row;
       
   125         }
       
   126         return $result;
       
   127     }
       
   128 }