當前位置: 首頁>>代碼示例>>PHP>>正文


PHP SqlQuery::getTypeChar方法代碼示例

本文整理匯總了PHP中SqlQuery::getTypeChar方法的典型用法代碼示例。如果您正苦於以下問題:PHP SqlQuery::getTypeChar方法的具體用法?PHP SqlQuery::getTypeChar怎麽用?PHP SqlQuery::getTypeChar使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SqlQuery的用法示例。


在下文中一共展示了SqlQuery::getTypeChar方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: executeSQL

 static function executeSQL($db, $sql, $bindings = null, $types = null)
 {
     if ($statement = $db->prepare($sql)) {
         if (isset($bindings)) {
             $reset_types = false;
             if (!isset($types)) {
                 $types = '';
                 $reset_types = true;
             }
             $bindings_ref = [];
             foreach ($bindings as $key => $value) {
                 $bindings_ref[] =& $bindings[$key];
                 if ($reset_types) {
                     $types .= SqlQuery::getTypeChar($value);
                 }
             }
             array_unshift($bindings_ref, $types);
             call_user_func_array(array($statement, 'bind_param'), $bindings_ref);
         }
         if ($statement->execute()) {
             return $statement;
         } else {
             dbErr('query', 'execute', $sql, $db->error);
         }
     } else {
         dbErr('query', 'prepare', $sql, $db->error);
     }
 }
開發者ID:lotcz,項目名稱:zshop,代碼行數:28,代碼來源:query.php

示例2: save

 public function save()
 {
     $result = false;
     $id = $this->ival($this->id_name);
     if (isset($id) && $id > 0) {
         $columns = [];
         $bindings = [];
         $types = '';
         foreach ($this->data as $key => $value) {
             if ($key != $this->id_name) {
                 $columns[] = SqlQuery::validateColumn($key) . ' = ?';
                 $bindings[] =& $this->data[$key];
                 $types .= SqlQuery::getTypeChar($value);
             }
         }
         $bindings[] =& $this->data[$this->id_name];
         $types .= 'i';
         array_unshift($bindings, $types);
         $sql = sprintf('UPDATE %s SET %s WHERE %s = ?', $this->table_name, implode(',', $columns), $this->id_name);
         if ($st = $this->db->prepare($sql)) {
             call_user_func_array(array($st, 'bind_param'), $bindings);
             if ($st->execute()) {
                 $result = true;
             } else {
                 dbErr($this->table_name, 'execute', $sql, $this->db->error);
             }
             $st->close();
         } else {
             dbErr($this->table_name, 'prepare', $sql, $this->db->error);
         }
     } else {
         $columns = [];
         $values = [];
         $bindings = [];
         $types = '';
         foreach ($this->data as $key => $value) {
             if ($key != $this->id_name) {
                 $columns[] = SqlQuery::validateColumn($key);
                 $values[] = '?';
                 $bindings[] =& $this->data[$key];
                 $types .= SqlQuery::getTypeChar($value);
             }
         }
         array_unshift($bindings, $types);
         $sql = sprintf('INSERT INTO %s (%s) VALUES (%s)', $this->table_name, implode(',', $columns), implode(',', $values));
         if ($st = $this->db->prepare($sql)) {
             //echo $sql;
             call_user_func_array(array($st, 'bind_param'), $bindings);
             if ($st->execute()) {
                 $this->is_loaded = true;
                 $result = true;
                 $this->data[$this->id_name] = $this->db->insert_id;
             } else {
                 dbErr($this->table_name, 'execute', $sql, $this->db->error);
             }
             $st->close();
         } else {
             dbErr($this->table_name, 'prepare', $sql, $this->db->error);
         }
     }
     return $result;
 }
開發者ID:lotcz,項目名稱:zshop,代碼行數:62,代碼來源:base.m.php


注:本文中的SqlQuery::getTypeChar方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。