Example #1
0
 /**
  * Returns a quoted and escaped string of $data for use in an SQL statement.
  *
  * @param string $data String to be prepared for use in an SQL statement
  * @param string $column The column into which this data will be inserted
  * @param boolean $safe Whether or not numeric data should be handled automagically if no column data is provided
  * @return string Quoted and escaped data
  */
 function value($data, $column = null, $safe = false)
 {
     $parent = parent::value($data, $column, $safe);
     if ($parent != null) {
         return $parent;
     }
     if ($data === null || is_array($data) && empty($data)) {
         return 'NULL';
     }
     if ($data === '' && $column !== 'integer' && $column !== 'float' && $column !== 'boolean') {
         return "''";
     }
     if (empty($column)) {
         $column = $this->introspectType($data);
     }
     switch ($column) {
         case 'boolean':
             return $this->boolean((bool) $data);
             break;
         case 'integer':
         case 'float':
         case null:
             if ($data === '') {
                 return 'NULL';
             }
             if (is_int($data) || is_float($data) || $data === '0' || is_numeric($data) && strpos($data, ',') === false && $data[0] != '0' && strpos($data, 'e') === false) {
                 return $data;
             }
         case 'timestamp':
             if ($data === 'CURRENT_TIMESTAMP') {
                 return $data;
             }
         default:
             $data = "'" . mysqli_real_escape_string($this->connection, $data) . "'";
             break;
     }
     return $data;
 }
Example #2
0
 /**
  * Begin a transaction
  *
  * @param unknown_type $model
  * @return boolean True on success, false on fail
  * (i.e. if the database/model does not support transactions).
  */
 function begin(&$model)
 {
     if (parent::begin($model) && $this->execute('START TRANSACTION')) {
         $this->_transactionStarted = true;
         return true;
     }
     return false;
 }