コード例 #1
0
ファイル: list.php プロジェクト: pascal26/fabrik
 /**
  * Hack! copied from mysqli db driver to enable AES_ENCRYPT calls
  * Inserts a row into a table based on an objects properties
  *
  * @param   string  $table    The name of the table
  * @param   object  &$object  An object whose properties match table fields
  * @param   string  $keyName  The name of the primary key. If provided the object property is updated.
  *
  * @thorws Exception
  *
  * @return  bool
  */
 public function insertObject($table, &$object, $keyName = null)
 {
     $db = $this->getDb();
     $secret = $this->config->get('secret');
     $fmtSql = 'INSERT INTO ' . $db->qn($table) . ' ( %s ) VALUES ( %s ) ';
     $fields = array();
     $values = array();
     foreach (get_object_vars($object) as $k => $v) {
         if (is_array($v) or is_object($v) or $v === null) {
             continue;
         }
         if ($k[0] == '_') {
             // Internal field
             continue;
         }
         $fields[] = $db->qn($k);
         $val = $db->q($v);
         if (in_array($k, $this->encrypt)) {
             $val = "AES_ENCRYPT({$val}, '{$secret}')";
         }
         $values[] = $val;
     }
     $db->setQuery(sprintf($fmtSql, implode(",", $fields), implode(",", $values)));
     $db->execute();
     $id = $db->insertid();
     if ($keyName && $id) {
         $object->{$keyName} = $id;
     }
     FabrikHelperHTML::debug((string) $db->getQuery(), 'list model insertObject:');
     return true;
 }