import v1.1.0_beta1 | 2009-08-21
This commit is contained in:
69
libs/Zend/Amf/Parse/Resource/MysqlResult.php
Executable file
69
libs/Zend/Amf/Parse/Resource/MysqlResult.php
Executable file
@ -0,0 +1,69 @@
|
||||
<?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) 2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class will convert mysql result resource to array suitable for passing
|
||||
* to the external entities.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Parse_Resource_MysqlResult
|
||||
{
|
||||
/**
|
||||
* @var array List of Mysql types with PHP counterparts
|
||||
*
|
||||
* Key => Value is Mysql type (exact string) => PHP type
|
||||
*/
|
||||
static public $fieldTypes = array(
|
||||
"int" => "int",
|
||||
"timestamp" => "int",
|
||||
"year" => "int",
|
||||
"real" => "float",
|
||||
);
|
||||
/**
|
||||
* Parse resource into array
|
||||
*
|
||||
* @param resource $resource
|
||||
* @return array
|
||||
*/
|
||||
public function parse($resource) {
|
||||
$result = array();
|
||||
$fieldcnt = mysql_num_fields($resource);
|
||||
$fields_transform = array();
|
||||
for($i=0;$i<$fieldcnt;$i++) {
|
||||
$type = mysql_field_type($resource, $i);
|
||||
if(isset(self::$fieldTypes[$type])) {
|
||||
$fields_transform[mysql_field_name($resource, $i)] = self::$fieldTypes[$type];
|
||||
}
|
||||
}
|
||||
|
||||
while($row = mysql_fetch_assoc($resource)) {
|
||||
foreach($fields_transform as $fieldname => $fieldtype) {
|
||||
settype($row[$fieldname], $fieldtype);
|
||||
}
|
||||
$result[] = $row;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
127
libs/Zend/Amf/Parse/Resource/MysqliResult.php
Normal file
127
libs/Zend/Amf/Parse/Resource/MysqliResult.php
Normal file
@ -0,0 +1,127 @@
|
||||
<?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) 2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class will convert mysql result resource to array suitable for passing
|
||||
* to the external entities.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2009 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;
|
||||
}
|
||||
}
|
41
libs/Zend/Amf/Parse/Resource/Stream.php
Executable file
41
libs/Zend/Amf/Parse/Resource/Stream.php
Executable file
@ -0,0 +1,41 @@
|
||||
<?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) 2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class will convert stream resource to string by just reading it
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Parse_Resource_Stream
|
||||
{
|
||||
/**
|
||||
* Parse resource into string
|
||||
*
|
||||
* @param resource $resource Stream resource
|
||||
* @return array
|
||||
*/
|
||||
public function parse($resource) {
|
||||
return stream_get_contents($resource);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user