Esempio n. 1
0
 /**
  * Executes a prepared statement.
  *
  * @param array $params OPTIONAL Values to bind to parameter placeholders.
  * @return bool
  */
 public function execute(array $params = null)
 {
     /*
      * Simple case - no query profiler to manage.
      */
     if ($this->_queryId === null) {
         return $this->_execute($params);
     }
     /*
      * Do the same thing, but with query profiler
      * management before and after the execute.
      */
     $prof = $this->_adapter->getProfiler();
     $qp = $prof->getQueryProfile($this->_queryId);
     if ($qp->hasEnded()) {
         $this->_queryId = $prof->queryClone($qp);
         $qp = $prof->getQueryProfile($this->_queryId);
     }
     if ($params !== null) {
         $qp->bindParams($params);
     } else {
         $qp->bindParams($this->_bindParam);
     }
     $qp->start($this->_queryId);
     $retval = $this->_execute($params);
     $prof->queryEnd($this->_queryId);
     return $retval;
 }
Esempio n. 2
0
 /**
  * Support method for fetching rows.
  *
  * @param  JO_Db_Table_Select $select  query options.
  * @return array An array containing the row results in FETCH_ASSOC mode.
  */
 protected function _fetch(JO_Db_Table_Select $select)
 {
     $stmt = $this->_db->query($select);
     $data = $stmt->fetchAll(JO_Db::FETCH_ASSOC);
     return $data;
 }
Esempio n. 3
0
 public static function installWithoutDemo(JO_Db_Adapter_Abstract $db)
 {
     mysql_connect($db->getConfig('host'), $db->getConfig('username'), $db->getConfig('password'));
     mysql_select_db($db->getConfig('dbname'));
     mysql_set_charset('utf8');
     $structure = APPLICATION_PATH . '/modules/install/structure.sql';
     if (!file_exists($structure)) {
         return false;
     }
     $queryes = self::getQueryes(file($structure));
     $results = array();
     foreach ($queryes as $query) {
         if (trim($query)) {
             try {
                 /*$results[] = */
                 (bool) mysql_query($query);
             } catch (JO_Exception $e) {
                 /*$results[] = false;*/
             }
         }
     }
     $request = JO_Request::getInstance();
     $results[] = $db->insert('users', array('user_id' => 1, 'username' => $request->getPost('username'), 'password' => md5(md5($request->getPost('password'))), 'register_datetime' => new JO_Db_Expr('NOW()'), 'status' => 'activate', 'groups' => 'a:1:{i:2;s:2:"on";}'));
     /*$results[] = */
     $db->update('system', array('value' => $request->getPost('admin_mail')), array('`key` = ?' => 'admin_mail'));
     /*$results[] = */
     $db->update('system', array('value' => $request->getPost('report_mail')), array('`key` = ?' => 'report_mail'));
     if (!in_array(false, $results)) {
         $db_set = "\r\r\n\tdb.adapter = \"MYSQLi\"\r\r\n\tdb.params.host = \"" . $db->getConfig('host') . "\"\r\r\n\tdb.params.username = \"" . $db->getConfig('username') . "\"\r\r\n\tdb.params.password = \"" . $db->getConfig('password') . "\"\r\r\n\tdb.params.dbname = \"" . $db->getConfig('dbname') . "\"\r\r\n\tdb.params.charset =\"utf8\"";
         $results[] = (bool) @file_put_contents(APPLICATION_PATH . '/config/config_db.ini', $db_set);
     }
     return !in_array(false, $results);
 }
Esempio n. 4
0
 /**
  * DB2-specific sequence id value
  *
  *  @param string $sequenceName
  *  @return integer
  */
 public function nextSequenceId($sequenceName)
 {
     $sql = 'SELECT NEXTVAL FOR ' . $this->_adapter->quoteIdentifier($sequenceName) . ' AS VAL FROM SYSIBM.SYSDUMMY1';
     $value = $this->_adapter->fetchOne($sql);
     return $value;
 }
Esempio n. 5
0
 /**
  * Quote a raw string.
  *
  * @param string $value     Raw string
  * @return string           Quoted string
  */
 protected function _quote($value)
 {
     if (is_int($value) || is_float($value)) {
         return $value;
     }
     /**
      * Use db2_escape_string() if it is present in the IBM DB2 extension.
      * But some supported versions of PHP do not include this function,
      * so fall back to default quoting in the parent class.
      */
     if (function_exists('db2_escape_string')) {
         return "'" . db2_escape_string($value) . "'";
     }
     return parent::_quote($value);
 }
Esempio n. 6
0
 /**
  * Special handling for PDO query().
  * All bind parameter names must begin with ':'
  *
  * @param string|JO_Db_Select $sql The SQL statement with placeholders.
  * @param array $bind An array of data to bind to the placeholders.
  * @return JO_Db_Statement_Pdo
  * @throws JO_Db_Adapter_Exception To re-throw PDOException.
  */
 public function query($sql, $bind = array())
 {
     if (empty($bind) && $sql instanceof JO_Db_Select) {
         $bind = $sql->getBind();
     }
     if (is_array($bind)) {
         foreach ($bind as $name => $value) {
             if (!is_int($name) && !preg_match('/^:/', $name)) {
                 $newName = ":{$name}";
                 unset($bind[$name]);
                 $bind[$newName] = $value;
             }
         }
     }
     try {
         return parent::query($sql, $bind);
     } catch (PDOException $e) {
         /**
          * @see JO_Db_Statement_Exception
          */
         require_once 'JO/Db/Statement/Exception.php';
         throw new JO_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
     }
 }
Esempio n. 7
0
 /**
  * IDS-specific sequence id value
  *
  *  @param string $sequenceName
  *  @return integer
  */
 public function nextSequenceId($sequenceName)
 {
     $sql = 'SELECT ' . $this->_adapter->quoteIdentifier($sequenceName) . '.NEXTVAL FROM ' . 'systables WHERE tabid = 1';
     $value = $this->_adapter->fetchOne($sql);
     return $value;
 }
Esempio n. 8
0
 /**
  * Render LIMIT OFFSET clause
  *
  * @param string   $sql SQL query
  * @return string
  */
 protected function _renderLimitoffset($sql)
 {
     $count = 0;
     $offset = 0;
     if (!empty($this->_parts[self::LIMIT_OFFSET])) {
         $offset = (int) $this->_parts[self::LIMIT_OFFSET];
         $count = PHP_INT_MAX;
     }
     if (!empty($this->_parts[self::LIMIT_COUNT])) {
         $count = (int) $this->_parts[self::LIMIT_COUNT];
     }
     /*
      * Add limits clause
      */
     if ($count > 0) {
         $sql = trim($this->_adapter->limit($sql, $count, $offset));
     }
     return $sql;
 }
Esempio n. 9
0
 /**
  * Verify that we have a valid connection.
  *
  * @param JO_Db_Adapter_Abstract $adapter
  * @return boolean
  * @throws JO_Db_Exception
  */
 public function isConnected(JO_Db_Adapter_Abstract $adapter)
 {
     try {
         return $adapter->getConnection() ? true : false;
     } catch (JO_Exception $e) {
         return false;
         //throw new JO_Db_Exception($e->getMessage());
     }
 }