Posted inTechnology / Codeigniter / Mysql / Mysqli / php / Programming

insert Query In Codeigniter Example Tutorial

Today, We want to share with you insert Query In Codeigniter Example Tutorial.In this post we will show you update query in codeigniter, hear for codeigniter update query we will give you demo and example for implement.In this post, we will learn about codeigniter delete query with an example.

insert Query In Codeigniter Example Tutorial

There are the Following The simple About delete in codeigniter Full Information With Example and source code.

As I will cover this Post with live Working example to develop select query in codeigniter, so the codeigniter join query is used for this example is following below.

insert Query In Codeigniter Example Tutorial
insert Query In Codeigniter Example Tutorial

PHP Based Framework like as a CodeIgniter insert or added store query will run or execute using following all the functions. They are

  • Insert With Query Bindings
  • Standard Insert
  • Escaping Insert Queries
  • Retrive Inserted ID
  • Get Affected Rows
  • $this->db->query()
  • $this->db->insert_string()
  • $this->db->insert_batch()

Codeigniter (CRUD) Select Insert Update Delete Query

  1. Update Query In Codeigniter
  2. Select Query In Codeigniter
  3. Insert Query In Codeigniter
  4. Delete Query In Codeigniter

using $this->db->query()

Example 1:

$query = "insert into tbl_member (first_name, price, teamfirst_name)
        values ('pakainfo, 35, 'Infinityknow 1')";
$this->db->query($query);

Example 2:

$data = array( 
        'first_name'	= >  $_POST['first_name'] , 
        'teamfirst_name'= >  $_POST['teamfirst_name'], 
        'price'	= >  $_POST['price']
    );
$this->db->insert('tbl_member', $data);

Insert With Query Bindings

Use Of Query Bindings

Benefit of using binds is that the values are automatically escaped, producing safer queries


$query = "insert into tbl_member (first_name, price, teamfirst_name)
        values (?, ?, ?)";
$this->db->query($query,array('pakainfo, 35, 'Infinityknow 1'));

Standard Insert



$query = "INSERT INTO tbl_member (first_name, teamfirst_name, price) 
        VALUES (".$this->db->escape($first_name).", ".$this->db->escape($teamfirst_name).".", ".$this->db->escape($price).")";
$this->db->query($query);


using $this->db->insert_string()

Note: Values are automatically escaped, producing safer queries.

$data = array( 
        'first_name'	= >  $_POST['first_name'] , 
        'teamfirst_name'= >  $_POST['teamfirst_name'], 
        'price'	= >  $_POST['price'] 
    );
$this-> db->insert_string('tbl_member', $data);

using $this->db->insert_batch()


$data = array(
            array(
                'first_name'	= >  'first_name1' , 
                'teamfirst_name'= >  'teamfirst_name1', 
                'price'	= >  'price1'
            ),
            array(
                'first_name'	= >  'first_name2' , 
                'teamfirst_name'= >  'teamfirst_name2', 
                'price'	= >  'price2'
            )
        );
$this->db->insert_batch('tbl_member', $data); 
//INSERT INTO mytable (first_name, teamfirst_name, price) 
//VALUES ('first_name1', 'teamfirst_name1', 'price1'), ('first_name2', 'teamfirst_name2', 'price2')

Escaping Insert Queries

$this->db->escape()

This function determines the data type so that it can escape only string data. It also automatically adds single quotes around the data so you don’t have to:


$query = "INSERT INTO tbl_member (first_name) VALUES(".$this->db->escape($first_name).")";


using $this->db->escape_str()

This function escapes the data passed to it, regardless of type. Most of the time you’ll use the above function rather than this one. Use the function like this:


$query = "INSERT INTO tbl_member (first_name) VALUES('".$this->db->escape_str($first_name)."')";


Get Last Inserted ID

The Get the Last insert ID number when performing CodeIgniter database Last row inserts.


$this->db->insert_id()

Get Affected Rows

show the number of affected records, when doing “write” type mysql queries Like as a CRUD Operations (insert, update, etc.).


$this->db->affected_rows();

How to insert data in database – CodeIgniter framework

simple tou can also The INSERT INTO query is used to insert or store sabe new fresh data to a MySQL Database table:

INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)

codeIgniter\application\controllers\Member.php

load->database();
	
	$this->load->model('Member_model');
	}
	public function savedata()
	{
		$this->load->view('insert');
	
		if($this->input->post('save'))
		{
		
		$member_user=$this->input->post('member_user');
		$sirname=$this->input->post('sirname');
		$email=$this->input->post('email');
		
		$this->Member_model->saverecords($member_user,$sirname,$email);	
		echo "Member all the Records Saved Successfully";
		}
	}
	
}
?>

codeIgniter\application\models\Member_model.php

db->query($query);
	}
	
}

codeIgniter\application\views\insert.php

  


Registration form - www.pakainfo.com

 

	
User(Member) Name
Sirname
Email ID
Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about join query in codeigniter.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype