Beispiel #1
0
<?php

require_once "../modules/autoload.php";
require_once "../modules/dbconnection.php";
use Asymptix\db\DBCore;
use Asymptix\db\DBPreparedQuery;
use Asymptix\core\OutputStream;
const RESULTS_PATH = "../classes/db/";
const CLASS_TPL = "templates/bean.tpl";
const AUTHOR = "Dmytro Zarezenko";
const EMAIL = "*****@*****.**";
OutputStream::start();
if (!file_exists(RESULTS_PATH) || is_file(RESULTS_PATH)) {
    OutputStream::msg(OutputStream::MSG_ERROR, "Destination directory '" . RESULTS_PATH . "' doesn't exists.");
    OutputStream::close();
    exit;
}
OutputStream::msg(OutputStream::MSG_INFO, "Reading tables list...");
$query = new DBPreparedQuery("SHOW TABLES");
$stmt = $query->go();
if ($stmt !== false) {
    $tpl = file_get_contents(CLASS_TPL);
    while ($resultSet = DBCore::bindResults($stmt)) {
        $tableName = $resultSet['TABLE_NAMES']['Tables_in_' . conf\Config::getDBConfigParam('DBNAME')];
        OutputStream::msg(OutputStream::MSG_INFO, "Reading structure for table '" . $tableName . "'...");
        $idFieldName = 'id';
        $fieldsListStr = "";
        $fieldsList = DBCore::getTableFieldsList($tableName);
        if (!empty($fieldsList)) {
            foreach ($fieldsList as $field => $attributes) {
                if ($attributes['key'] === 'PRI') {
Beispiel #2
0
 /**
  * Performs preparation to the logging process.
  *
  * @throws LoggerException
  */
 public function start()
 {
     switch ($this->direction) {
         case self::TO_OUTPUT_STREAM:
             OutputStream::start();
             return;
         case self::TO_FILE:
             if (empty($this->fileName)) {
                 throw new LoggerException("Log file name is invalid");
             }
             if (file_exists($this->fileName)) {
                 if (!is_file($this->fileName)) {
                     throw new LoggerException("Log file name is invalid");
                 }
             }
             if (file_put_contents($this->fileName, "", FILE_APPEND) === false) {
                 throw new LoggerException("Can't write to a file");
             }
             return;
         case self::TO_DB:
             if (empty($this->dbObject) || !is_object($this->dbObject)) {
                 throw new LoggerException("Invalid LogDBObject object");
             }
             if (!method_exists($this->dbObject, "log")) {
                 throw new LoggerException("No log() method in the LogDBObject object");
             }
             return;
         default:
             throw new LoggerException("Invalid logging output direction type");
     }
 }
Beispiel #3
0
 /**
  * Outputs DB query debug information to the stream.
  *
  * @param string $query SQL query.
  * @param string $types SQL types string.
  * @param array $params List of SQL query parameters.
  */
 public static function showQueryDebugInfo($query = "", $types = "", array $params = array())
 {
     OutputStream::start();
     if (!empty($query)) {
         if (empty($types) && empty($params)) {
             OutputStream::message(OutputStream::MSG_INFO, "Q: " . $query);
         } else {
             if (strlen($types) === count($params)) {
                 $query = preg_replace('/\\s+/', ' ', $query);
                 $preparedQuery = $query;
                 $paramsStr = array();
                 for ($i = 0; $i < strlen($types); $i++) {
                     $query = preg_replace("/\\?/", DBField::sqlValue($types[$i], $params[$i]), $query, 1);
                     $paramsStr[] = $types[$i] . ": " . DBField::sqlValue($types[$i], $params[$i]);
                 }
                 OutputStream::message(OutputStream::MSG_INFO, "Q: " . $query);
                 OutputStream::message(OutputStream::MSG_INFO, "P: " . $preparedQuery);
                 OutputStream::message(OutputStream::MSG_INFO, "A: [" . implode(", ", $paramsStr) . "]");
             } else {
                 OutputStream::message(OutputStream::MSG_ERROR, "Number of types is not equal parameters number.");
                 OutputStream::message(OutputStream::MSG_INFO, "T: " . $types);
                 OutputStream::message(OutputStream::MSG_INFO, "A: [" . implode(", ", $params) . "]");
             }
         }
     } else {
         OutputStream::message(OutputStream::MSG_WARNING, "DB query is empty.");
     }
     OutputStream::close();
 }