forked from verdnatura/hedera-web
89 lines
1.9 KiB
PHP
Executable File
89 lines
1.9 KiB
PHP
Executable File
<?php
|
|
|
|
class RestMod extends Vn\Rest\Module
|
|
{
|
|
function run ()
|
|
{
|
|
if (!isset ($_REQUEST['sql']) || $_REQUEST['sql'] == '')
|
|
throw new Rest\Exception ('Conn', 'emptyQuery', s('EmptyQuery'));
|
|
|
|
$results = [];
|
|
$conn = $this->conn;
|
|
|
|
try {
|
|
if ($conn->multiQuery ($_REQUEST['sql']))
|
|
do {
|
|
$result = $conn->storeResult ();
|
|
|
|
if ($result !== FALSE)
|
|
{
|
|
$columns = $result->fetch_fields ();
|
|
|
|
$resultMap = [];
|
|
$resultMap['data'] = [];
|
|
$resultMap['field'] = $columns;
|
|
|
|
while ($row = $result->fetch_row ())
|
|
{
|
|
for ($j = 0; $j < $result->field_count; $j++)
|
|
{
|
|
$cell = &$row[$j];
|
|
|
|
if ($cell !== NULL)
|
|
switch ($columns[$j]->type)
|
|
{
|
|
case MYSQLI_TYPE_DATE:
|
|
case MYSQLI_TYPE_DATETIME:
|
|
case MYSQLI_TYPE_TIMESTAMP:
|
|
$cell = mktime
|
|
(
|
|
substr ($cell, 11 , 2)
|
|
,substr ($cell, 14 , 2)
|
|
,substr ($cell, 17 , 2)
|
|
,substr ($cell, 5 , 2)
|
|
,substr ($cell, 8 , 2)
|
|
,substr ($cell, 0 , 4)
|
|
);
|
|
break;
|
|
case MYSQLI_TYPE_BIT:
|
|
$cell = (bool) $cell;
|
|
break;
|
|
case MYSQLI_TYPE_TINY:
|
|
case MYSQLI_TYPE_SHORT:
|
|
case MYSQLI_TYPE_LONG:
|
|
case MYSQLI_TYPE_LONGLONG:
|
|
case MYSQLI_TYPE_INT24:
|
|
case MYSQLI_TYPE_YEAR:
|
|
$cell = (int) $cell;
|
|
break;
|
|
case MYSQLI_TYPE_FLOAT:
|
|
case MYSQLI_TYPE_DOUBLE:
|
|
case MYSQLI_TYPE_DECIMAL:
|
|
case MYSQLI_TYPE_NEWDECIMAL:
|
|
$cell = (float) $cell;
|
|
break;
|
|
}
|
|
}
|
|
|
|
$resultMap['data'][] = $row;
|
|
}
|
|
|
|
$results[] = $resultMap;
|
|
$result->free ();
|
|
}
|
|
else
|
|
$results[] = TRUE;
|
|
}
|
|
while ($conn->moreResults () && $conn->nextResult ());
|
|
}
|
|
catch (Db\Exception $e)
|
|
{
|
|
throw new Rest\Exception ('Conn', $e->getCode (), $e->getMessage ());
|
|
}
|
|
|
|
return $results;
|
|
}
|
|
}
|
|
|
|
?>
|