File indexing completed on 2025-01-26 05:29:15
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Amf 0017 * @subpackage Parse 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** 0024 * This class will convert mysql result resource to array suitable for passing 0025 * to the external entities. 0026 * 0027 * @package Zend_Amf 0028 * @subpackage Parse 0029 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0030 * @license http://framework.zend.com/license/new-bsd New BSD License 0031 */ 0032 class Zend_Amf_Parse_Resource_MysqliResult 0033 { 0034 0035 /** 0036 * mapping taken from http://forums.mysql.com/read.php?52,255868,255895#msg-255895 0037 */ 0038 static public $mysqli_type = array( 0039 0 => "MYSQLI_TYPE_DECIMAL", 0040 1 => "MYSQLI_TYPE_TINYINT", 0041 2 => "MYSQLI_TYPE_SMALLINT", 0042 3 => "MYSQLI_TYPE_INTEGER", 0043 4 => "MYSQLI_TYPE_FLOAT", 0044 5 => "MYSQLI_TYPE_DOUBLE", 0045 7 => "MYSQLI_TYPE_TIMESTAMP", 0046 8 => "MYSQLI_TYPE_BIGINT", 0047 9 => "MYSQLI_TYPE_MEDIUMINT", 0048 10 => "MYSQLI_TYPE_DATE", 0049 11 => "MYSQLI_TYPE_TIME", 0050 12 => "MYSQLI_TYPE_DATETIME", 0051 13 => "MYSQLI_TYPE_YEAR", 0052 14 => "MYSQLI_TYPE_DATE", 0053 16 => "MYSQLI_TYPE_BIT", 0054 246 => "MYSQLI_TYPE_DECIMAL", 0055 247 => "MYSQLI_TYPE_ENUM", 0056 248 => "MYSQLI_TYPE_SET", 0057 249 => "MYSQLI_TYPE_TINYBLOB", 0058 250 => "MYSQLI_TYPE_MEDIUMBLOB", 0059 251 => "MYSQLI_TYPE_LONGBLOB", 0060 252 => "MYSQLI_TYPE_BLOB", 0061 253 => "MYSQLI_TYPE_VARCHAR", 0062 254 => "MYSQLI_TYPE_CHAR", 0063 255 => "MYSQLI_TYPE_GEOMETRY", 0064 ); 0065 0066 // Build an associative array for a type look up 0067 static $mysqli_to_php = array( 0068 "MYSQLI_TYPE_DECIMAL" => 'float', 0069 "MYSQLI_TYPE_NEWDECIMAL" => 'float', 0070 "MYSQLI_TYPE_BIT" => 'integer', 0071 "MYSQLI_TYPE_TINYINT" => 'integer', 0072 "MYSQLI_TYPE_SMALLINT" => 'integer', 0073 "MYSQLI_TYPE_MEDIUMINT" => 'integer', 0074 "MYSQLI_TYPE_BIGINT" => 'integer', 0075 "MYSQLI_TYPE_INTEGER" => 'integer', 0076 "MYSQLI_TYPE_FLOAT" => 'float', 0077 "MYSQLI_TYPE_DOUBLE" => 'float', 0078 "MYSQLI_TYPE_NULL" => 'null', 0079 "MYSQLI_TYPE_TIMESTAMP" => 'string', 0080 "MYSQLI_TYPE_INT24" => 'integer', 0081 "MYSQLI_TYPE_DATE" => 'string', 0082 "MYSQLI_TYPE_TIME" => 'string', 0083 "MYSQLI_TYPE_DATETIME" => 'string', 0084 "MYSQLI_TYPE_YEAR" => 'string', 0085 "MYSQLI_TYPE_NEWDATE" => 'string', 0086 "MYSQLI_TYPE_ENUM" => 'string', 0087 "MYSQLI_TYPE_SET" => 'string', 0088 "MYSQLI_TYPE_TINYBLOB" => 'object', 0089 "MYSQLI_TYPE_MEDIUMBLOB" => 'object', 0090 "MYSQLI_TYPE_LONGBLOB" => 'object', 0091 "MYSQLI_TYPE_BLOB" => 'object', 0092 "MYSQLI_TYPE_CHAR" => 'string', 0093 "MYSQLI_TYPE_VARCHAR" => 'string', 0094 "MYSQLI_TYPE_GEOMETRY" => 'object', 0095 "MYSQLI_TYPE_BIT" => 'integer', 0096 ); 0097 0098 /** 0099 * Parse resource into array 0100 * 0101 * @param resource $resource 0102 * @return array 0103 */ 0104 public function parse($resource) { 0105 0106 $result = array(); 0107 $fieldcnt = mysqli_num_fields($resource); 0108 0109 0110 $fields_transform = array(); 0111 0112 for($i=0;$i<$fieldcnt;$i++) { 0113 $finfo = mysqli_fetch_field_direct($resource, $i); 0114 0115 if(isset(self::$mysqli_type[$finfo->type])) { 0116 $fields_transform[$finfo->name] = self::$mysqli_to_php[self::$mysqli_type[$finfo->type]]; 0117 } 0118 } 0119 0120 while($row = mysqli_fetch_assoc($resource)) { 0121 foreach($fields_transform as $fieldname => $fieldtype) { 0122 settype($row[$fieldname], $fieldtype); 0123 } 0124 $result[] = $row; 0125 } 0126 return $result; 0127 } 0128 }