Skip to content

Query insert Method

Samuel Fajreldines edited this page Feb 28, 2018 · 1 revision
public function insert($insert, $addslashes = true, $literal = false, $result_comparison_signal = '>'){

This method is responsible for executes a new INSERT query.

Parameters

  • $insert - Fields and values to insert.
    • Example: array('id' => 1,'register_date' => date('Y-m-d H:i:s'))
  • $addslashes - If true it'll quote strings with slashes on $insert values.
  • $literal - If false it'll add, IN THE QUERY, quotes before and after the values.
  • $result_comparison_signal - Comparison signal to verify if query was successfully executed. - See More

Usage

<?php 
    require_once('class_db.php');

    $sql = new query(array(
    	'host'     => 'localhost' ,
    	'user'     => 'root'      ,  
    	'password' => ''          ,  
    	'database' => 'test'  	  ,  
    	'db_type'  => 'mysqli'    , 
    ));
    $sql->table('users');
    $query = $sql->insert(array(
      'name'  => 'Samuel Faj',
      'email' => 'samuelfaj@icloud.com'
    ));

    var_dump('Query result: ' . var_export($query->result,true));
    var_dump($query);

Returns

string(18) "Query result: true"
object(stdClass)#4 (8) {
  ["sql"]=>
  string(89) "
			INSERT INTO users (name,email)
			VALUES ('Samuel Faj','samuelfaj@icloud.com');
		"
  ["fetch"]=>
  array(0) {
  }
  ["result"]=>
  bool(true)
  ["object"]=>
  bool(true)
  ["num_rows"]=>
  int(0)
  ["have_rows"]=>
  bool(false)
  ["affected_rows"]=>
  int(1)
  ["elapsed_time"]=>
  int(0)
}
Clone this wiki locally