0

I want to print query before inserting in database in CODEIGNITER.

PHP CODE :

    $data['prices'] = $prices;
    $data['countryID'] = '0';
    $data['userTypeID'] = $roleType;
    $data['districtDivisionID'] = '0';
    $data['userTypeValue'] = $userTypeValue;
    $data['receiverUserTypeID'] = $receiverUserType;
    $this->db->insert('db_DevicePrices', $data);
6
  • use echo $this->db->last_query() Commented Dec 11, 2019 at 5:51
  • Does this answer your question? Echo query before execution and without execution in codeigniter Active Record Commented Dec 11, 2019 at 5:51
  • @ Devsi Odedra it is working with $this->db->get(); not for inserting. I have already check it. Commented Dec 11, 2019 at 5:52
  • @Prabhjot Singh Kainth i have already check this. But no solution get. Commented Dec 11, 2019 at 5:54
  • @SandeepK. what is the output/error you are getting? Commented Dec 11, 2019 at 5:54

2 Answers 2

2

please use insert_string, please take a look at following example.

$data = array( 
        'name'  = >  $_POST['name'] , 
        'groupname'= >  $_POST['groupname'], 
        'age'   = >  $_POST['age']
);
$this-> db->insert_string('tbl_user', $data);

Refer to this link

Sign up to request clarification or add additional context in comments.

Comments

1

You can use $this->db->insert_string() for print insert query before inserting data in database

Example:

$data = array('prices' => $prices, 'countryID' => 0, 'userTypeID' => $roleType,'districtDivisionID'=>0,'userTypeValue'=>$userTypeValue,'receiverUserTypeID'=>$receiverUserType);
$str = $this->db->insert_string('db_DevicePrices', $data);

Refer this link

Hope this will help you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.