Пример #1
0
 /**
  * Change Db table engine
  *
  * @param string $table
  *          - table name without prefix
  * @param string $engine
  *          - new engine name
  * @param boolean $returnQuery
  *          - optional, return update query
  * @return boolean | string
  * @throws Exception
  */
 public function changeTableEngine($engine, $returnQuery = false)
 {
     if ($this->_objectConfig->isLocked() || $this->_objectConfig->isReadOnly()) {
         $this->_errors[] = 'Can not build locked object ' . $this->_objectConfig->getName();
         return false;
     }
     $sql = 'ALTER TABLE `' . $this->_model->table() . '` ENGINE = ' . $engine;
     if ($returnQuery) {
         return $sql;
     }
     try {
         $this->_db->query($sql);
         $this->_logSql($sql);
         return true;
     } catch (Exception $e) {
         $this->_errors[] = $e->getMessage() . ' <br>SQL: ' . $sql;
         return false;
     }
 }
Пример #2
0
 /**
  * Executa o comando SQL dentro do Banco de Dados
  * 
  * @param string $sql
  * @param array $bind
  * @return bool 
  */
 public function query($sql, $bind = array())
 {
     $cmd = strtolower(substr($sql, 0, 6));
     ZendT_Config::$type = $this->_config['options']['charset'];
     $orderParam = array();
     foreach ($bind as $name => $value) {
         if ($value instanceof ZendT_Type_Date) {
             $value = $value->getIso();
             $value = str_replace('T', ' ', $value);
         } else {
             if ($value instanceof ZendT_Type_Number && in_array($cmd, array('insert', 'update'))) {
                 $value = $value->getValueToDb();
                 if (!$value) {
                     $value = null;
                 }
             } else {
                 if ($value instanceof ZendT_Type) {
                     $value = $value->getValueToDb();
                 }
             }
         }
         $bind[$name] = $value;
         if (!is_numeric($name)) {
             $orderParam[] = $name;
         }
     }
     if (count($orderParam) > 0) {
         sort($orderParam);
         $count = count($orderParam) - 1;
         for ($i = $count; $i >= 0; $i--) {
             $name = $orderParam[$i];
             $value = $bind[$name];
             if (substr($name, 0, 1) != ':') {
                 $sql = str_replace(':' . $name, $this->quote($value), $sql);
             } else {
                 $sql = str_replace($name, $this->quote($value), $sql);
             }
             unset($bind[$name]);
         }
     }
     /* if (count($bind) > 0) {
        foreach ($bind as $name => $value) {
        if (!is_numeric($name)) {
        if (substr($name, 0, 1) != ':') {
        $sql = str_replace(':' . $name, $this->quote($value), $sql);
        } else {
        $sql = str_replace($name, $this->quote($value), $sql);
        }
        unset($bind[$name]);
        }
        }
        } */
     return parent::query($sql, $bind);
 }
Пример #3
0
 /**
  * Overload the query method of Zend Db
  * So we can debug the sql message
  * @see Hush_Debug
  * @param string $sql
  * @param array $bind
  * @return Zend_Db_Statement_Interface
  */
 public function query($sql, $bind = array())
 {
     if ($this->_debug) {
         require_once 'Hush/Debug.php';
         $debug = Hush_Debug::getInstance();
         $debug->setWriter(new Hush_Debug_Writer_Html());
         // default can be override
         if (!$debug instanceof Hush_Debug) {
             require_once 'Zend/Db/Adapter/Exception.php';
             throw new Zend_Db_Adapter_Exception("Can not initialize 'Hush_Debug' instance");
         }
         if ($sql instanceof Zend_Db_Select) {
             $sql = $sql->__toString();
         }
         if (sizeof($bind) > 0) {
             $label = 'Prepared Sql >>>';
         } else {
             $label = 'Query Sql >>>';
         }
         $debug->debug($sql, '<font style="color:red">' . $label . '</font>');
     }
     return parent::query($sql, $bind);
 }
Пример #4
0
}
/******************************************************************************
 * Constants
 *****************************************************************************/
define('ROOT_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
define('ROOT_URL', get_base_url());
ini_set("include_path", ROOT_PATH . 'libs' . DIRECTORY_SEPARATOR);
$loader = (require_once ROOT_PATH . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php');
use Symfony\Component\ClassLoader\UniversalClassLoader;
$universalLoader = new UniversalClassLoader();
$universalLoader->useIncludePath(true);
$universalLoader->register();
require_once 'Zend/Db/Adapter/Mysqli.php';
/******************************************************************************
 * Loading of the options (default & user)
 *****************************************************************************/
if (!file_exists(ROOT_PATH . "options.php")) {
    die("The file options.php should exists, please read the instructions inside of 'options.php-example'.");
}
require_once ROOT_PATH . "options_default.php";
require_once ROOT_PATH . "options.php";
/******************************************************************************
 * Initialize all the global variables
 *****************************************************************************/
require_once ROOT_PATH . '/services.php';
$g_database = new Zend_Db_Adapter_Mysqli($g_options['mysql']);
$g_database->setFetchMode(Zend_Db::FETCH_OBJ);
$g_database->query("SET NAMES utf8");
if (!defined('KNB_NO_DATABASE_ACCESS')) {
    $g_user = $serviceContainer->get('connectedUser');
}