Пример #1
0
 public static function find_by_name($name)
 {
     $sql = "SELECT * FROM users WHERE name = ? ORDER BY updated_at DESC LIMIT 1";
     $pdo = NeechyDatabase::connect_to_db();
     $query = $pdo->prepare($sql);
     $query->execute(array($name));
     $row = $query->fetch(PDO::FETCH_ASSOC);
     if ($row) {
         $user = new User($row);
     } else {
         $user = new User(array('name' => $name));
     }
     return $user;
 }
Пример #2
0
 private function setup_dev_environment()
 {
     $handler_path = NeechyPath::join(NEECHY_HANDLER_CORE_PATH, 'install', 'handler.php');
     require_once $handler_path;
     if (NeechyDatabase::database_exists(NeechyConfig::get('mysql_database'))) {
         error_log('Test database found.');
     } else {
         error_log('Setting up dev environment using test configuration file.');
         # Buffer console output.
         ob_start();
         $handler = new InstallHandler($this->request);
         $handler->setup_dev();
         ob_end_clean();
     }
 }
Пример #3
0
 public static function find_by_title($title)
 {
     $sql = "SELECT * FROM pages WHERE slug = ? ORDER BY created_at DESC LIMIT 1";
     $slug = self::title_to_slug($title);
     $pdo = NeechyDatabase::connect_to_db();
     $query = $pdo->prepare($sql);
     $query->execute(array($slug));
     $row = $query->fetch(PDO::FETCH_ASSOC);
     if ($row) {
         $page = new Page($row);
     } else {
         $page = new Page(array('title' => $title, 'slug' => $slug));
     }
     return $page;
 }
Пример #4
0
<?php

require_once '../core/neechy/config.php';
require_once '../core/neechy/database.php';
require_once '../core/neechy/response.php';
# Parse params
$params = explode('/', $_SERVER["REQUEST_URI"]);
$action = count($params) > 2 ? $params[2] : null;
# Must init config for NeechyDatabase
NeechyConfig::init();
# Response
$json = array('params' => $params, 'action' => $action);
# Router
if ($action == 'database') {
    NeechyDatabase::reset();
    $json['result'] = 'ok';
} else {
    $json['warning'] = 'Invalid action.';
}
$response = new NeechyResponse(json_encode($json), 200);
$response->send_headers();
$response->render();
Пример #5
0
 private function create_model_tables()
 {
     $this->println('Creating database tables');
     $tables_created = NeechyDatabase::create_model_tables();
     $this->println(sprintf("Created tables: %s", join(', ', $tables_created)));
 }
 private function destroy_database_if_exists($db_name)
 {
     $pdo = NeechyDatabase::connect_to_database_host();
     $pdo->exec(sprintf('DROP DATABASE IF EXISTS `%s`', $db_name));
     return $pdo;
 }
Пример #7
0
 public static function disconnect_from_db()
 {
     self::$pdo = null;
 }
Пример #8
0
        </tr>
        <tr>
          <td><?php 
echo NeechyConfig::get('mysql_database');
?>
</td>
          <td><?php 
echo NeechyConfig::get('mysql_host');
?>
</td>
          <td><?php 
echo NeechyConfig::get('mysql_user');
?>
</td>
          <td><?php 
echo NeechyDatabase::connection_status();
?>
</td>
        </tr>
      </table>

      <div class="form-group database-actions">
        <?php 
echo $t->open_form('', 'post', array('class' => 'form-inline'));
?>
          <?php 
if ($t->data('database_installed')) {
    ?>
            <?php 
    if ($t->data('confirm-reset-db')) {
        ?>
Пример #9
0
 public static function count()
 {
     $sql = sprintf('SELECT COUNT(*) FROM %s', self::extract_table_name());
     $pdo = NeechyDatabase::connect_to_db();
     return $pdo->query($sql)->fetchColumn();
 }
Пример #10
0
 public static function init_database()
 {
     NeechyDatabase::destroy_database();
     $pdo = NeechyDatabase::create_database();
     $pdo->query(sprintf('USE %s', NeechyConfig::get('mysql_database')));
 }
Пример #11
0
 public function reload()
 {
     NeechyDatabase::disconnect_from_db();
     NeechyConfig::init();
 }
Пример #12
0
 protected function drop_tables()
 {
     $dropped_tables = array();
     foreach (NeechyDatabase::core_model_classes() as $model_class) {
         $model = $model_class::drop_table_if_exists();
         $dropped_tables[] = $model->table;
     }
     return $dropped_tables;
 }