values() static public method

Makes it possible to use arrays for inputs instead of MySQL strings
static public values ( array $input ) : string
$input array
return string The final MySQL string, which will be used in the queries.
コード例 #1
0
ファイル: db.php プロジェクト: rigidus/ea
 function smartInsert($array)
 {
     self::getColumns();
     $collect = array();
     self::$values = '';
     foreach (self::$columns as $k => $v) {
         if (isset($array[$k])) {
             $v['value'] = $array[$k];
         } else {
             if (!empty($v['default'])) {
                 $v['value'] = $v['default'];
             }
         }
         if ($v['value'] === true) {
             $v['value'] = 1;
         } else {
             if ($v['value'] === false) {
                 $v['value'] = 0;
             }
         }
         if (!preg_match("/^([A-Z]+)\\(([\\w\\W]*?)\\)\$/", $v['value'])) {
             $collect[] = "'" . addslashes($v['value']) . "'";
         } else {
             $collect[] = $v['value'];
         }
     }
     self::$values = implode(', ', $collect);
     self::$sql = "INSERT `" . self::$table . "` VALUES (" . self::$values . "); ";
     self::query(self::$sql);
 }