SQLBuilder\Driver\BaseDriver::quote PHP Метод

quote() публичный Метод

quote & escape string with single quote
public quote ( $string )
    public function quote($string)
    {
        /**
         * quote:
         *
         *    string mysqli_real_escape_string ( mysqli $link , string $escapestr )
         *    string pg_escape_string ([ resource $connection ], string $data )
         *    string PDO::quote ( string $string [, int $parameter_type = PDO::PARAM_STR ] )
         *
         *  $driver->configure('quote',array($pgconn,'escape_string'));
         */
        if ($this->quoter) {
            return call_user_func($this->quoter, $string);
        }
        // Defualt escape function, this is not safe.
        return "'" . addslashes($string) . "'";
    }

Usage Example

Пример #1
0
 public function toSql(BaseDriver $driver, ArgumentArray $args)
 {
     $sql = 'CREATE DATABASE';
     if ($this->ifNotExists && $driver instanceof MySQLDriver) {
         $sql .= ' IF NOT EXISTS';
     }
     $sql .= ' ' . $driver->quoteIdentifier($this->dbName);
     if ($driver instanceof MySQLDriver) {
         if ($this->characterSet) {
             $sql .= ' CHARACTER SET ' . $driver->quote($this->characterSet);
         }
         if ($this->collate) {
             $sql .= ' COLLATE ' . $driver->quote($this->collate);
         }
     } elseif ($driver instanceof PgSQLDriver) {
         /**
          * PostgreSQL properties
          */
         if ($this->owner) {
             $sql .= ' OWNER ' . $driver->quote($this->owner);
         }
         if ($this->template) {
             $sql .= ' TEMPLATE ' . $driver->quote($this->template);
         }
         if ($this->encoding) {
             $sql .= ' ENCODING ' . $driver->quote($this->encoding);
         }
         if ($this->collate) {
             $sql .= ' LC_COLLATE ' . $driver->quote($this->collate);
         }
         if ($this->ctype) {
             $sql .= ' LC_CTYPE ' . $driver->quote($this->ctype);
         }
         if ($this->tablespace) {
             $sql .= ' TABLESPACE ' . $driver->quote($this->tablespace);
         }
         if ($this->connectionLimit) {
             $sql .= ' CONNECTION LIMIT ' . $this->connectionLimit;
         }
     }
     return $sql;
 }