Skip to content

Instantly share code, notes, and snippets.

@bombless
Last active December 13, 2015 22:28
Show Gist options
  • Save bombless/4984274 to your computer and use it in GitHub Desktop.
Save bombless/4984274 to your computer and use it in GitHub Desktop.
a dirty class to help using ext/mysqli
<?php
class BindParam{
private $values = array(),
$names = array(),
$types = '',
$question_marks = array(),
$table_name;
public function __construct($table){
$this->table_name = $table;
}
public function add( $type, $name, &$value ){
$this->values[] = $value;
$this->types .= $type;
$this->question_marks[] = '?';
$this->names[] = $name;
}
public function prepareInsert(){
$query = 'INSERT INTO '.($this->table_name).' ('.implode(',', $this->names).
') VALUES('.implode(',',$this->question_marks).')';
return $query;
}
public function args(){
$args = array_merge(array($this->types), $this->values);
return $args;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment