当前位置: 首页>>代码示例>>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;未经允许,请勿转载。