File: MysqliResult.php

package info (click to toggle)
zendframework 1.12.9%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 133,584 kB
  • sloc: xml: 1,311,829; php: 570,173; sh: 170; makefile: 125; sql: 121
file content (128 lines) | stat: -rw-r--r-- 4,384 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Amf
 * @subpackage Parse
 * @copyright  Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id$
 */

/**
 * This class will convert mysql result resource to array suitable for passing
 * to the external entities.
 *
 * @package    Zend_Amf
 * @subpackage Parse
 * @copyright  Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Amf_Parse_Resource_MysqliResult
{

    /**
     * mapping taken from http://forums.mysql.com/read.php?52,255868,255895#msg-255895
     */
    static public $mysqli_type = array(
        0 => "MYSQLI_TYPE_DECIMAL",
        1 => "MYSQLI_TYPE_TINYINT",
        2 => "MYSQLI_TYPE_SMALLINT",
        3 => "MYSQLI_TYPE_INTEGER",
        4 => "MYSQLI_TYPE_FLOAT",
        5 => "MYSQLI_TYPE_DOUBLE",
        7 => "MYSQLI_TYPE_TIMESTAMP",
        8 => "MYSQLI_TYPE_BIGINT",
        9 => "MYSQLI_TYPE_MEDIUMINT",
        10 => "MYSQLI_TYPE_DATE",
        11 => "MYSQLI_TYPE_TIME",
        12 => "MYSQLI_TYPE_DATETIME",
        13 => "MYSQLI_TYPE_YEAR",
        14 => "MYSQLI_TYPE_DATE",
        16 => "MYSQLI_TYPE_BIT",
        246 => "MYSQLI_TYPE_DECIMAL",
        247 => "MYSQLI_TYPE_ENUM",
        248 => "MYSQLI_TYPE_SET",
        249 => "MYSQLI_TYPE_TINYBLOB",
        250 => "MYSQLI_TYPE_MEDIUMBLOB",
        251 => "MYSQLI_TYPE_LONGBLOB",
        252 => "MYSQLI_TYPE_BLOB",
        253 => "MYSQLI_TYPE_VARCHAR",
        254 => "MYSQLI_TYPE_CHAR",
        255 => "MYSQLI_TYPE_GEOMETRY",
    );

    // Build an associative array for a type look up
    static $mysqli_to_php = array(
        "MYSQLI_TYPE_DECIMAL"     => 'float',
        "MYSQLI_TYPE_NEWDECIMAL"  => 'float',
        "MYSQLI_TYPE_BIT"         => 'integer',
        "MYSQLI_TYPE_TINYINT"     => 'integer',
        "MYSQLI_TYPE_SMALLINT"    => 'integer',
        "MYSQLI_TYPE_MEDIUMINT"   => 'integer',
        "MYSQLI_TYPE_BIGINT"      => 'integer',
        "MYSQLI_TYPE_INTEGER"     => 'integer',
        "MYSQLI_TYPE_FLOAT"       => 'float',
        "MYSQLI_TYPE_DOUBLE"      => 'float',
        "MYSQLI_TYPE_NULL"        => 'null',
        "MYSQLI_TYPE_TIMESTAMP"   => 'string',
        "MYSQLI_TYPE_INT24"       => 'integer',
        "MYSQLI_TYPE_DATE"        => 'string',
        "MYSQLI_TYPE_TIME"        => 'string',
        "MYSQLI_TYPE_DATETIME"    => 'string',
        "MYSQLI_TYPE_YEAR"        => 'string',
        "MYSQLI_TYPE_NEWDATE"     => 'string',
        "MYSQLI_TYPE_ENUM"        => 'string',
        "MYSQLI_TYPE_SET"         => 'string',
        "MYSQLI_TYPE_TINYBLOB"    => 'object',
        "MYSQLI_TYPE_MEDIUMBLOB"  => 'object',
        "MYSQLI_TYPE_LONGBLOB"    => 'object',
        "MYSQLI_TYPE_BLOB"        => 'object',
        "MYSQLI_TYPE_CHAR"        => 'string',
        "MYSQLI_TYPE_VARCHAR"     => 'string',
        "MYSQLI_TYPE_GEOMETRY"    => 'object',
        "MYSQLI_TYPE_BIT"         => 'integer',
    );

    /**
     * Parse resource into array
     *
     * @param resource $resource
     * @return array
     */
    public function parse($resource) {

        $result = array();
        $fieldcnt = mysqli_num_fields($resource);


        $fields_transform = array();

        for($i=0;$i<$fieldcnt;$i++) {
            $finfo = mysqli_fetch_field_direct($resource, $i);

            if(isset(self::$mysqli_type[$finfo->type])) {
                $fields_transform[$finfo->name] = self::$mysqli_to_php[self::$mysqli_type[$finfo->type]];
            }
        }

        while($row = mysqli_fetch_assoc($resource)) {
            foreach($fields_transform as $fieldname => $fieldtype) {
               settype($row[$fieldname], $fieldtype);
            }
            $result[] = $row;
        }
        return $result;
    }
}