Beispiel #1
0
if (!extension_loaded('mcrypt')) {
    die("Cygnite require mcrypt extension to run.");
}
require __DIR__ . "/../vendor/autoload.php";
function show($resultArray = array(), $hasExit = "")
{
    echo '<pre>';
    print_r($resultArray);
    echo '</pre>';
    if ($hasExit === 'exit') {
        exit;
    }
}
global $event;
//create Event handler to attach all events
$event = new Event();
$event->attach("exception", '\\Cygnite\\Exception\\Handler@handleException');
$config = array();
//Get the configuration variables.
$config = array('app' => Config::load(), 'event' => $event);
//unset($config);
//Load application and Get application instance to boot up
$application = Application::instance(function ($app) use($config) {
    /**
     *---------------------------------------------------
     * Set Configurations and Events for boot-up process
     * --------------------------------------------------
     */
    return $app->setConfiguration($config)->boot();
});
//Response to browser
Beispiel #2
0
 /**
  * Trash method
  *
  * Delete rows from the table and runs the query
  *
  * @access    public
  * @param array $where
  * $multiple false
  * @param bool  $multiple
  * @throws \Exception
  * @internal  param \Cygnite\Database\the $string table to retrieve the results from
  * @return object
  */
 public function trash($where, $multiple = false)
 {
     $whr = array();
     $column = $value = $statement = null;
     if (method_exists($this, 'beforeDelete')) {
         Event::instance()->trigger('beforeDelete', $this);
     }
     if (is_array($where) && $multiple == false) {
         $whr = array_keys($where);
         $column = $whr[0];
         $value = $where[$whr[0]];
         $condition = "` WHERE `" . $column . "` = " . $value;
     }
     if (is_string($where) || is_int($where)) {
         $column = $this->primaryKey;
         $value = $where;
         $condition = "` WHERE `" . $column . "` = " . $value;
     }
     $values = array();
     if (is_array($where) && $multiple == true) {
         $condition = "` WHERE `id` IN (" . implode(',', $where) . ")";
         $output = array_map(function ($val) {
             return '?';
         }, $where);
         $debugQuery = "` WHERE `id` IN (" . implode(',', $output) . ")";
         $sqlQuery = self::DELETE . " FROM `" . $this->tableName . $condition;
         $debugQuery = self::DELETE . " FROM `" . $this->tableName . $debugQuery;
     } else {
         $sqlQuery = self::DELETE . " FROM `" . $this->tableName . "` WHERE `" . $column . "` = :where";
         $debugQuery = self::DELETE . " FROM `" . $this->tableName . "` WHERE `" . $column . "` = " . $value;
     }
     /** @var $exception TYPE_NAME */
     try {
         $statement = $this->getDatabaseConnection()->prepare($sqlQuery);
         if (is_array($values) && empty($values)) {
             $statement->bindValue(':where', $value);
         }
         $affectedRows = null;
         $affectedRows = $statement->execute();
         if (method_exists($this, 'afterDelete')) {
             Event::instance()->trigger('afterDelete', $this);
         }
         return $affectedRows;
     } catch (\PDOException $exception) {
         throw new \Exception($exception->getMessage());
     }
 }