Advertisement
Guest User

.service.php

a guest
Jul 11th, 2019
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.17 KB | None | 0 0
  1. <?php
  2.  
  3.     #
  4.     # Namespace Declaration
  5.     #
  6.     namespace MyAPI\App\Services\v1\Test;
  7.  
  8.     #
  9.     # Required Files
  10.     #
  11.     require 'app/models/DatabaseTable.php';
  12.  
  13.     #
  14.     # Use Namespaces
  15.     #
  16.     use Phalcon\Mvc\Model\Resultset\Simple as Resultset;
  17.     use Phalcon\Di\FactoryDefault;
  18.     use ChronosAPI\App\Models;
  19.  
  20.  
  21.     class Test1RouteService
  22.     {
  23.         public function GetDbVersion()
  24.         {
  25.             try
  26.             {
  27.                 // i deliberately failed this one to test the fatal error
  28.                 $sqlQry = "SELECT VERSIONs();";
  29.  
  30.                 $conn = FactoryDefault::getDefault()->get("db");
  31.  
  32.                 return $conn->fetchColumn($sqlQry);
  33.             }
  34.             catch(Throwable $e)
  35.             {
  36.                 throw $e;
  37.             }
  38.         }
  39.  
  40.         public function GetSchemaTables($schema)
  41.         {
  42.             $sqlQry = "SELECT * FROM information_schema.`TABLES` WHERE TABLE_SCHEMA = '$schema' AND TABLE_TYPE = 'BASE TABLE';";
  43.  
  44.             $dbTable = new Models\DatabaseTable();
  45.  
  46.             $resultSet = new ResultSet(null, $dbTable, $dbTable->getReadConnection()->query($sqlQry));
  47.  
  48.  
  49.             if(count($resultSet) == 0)
  50.             {
  51.                 return "schema not found, or no tables defined.";
  52.             }
  53.  
  54.  
  55.             $data = [];
  56.  
  57.             foreach ($resultSet as $result) {
  58.                 $data[] = [
  59.                     'TABLE_CATALOG'   => $result->TABLE_CATALOG,
  60.                     'TABLE_SCHEMA'    => $result->TABLE_SCHEMA,
  61.                     'TABLE_NAME'      => $result->TABLE_NAME,
  62.                     'TABLE_TYPE'      => $result->TABLE_TYPE,
  63.                     'ENGINE'          => $result->ENGINE,
  64.                     'VERSION'         => $result->VERSION,
  65.                     'ROW_FORMAT'      => $result->ROW_FORMAT,
  66.                     'TABLE_ROWS'      => $result->TABLE_ROWS,
  67.                     'AVG_ROW_LENGTH'  => $result->AVG_ROW_LENGTH,
  68.                     'DATA_LENGTH'     => $result->DATA_LENGTH,
  69.                     'MAX_DATA_LENGTH' => $result->MAX_DATA_LENGTH,
  70.                     'INDEX_LENGTH'    => $result->INDEX_LENGTH,
  71.                     'DATA_FREE'       => $result->DATA_FREE,
  72.                     'AUTO_INCREMENT'  => $result->AUTO_INCREMENT,
  73.                     'CREATE_TIME'     => $result->CREATE_TIME,
  74.                     'UPDATE_TIME'     => $result->UPDATE_TIME,
  75.                     'CHECK_TIME'      => $result->CHECK_TIME,
  76.                     'TABLE_COLLATION' => $result->TABLE_COLLATION,
  77.                     'CHECKSUM'        => $result->CHECKSUM,
  78.                     'CREATE_OPTIONS'  => $result->CREATE_OPTIONS,
  79.                     'TABLE_COMMENT'   => $result->TABLE_COMMENT
  80.                 ];
  81.             }
  82.  
  83.             return $data;
  84.         }
  85.     }
  86.  
  87. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement