コード例 #1
0
ファイル: Install.php プロジェクト: noikiy/PD
 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);
 }
コード例 #2
0
ファイル: Abstract.php プロジェクト: NareshChennuri/pyng
 /**
  * Inserts a new row.
  *
  * @param  array  $data  Column-value pairs.
  * @return mixed         The primary key of the row inserted.
  */
 public function insert(array $data)
 {
     $this->_setupPrimaryKey();
     /**
      * JO_Db_Table assumes that if you have a compound primary key
      * and one of the columns in the key uses a sequence,
      * it's the _first_ column in the compound key.
      */
     $primary = (array) $this->_primary;
     $pkIdentity = $primary[(int) $this->_identity];
     /**
      * If this table uses a database sequence object and the data does not
      * specify a value, then get the next ID from the sequence and add it
      * to the row.  We assume that only the first column in a compound
      * primary key takes a value from a sequence.
      */
     if (is_string($this->_sequence) && !isset($data[$pkIdentity])) {
         $data[$pkIdentity] = $this->_db->nextSequenceId($this->_sequence);
     }
     /**
      * If the primary key can be generated automatically, and no value was
      * specified in the user-supplied data, then omit it from the tuple.
      */
     if (array_key_exists($pkIdentity, $data) && $data[$pkIdentity] === null) {
         unset($data[$pkIdentity]);
     }
     /**
      * INSERT the new row.
      */
     $tableSpec = ($this->_schema ? $this->_schema . '.' : '') . $this->_name;
     $this->_db->insert($tableSpec, $data);
     /**
      * Fetch the most recent ID generated by an auto-increment
      * or IDENTITY column, unless the user has specified a value,
      * overriding the auto-increment mechanism.
      */
     if ($this->_sequence === true && !isset($data[$pkIdentity])) {
         $data[$pkIdentity] = $this->_db->lastInsertId();
     }
     /**
      * Return the primary key value if the PK is a single column,
      * else return an associative array of the PK column/value pairs.
      */
     $pkData = array_intersect_key($data, array_flip($primary));
     if (count($primary) == 1) {
         reset($pkData);
         return current($pkData);
     }
     return $pkData;
 }