Beispiel #1
0
 /**
  * Executes the current select object and returns the result
  *
  * @param integer $fetchMode OPTIONAL
  * @return \mysqli_result
  */
 public function query()
 {
     if (!empty($this->_bind)) {
         throw new Exception('MDO doesn\'t support bind query now.');
     }
     return $this->_adapter->query($this->assemble());
 }
 /**
  * Execute a query on the database and logs it
  *
  * @throws Exception
  *
  * @param string $key
  *            name of the query
  * @param string $query
  * @param boolean $disable_foreign_key_checks
  * @param string $entity
  * @return void
  */
 public function executeSQL($key, $query, $disable_foreign_key_checks = true, $entity = null)
 {
     if ($entity !== null && $entity != $this->last_entity) {
         $this->log("------------------------------------------------------");
         $this->log("Entity: '{$entity}'");
         $this->log("------------------------------------------------------");
         $this->last_entity = $entity;
     }
     $this->log(" * Sync::executeSQL '{$key}'...");
     $total_time_start = microtime(true);
     if ($disable_foreign_key_checks) {
         $this->adapter->query('set foreign_key_checks=0');
         $this->log("  * FK : Foreign key check disabled");
     }
     try {
         $time_start = microtime(true);
         $result = $this->adapter->query($query, ZendDb::QUERY_MODE_EXECUTE);
         $affected_rows = $result->getAffectedRows();
         // Log stuffs
         $time_stop = microtime(true);
         $time = number_format($time_stop - $time_start, 2);
         $formatted_query = preg_replace('/(\\n)|(\\r)|(\\t)/', ' ', $query);
         $formatted_query = preg_replace('/(\\ )+/', ' ', $formatted_query);
         $this->log("  * SQL: " . substr(trim($formatted_query), 0, 70) . '...');
         $this->log("  * SQL: Query time {$time} sec(s))");
     } catch (\Exception $e) {
         $err = $e->getMessage();
         $msg = "Error running query ({$err}) : \n--------------------\n{$query}\n------------------\n";
         $this->log("[+] {$msg}\n");
         if ($disable_foreign_key_checks) {
             $this->log("[Error] Error restoring foreign key checks");
             $this->adapter->query('set foreign_key_checks=1');
         }
         throw new \Exception($msg);
     }
     if ($disable_foreign_key_checks) {
         $time_start = microtime(true);
         $this->adapter->query('set foreign_key_checks=1');
         $time_stop = microtime(true);
         $time = number_format($time_stop - $time_start, 2);
         $this->log("  * FK : Foreign keys restored");
     }
     $time_stop = microtime(true);
     $time = number_format($time_stop - $total_time_start, 2);
     $this->log(" * Time: {$time} secs, affected rows {$affected_rows}.");
 }
Beispiel #3
0
 /**
  * This method init $this->object
  */
 protected function _prepareTable($data)
 {
     $quoteTableName = $this->adapter->platform->quoteIdentifier($this->dbTableName);
     $deleteStatementStr = "DROP TABLE IF EXISTS " . $quoteTableName;
     $deleteStatement = $this->adapter->query($deleteStatementStr);
     $deleteStatement->execute();
     $createStr = "CREATE TABLE IF NOT EXISTS  " . $quoteTableName;
     $fields = $this->_getDbTableFields($data);
     $createStatementStr = $createStr . '(' . $fields . ') ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;';
     $createStatement = $this->adapter->query($createStatementStr);
     $createStatement->execute();
 }
Beispiel #4
0
{
    public function query();
}
// Адаптируемый интерфейс. Клиент с ним не умеет работать, но очень хочет
interface iAdaptee
{
    public function request();
}
// Класс, реализующий адаптирумым интерфейс
class Adaptee implements iAdaptee
{
    public function request()
    {
        return __CLASS__ . "::" . __METHOD__;
    }
}
class Adapter implements iTarget
{
    protected $adaptee = null;
    public function __construct()
    {
        $this->adaptee = new Adaptee();
    }
    public function query()
    {
        return $this->adaptee->request();
    }
}
$Target = new Adapter();
print $Target->query();
// "Adaptee::request"