示例#1
0
 public function exec($pdo_statement, $bindings = array(), $swallow_errors = false)
 {
     try {
         WaxLog::log("info", "[DB] " . $pdo_statement->queryString);
         if (count($bindings)) {
             WaxLog::log("info", "[DB] Values:" . join($bindings, ","));
         }
         $pdo_statement->execute($bindings);
     } catch (PDOException $e) {
         $err = $pdo_statement->errorInfo();
         switch ($e->getCode()) {
             case "42S02":
             case "42S22":
                 ob_start();
                 foreach (Autoloader::$plugin_array as $plugin) {
                     Autoloader::recursive_register(PLUGIN_DIR . $plugin["name"] . "/lib/model", "plugin", true);
                 }
                 Autoloader::include_dir(MODEL_DIR, true);
                 foreach (get_declared_classes() as $class) {
                     if (is_subclass_of($class, "WaxModel")) {
                         $class_obj = new $class();
                         $output = $class_obj->syncdb();
                         if (strlen($output)) {
                             echo $output;
                         }
                     }
                 }
                 $sync = false;
                 //Forces destruction and flushing of output buffer
                 ob_end_clean();
                 try {
                     $pdo_statement->execute($bindings);
                 } catch (PDOException $e) {
                     throw new WaxDBStructureException("{$err[2]}", "Database Structure Error", $pdo_statement->queryString . "\n" . print_r($bindings, 1));
                 }
                 break;
             default:
                 WaxLog::log("error", "[DB] {$err['2']} , SQL: " . $pdo_statement->queryString . ($bindings ? "\n" . print_r($bindings, 1) : ""));
                 if (!$swallow_errors) {
                     throw new WaxSqlException("{$err[2]}", "Error Preparing Database Query", $pdo_statement->queryString . "\n" . print_r($bindings, 1));
                 }
         }
     }
     return $pdo_statement;
 }
示例#2
0
 public function syncdb($dir = false)
 {
     if ($dir[1] && ($dir[1] == "test" || $dir[1] == "production")) {
         define("ENV", $dir[1]);
     }
     $this->app_setup();
     if ($dir && is_dir($dir)) {
         Autoloader::include_dir($dir, true);
     } else {
         Autoloader::include_dir(MODEL_DIR, true);
     }
     foreach (get_declared_classes() as $class) {
         if (is_subclass_of($class, "WaxModel")) {
             $class_obj = new $class();
             $output = $class_obj->syncdb();
             if (strlen($output)) {
                 $this->add_output($output);
             }
         }
     }
 }