Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- #
- # Namespace Declaration
- #
- namespace MyAPI\App\Services\v1\Test;
- #
- # Required Files
- #
- require 'app/models/DatabaseTable.php';
- #
- # Use Namespaces
- #
- use Phalcon\Mvc\Model\Resultset\Simple as Resultset;
- use Phalcon\Di\FactoryDefault;
- use ChronosAPI\App\Models;
- class Test1RouteService
- {
- public function GetDbVersion()
- {
- try
- {
- // i deliberately failed this one to test the fatal error
- $sqlQry = "SELECT VERSIONs();";
- $conn = FactoryDefault::getDefault()->get("db");
- return $conn->fetchColumn($sqlQry);
- }
- catch(Throwable $e)
- {
- throw $e;
- }
- }
- public function GetSchemaTables($schema)
- {
- $sqlQry = "SELECT * FROM information_schema.`TABLES` WHERE TABLE_SCHEMA = '$schema' AND TABLE_TYPE = 'BASE TABLE';";
- $dbTable = new Models\DatabaseTable();
- $resultSet = new ResultSet(null, $dbTable, $dbTable->getReadConnection()->query($sqlQry));
- if(count($resultSet) == 0)
- {
- return "schema not found, or no tables defined.";
- }
- $data = [];
- foreach ($resultSet as $result) {
- $data[] = [
- 'TABLE_CATALOG' => $result->TABLE_CATALOG,
- 'TABLE_SCHEMA' => $result->TABLE_SCHEMA,
- 'TABLE_NAME' => $result->TABLE_NAME,
- 'TABLE_TYPE' => $result->TABLE_TYPE,
- 'ENGINE' => $result->ENGINE,
- 'VERSION' => $result->VERSION,
- 'ROW_FORMAT' => $result->ROW_FORMAT,
- 'TABLE_ROWS' => $result->TABLE_ROWS,
- 'AVG_ROW_LENGTH' => $result->AVG_ROW_LENGTH,
- 'DATA_LENGTH' => $result->DATA_LENGTH,
- 'MAX_DATA_LENGTH' => $result->MAX_DATA_LENGTH,
- 'INDEX_LENGTH' => $result->INDEX_LENGTH,
- 'DATA_FREE' => $result->DATA_FREE,
- 'AUTO_INCREMENT' => $result->AUTO_INCREMENT,
- 'CREATE_TIME' => $result->CREATE_TIME,
- 'UPDATE_TIME' => $result->UPDATE_TIME,
- 'CHECK_TIME' => $result->CHECK_TIME,
- 'TABLE_COLLATION' => $result->TABLE_COLLATION,
- 'CHECKSUM' => $result->CHECKSUM,
- 'CREATE_OPTIONS' => $result->CREATE_OPTIONS,
- 'TABLE_COMMENT' => $result->TABLE_COMMENT
- ];
- }
- return $data;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement