当前位置: 首页>>代码示例>>PHP>>正文


PHP PDO::quote方法代码示例

本文整理汇总了PHP中PDO::quote方法的典型用法代码示例。如果您正苦于以下问题:PHP PDO::quote方法的具体用法?PHP PDO::quote怎么用?PHP PDO::quote使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PDO的用法示例。


在下文中一共展示了PDO::quote方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: fetchTemplateAndTitle

 /**
  * Override the template-fetching-function of the Parser
  *
  * @global string $IP
  * @global string $wgTemplatePath
  * @global string $wgTemplateExtension
  * @global string $wgTemplatePrefix
  * @param Title $title
  * @return array
  */
 function fetchTemplateAndTitle($title)
 {
     #echo "\n--- Trying to find offline template: $title ---\n";
     global $wgTemplateDB, $wgTemplateFileID;
     $finalTitle = $title;
     $template_text = null;
     # $$$ need to fix later for all languages
     # We pad the title with '~' to force the database to import strings
     $title_orig = '~' . $wgTemplateFileID . '~' . strtolower($title);
     $db = new PDO('sqlite:' . $wgTemplateDB);
     $tl = $db->quote($title_orig);
     #echo "\n--- ($title_orig) --- \n";
     $result = $db->query("SELECT body FROM templates WHERE title = {$tl} LIMIT 1");
     $data = $result->fetchAll();
     $max_loop_count = 25;
     while ($max_loop_count && sizeof($data) == 0) {
         $result = $db->query("SELECT redirect FROM redirects WHERE title = {$tl} LIMIT 1");
         $data = $result->fetchAll();
         if (sizeof($data) == 0) {
             break;
         }
         $redirect = $db->quote($data[0]['redirect']);
         $result = $db->query("SELECT body FROM templates WHERE title = {$redirect} LIMIT 1");
         $data = $result->fetchAll();
         --$max_loop_count;
     }
     if (sizeof($data) > 0) {
         $template_text = substr($data[0]['body'], 1);
         #echo "\n--- TT:($template_text):TT --- \n";
     } else {
         $template_text = '';
     }
     $ret = array($template_text, $finalTitle);
     return $ret;
 }
开发者ID:akoehn,项目名称:wikireader,代码行数:45,代码来源:ParserStandAlone.php

示例2: quote

 public function quote($str)
 {
     if (!$this->link) {
         return false;
     }
     return $this->link->quote($str);
 }
开发者ID:qexyorg,项目名称:webMCR-1,代码行数:7,代码来源:module.class.php

示例3: where

 /**
  * @param $field
  * @param $operator
  * @param $value
  * @return $this
  */
 public function where($field, $operator, $value)
 {
     $value = is_numeric($value) ? $value : $this->pdo->quote($value);
     if (in_array($operator, $this->operators)) {
         $this->whereAnd[] = "`{$field}` {$operator} {$value}";
         return $this;
     }
     die(sprintf('unsupported operator %s', $operator));
 }
开发者ID:Antoine07,项目名称:Base-Objet,代码行数:15,代码来源:Model.php

示例4: generate_insert_query

function generate_insert_query($line, $places, $table, PDO $db, $v_ids)
{
    global $salt;
    foreach ($places as $field => $place) {
        $fields[] = $field;
        if ($field == 'password') {
            $values[] = $db->quote(md5($salt . $line[$place]));
        } else {
            $values[] = $db->quote($line[$place]);
        }
    }
    $username = $line[$places['username']];
    switch ($table) {
        case 'v_users':
            if (empty($username) || $username == 'NULL') {
                return false;
            }
            // we'll assume that every user should be able to login
            if (!in_array('password', $fields)) {
                $fields[] = 'password';
                $values[] = $db->quote(md5($salt . $username));
            }
            break;
        case 'v_extensions':
            $ext = $line[$places['extension']];
            if (empty($ext) || $ext == 'NULL') {
                return false;
            }
            // let's also assume every extension should also have a vm pin
            if (!in_array('vm_password', $fields)) {
                $fields[] = 'vm_password';
                $values[] = $db->quote($ext);
            }
            /* if we have a username but no user_list,
             * let's assume we want the extension tied to the current user
             */
            if (!in_array('user_list', $fields) && $username) {
                $fields[] = 'user_list';
                $values[] = $db->quote(sprintf('|%s|', $username));
            }
            $idx = array_search('username', $fields);
            unset($fields[$idx]);
            unset($values[$idx]);
            break;
        default:
            break;
    }
    if (!in_array('v_id')) {
        //print "v_id not found, adding one for localhost<br>\n";
        //printf('<pre>%s</pre>', print_r($v_ids, true));
        $fields[] = 'v_id';
        $values[] = $v_ids['localhost'];
    }
    $query = sprintf('INSERT INTO %s (%s) VALUES (%s);', $table, join(', ', $fields), join(', ', $values));
    return $query;
}
开发者ID:petekelly,项目名称:fusionpbx,代码行数:56,代码来源:v_users_bulk_add.php

示例5: buildInsertQuery

 private function buildInsertQuery($tablename, array $fields)
 {
     $columns = $values = array();
     foreach ($fields as $field => $value) {
         $columns[] = $field;
         $values[] = $this->db->quote($value);
     }
     $columns = implode(',', $columns);
     $values = implode(',', $values);
     return "INSERT INTO {$tablename} ({$columns}) VALUES ({$values})";
 }
开发者ID:kramapet,项目名称:nested-set,代码行数:11,代码来源:PDOQueryMapper.php

示例6: quote

 /**
  * Quote a value for use in a query.
  * @param  $value
  * @return string
  */
 public function quote($value)
 {
     if (is_array($value)) {
         $result = [];
         foreach ($value as $single) {
             $result[] = $this->quote($single);
         }
         return sprintf('(%s)', implode(', ', $result));
     } else {
         return $this->pdo->quote($value);
     }
 }
开发者ID:soneritics,项目名称:database,代码行数:17,代码来源:PDOMySQL.php

示例7: quote

 /**
  * Экранирует значение
  * @param  string|array $value
  * @param  int          $type
  * @return string
  */
 public function quote($value, $type = \PDO::PARAM_STR)
 {
     if (is_array($value)) {
         foreach ($value as $key => $val) {
             $value[$key] = $this->db->quote($val, $type);
         }
         $quoted_value = implode(', ', $value);
     } else {
         $quoted_value = $this->db->quote($value, $type);
     }
     return $quoted_value;
 }
开发者ID:shabuninil,项目名称:combine,代码行数:18,代码来源:PDO.php

示例8: authenticate

 public function authenticate($login, $password)
 {
     $query = "\n\t\t\tSELECT  *\n\t\t\tFROM\t`user`\n\t\t\tWHERE\t`user_login` = " . $this->_oDbAdapter->quote($login) . "\n\t\t\t\tAND `user_password` = " . $this->_oDbAdapter->quote(sha1($password)) . "\n\t\t";
     $mResult = $this->_oDbAdapter->query($query)->fetch();
     if ($mResult) {
         trigger_error('User #' . $mResult->user_id . ' authenticated', E_USER_NOTICE);
         $this->setIdentity($mResult);
         return true;
     }
     trigger_error('Could not authenticate user `' . $login . '` authenticated', E_USER_NOTICE);
     return false;
 }
开发者ID:nexces,项目名称:transys,代码行数:12,代码来源:auth.php

示例9: write

 /**
  * Write a message to the log
  *
  * @param array $messages
  * @throws \RuntimeException
  */
 public function write(array $messages)
 {
     $stmt = $this->dbh->prepare("INSERT INTO " . $this->dbh->quote($this->tableName) . " (level, level_name, message, creation_time)" . " VALUES (:level, :level_name, :message, :creation_time)");
     foreach ($messages as $record) {
         list($datetime, $level, $levelCode, $message) = $record;
         $stmt->bindParam(':creation_time', $datetime->getTimestamp(), \PDO::PARAM_INT);
         $stmt->bindParam(':level', $levelCode, \PDO::PARAM_INT);
         $stmt->bindParam(':level_name', $level, \PDO::PARAM_STR);
         $stmt->bindParam(':message', $message, \PDO::PARAM_STR);
         $stmt->execute();
     }
 }
开发者ID:tlumx,项目名称:framework,代码行数:18,代码来源:PdoWriter.php

示例10: quote

 function quote($Param)
 {
     $args = func_get_args();
     if (count($args) > 1) {
         foreach ($args as &$arg) {
             if ($x = $this->DB->quote($arg)) {
                 $arg = $x;
             }
         }
     } else {
         return $this->DB->quote($args[0]);
     }
 }
开发者ID:michalkoczwara,项目名称:WebGoatPHP,代码行数:13,代码来源:pdo_mysql.php

示例11: news_add

function news_add($catid, $title, $text)
{
    try {
        $db = new PDO("sqlite:D:\\OpenServer\\domains\\test.git\\news.db");
        $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $title = $db->quote($title);
        $text = $db->quote($text);
        $time = time();
        $sql = "INSERT INTO news(catid,title,text,time) VALUES({$catid},{$title},{$text},{$time})";
        $db->exec($sql);
    } catch (PDOException $e) {
        echo $e->getMessage();
    }
    $db = null;
}
开发者ID:AlekseiiShevchuk,项目名称:test,代码行数:15,代码来源:db_func.php

示例12: backup

 /**
  * 备份数据库
  * @param string|array $table 表名或表名数组,为空时备份所有表
  * @return bool
  */
 public function backup($table = null)
 {
     $tables = empty($table) ? $this->getTables() : (is_array($table) ? $table : array($table));
     $filePre = $this->dataDir . '/' . date('Ymd', time());
     $tablesStructure = '';
     $i = 0;
     $dataTemp = array();
     $dataHead = '';
     $backupData = '';
     $file = '';
     foreach ($tables as $table) {
         $tablesStructure .= '------------------------------------------' . PHP_EOL . '-- 表名:' . $table . PHP_EOL . '--------' . PHP_EOL . 'DROP TABLE IF EXISTS ' . $table . ';' . PHP_EOL;
         $createtable = $this->query('SHOW CREATE TABLE ' . $table)->fetchAll();
         $createtable = end($createtable[0]);
         $createtable = preg_replace('/AUTO_INCREMENT=\\d*/i', 'AUTO_INCREMENT=0', $createtable);
         $tablesStructure .= $createtable . ';' . PHP_EOL;
         $data = $this->query('SELECT * FROM ' . $table)->fetchAll();
         $dataHead = 'INSERT INTO ' . $table . ' VALUES' . PHP_EOL;
         foreach ($data as $rowIndex => $row) {
             foreach ($row as $colKey => $colValue) {
                 $row[$colKey] = $this->db->quote($colValue);
             }
             $dataTemp[] = '(' . implode(', ', $row) . ')';
             $data[$rowIndex] = '';
             if ($i < 200) {
                 $i++;
             } else {
                 $backupData .= $dataHead . implode(',' . PHP_EOL, $dataTemp) . ';' . PHP_EOL;
                 $dataTemp = array();
                 $i = 0;
             }
         }
         if (!empty($dataTemp)) {
             $backupData .= $dataHead . implode(',' . PHP_EOL, $dataTemp) . ';' . PHP_EOL;
         }
         $file = $filePre . '/' . $table . $this->dataFix;
         dir_check(dirname($file));
         file_put_contents($file, $backupData, LOCK_EX);
         $i = 0;
         $dataTemp = array();
         $dataHead = null;
         $backupData = '';
     }
     $file = $filePre . '/' . $this->structureFile;
     dir_check(dirname($file));
     file_put_contents($file, $tablesStructure, LOCK_EX);
     return true;
 }
开发者ID:chaoyanjie,项目名称:MonkeyPHP,代码行数:53,代码来源:DatabaseGhost.php

示例13: quoteString

 /**
  * @param string $string
  * @return string
  */
 public function quoteString($string)
 {
     if (!$this->_dbHandler) {
         $this->connect();
     }
     return $this->_dbHandler->quote($string);
 }
开发者ID:nlevee,项目名称:php-object-mapper,代码行数:11,代码来源:Adapter.php

示例14: prepararValor

 /**
  * Prepara valor segun tipo especificado.
  *
  * @param mixed $valor Valor a preparar
  * @param string $tipo Tipo de valor pasado: bol, txt, num, def
  * @param bool $permiteVacio Define si permite cadena de texto vacio en vez de nulo
  *
  * @return string Retorna valor escapado para MySQL
  */
 public function prepararValor($valor, $tipo = 'txt', $permiteVacio = false)
 {
     if (is_array($valor)) {
         if (empty($valor)) {
             return 'NULL';
         }
         foreach ($valor as $llave => $v) {
             $valor[$llave] = $this->prepararValor($v, $tipo);
         }
         return $valor;
     }
     // Retornamos valor boleano según el tipo
     if ($tipo == 'bol' || $tipo == 'bool') {
         return $valor ? '1' : '0';
     }
     // Detectamos y retornamos valor nulo
     if ($valor === null || $valor === false) {
         return 'NULL';
     }
     if (!$permiteVacio && $valor === '') {
         return 'NULL';
     }
     // Retornamos valor numerico según el tipo
     if ($tipo == 'num' || $tipo == 'int') {
         if ($valor === '') {
             return 'NULL';
         }
         return strval(floatval($valor));
     }
     // Retornamos valor textual como valor predeterminado
     return $this->pdo->quote($valor);
 }
开发者ID:armazon,项目名称:armazon,代码行数:41,代码来源:Relacional.php

示例15: Quote

 /** @return string */
 public function Quote($string)
 {
     if (!$this->connected) {
         $this->Connect();
     }
     return $this->Conn->quote($string);
 }
开发者ID:bnorm-software,项目名称:barkeep-backend,代码行数:8,代码来源:CLASS_MySQLDatabase.php


注:本文中的PDO::quote方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。