예제 #1
0
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') {
                    $idFieldName = $field;
                }
                $fieldsListStr .= "        " . DBCore::getPrintableFieldString($field, $attributes);
            }
            $fieldsListStr = substr($fieldsListStr, 0, strlen($fieldsListStr) - 1);
            $className = getClassName($tableName);
            $content = str_replace(array('{{CLASS_NAME}}', '{{TABLE_NAME}}', '{{PRIMARY_KEY}}', '{{FIELDS_LIST}}', '{{YEAR}}', '{{AUTHOR}}', '{{EMAIL}}'), array($className, $tableName, $idFieldName, $fieldsListStr, date("Y"), AUTHOR, EMAIL), $tpl);
예제 #2
0
파일: DBCore.php 프로젝트: pomed/Framework
 /**
  * Executes SQL query with single record and return this record.
  *
  * @param string $query SQL query to execute.
  * @param string $types Types string (ex: "isdb").
  * @param array $params Parameters in the same order like types string.
  *
  * @return array Selected record with table names as keys or NULL if no
  *           data selected.
  * @throws DBCoreException If no one or more than one records selected.
  */
 public static function selectSingleRecord($query, $types = "", $params = array())
 {
     $stmt = self::doSelectQuery($query, $types, $params);
     if ($stmt !== false) {
         $record = null;
         if ($stmt->num_rows === 1) {
             $record = DBCore::bindResults($stmt);
         }
         $stmt->close();
         if (is_null($record)) {
             throw new DBCoreException("No one or more than one records selected.");
         }
         return $record;
     }
     return null;
 }