public function bindParam($parameter, &$variable, $data_type = -1, $length = 0, $driver_options = null)
 {
     if (parent::bindParam($parameter, $variable, $data_type, $length, $driver_options)) {
         $this->bind_params_changed = true;
         return true;
     }
     return false;
 }
Example #2
0
 public function prepare(&$statement, &$options)
 {
     if (!$statement || !is_array($options)) {
         return false;
     }
     $driver_options = $this->driver_options;
     foreach ($options as $k => $v) {
         if (!$this->setAttribute($k, $v, $driver_options, 'PDO::prepare')) {
             return false;
         }
     }
     switch ($this->driver_quote_type) {
         case 1:
             $params_regex = '/(\'[^\']*(?:\'\'[^\']*)*\')|("[^"\\\\]*(?:\\\\.[^"\\\\]*)*")|([^:])(\\?|:[A-Za-z0-9_\\-]+)/';
             break;
         case 0:
         default:
             $params_regex = '/(\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\')|("[^"\\\\]*(?:\\\\.[^"\\\\]*)*")|([^:])(\\?|:[A-Za-z0-9_\\-]+)/';
             break;
     }
     $result = preg_split($params_regex, $statement, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
     $param_type = $this->driver_param_type;
     $has_named = false;
     $has_anon = false;
     $warn_text = 'Invalid parameter number: mixed named and positional parameters';
     $chunks_num = 0;
     $param_num = 0;
     $params_info = array();
     $named_params = array();
     foreach ($result as &$chunk) {
         switch ($chunk[0]) {
             case ':':
                 if ($has_anon) {
                     $this->set_error(0, $warn_text, 'HY093', PDO::ERRMODE_WARNING, 'prepare');
                     return false;
                 }
                 if (isset($named_params[$chunk])) {
                     $named_params[$chunk]++;
                     $chunk .= $named_params[$chunk];
                 } else {
                     $named_params[$chunk] = 1;
                 }
                 $has_named = true;
                 $param_num++;
                 switch ($param_type) {
                     case -1:
                         $params_info[$chunk] = $chunks_num;
                         break;
                     case 1:
                         $key = $chunk;
                         $chunk = str_replace('-', '__', $chunk);
                         $params_info[$key] = $chunk;
                         break;
                     case 2:
                         $params_info[$chunk] = $param_num;
                         $chunk = '$' . $param_num;
                         break;
                     case 0:
                         $params_info[$chunk] = $param_num;
                         $chunk = '?';
                         break;
                 }
                 break;
             case '?':
                 if ($has_named) {
                     $this->set_error(0, $warn_text, 'HY093', PDO::ERRMODE_WARNING, 'prepare');
                     return false;
                 }
                 $has_anon = true;
                 $param_num++;
                 switch ($param_type) {
                     case -1:
                         $params_info[$param_num] = $chunks_num;
                         break;
                     case 1:
                         $params_info[$param_num] = ':p' . $param_num;
                         $chunk = $params_info[$param_num];
                         break;
                     case 2:
                         $params_info[$param_num] = $param_num;
                         $chunk = '$' . $param_num;
                         break;
                     case 0:
                         $params_info[$param_num] = $param_num;
                         break;
                 }
                 break;
         }
         $chunks_num++;
     }
     if ($param_type == -1) {
         $this->prepared =& $result;
     } else {
         // Do not explode with a space. A space breaks this in Postgres, because ads a space between 'E' and '\\s+':
         // regexp_split_to_table('some string', E'\\s+')
         $this->prepared = implode('', $result);
     }
     $st = phppdo_base_statement::_new_instance($driver_options[PDO::ATTR_STATEMENT_CLASS], $statement);
     $st->_setup($this->link, $this, $driver_options, $this->prepared, $params_info);
     return $st;
 }
 protected function _fetch_lob(&$p, &$col)
 {
     $tmp_file = tempnam(sys_get_temp_dir(), 'phppdo_');
     if (!$tmp_file) {
         return false;
     }
     if (!@pg_lo_export($this->_link, $col, $tmp_file)) {
         // maybe this is a 'bytea'
         return parent::_fetch_lob($p, $col);
     }
     $p = fopen($tmp_file, 'rb');
     if ($p) {
         $this->tmp_lobs[$tmp_file] = $p;
     }
 }
Example #4
0
 protected function _fetch_lob(&$p, &$col)
 {
     $tmp_file = tempnam(sys_get_temp_dir(), 'phppdo_');
     if (!$tmp_file) {
         return false;
     }
     if (is_object($col)) {
         $col->export($tmp_file);
     } else {
         return parent::_fetch_lob($p, $col);
     }
     $p = fopen($tmp_file, 'rb');
     if ($p) {
         $this->tmp_lobs[$tmp_file] = $p;
     }
 }