Welcome Guest, Not a member yet? Register   Sign In
Multi Query Problems in Codeigniter 3
#1

I want to ask about the CI3 problem. 

Why in Codeigniter 3 can't run multi query with select statement
I tried to  
Code:
var_dump($get) 
but the result is boolean.
This is my code : 
PHP Code:
$get $this->db->query("
            insert tblmaster values('namefield','cityfield');
            select * from tblmaster;
            "
);

var_dump($get); 
Reply
#2

Because that's not a valid SQL query. That's 2 queries. Why don't you run them one after the other? What are you trying to do?
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#3

(This post was last modified: 07-09-2021, 08:47 PM by sultantaspusat.)

not separated because I'm actually using a store procedure . Inside the stored procedure, there must be many queries


i want to run insert data and want to print the result of select , but why is the result boolean
Reply
#4

@includebeer It's possible to run a insert on a select, but the amount of columns must match for this.

@sultantaspusat Are you trying to copy from the select to the insert or do you want something else?
Reply
#5

(This post was last modified: 07-11-2021, 06:36 AM by includebeer.)

(07-09-2021, 08:20 PM)sultantaspusat Wrote: not separated because I'm actually using a store procedure . Inside the stored procedure, there must be many queries


i want to run insert data and want to print the result of select , but why is the result boolean

Maybe you are looking for transactions?
PHP Code:
$this->db->transStart();
$this->db->query('AN SQL QUERY...');
$this->db->query('ANOTHER QUERY...');
$this->db->transComplete();

if (
$this->db->transStatus() === FALSE)
{
    // generate an error... or use the log_message() function to log your error


(07-11-2021, 02:32 AM)superior Wrote: @includebeer It's possible to run a insert on a select, but the amount of columns must match for this.

Yes, but that's not the case here. He's doing an insert, then a select. I don't understand what different result he's expecting by doing it that way...

As to why the result is boolean, that's  because the insert is a "write" operation. See this page of the user guide.
Quote:The query() function returns a database result object when “read” type queries are run which you can use to show your results. When “write” type queries are run it simply returns TRUE or FALSE depending on success or failure.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#6

@includebeer the order for this is correct, the column count depends on this, so calling all columns should match the insert.

see: https://dev.mysql.com/doc/refman/8.0/en/...elect.html
Reply
#7

(07-11-2021, 07:07 AM)superior Wrote: @includebeer the order for this is correct, the column count depends on this, so calling all columns should match the insert.

see: https://dev.mysql.com/doc/refman/8.0/en/...elect.html
I know you can insert the result of a select, but that's not what he's doing here...
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#8

[quote pid="388450" dateline="1625995947"]

i even want more than one select in store procedure , and how to get data from 3 table in the below, For Example : 

PHP Code:
select from tableA
select 
from tableB
select 
from tableC 

[/quote]
Reply
#9

Then do 3 separate select. What are you trying to do that won’t work with separate queries? Maybe show us some code. For someone looking for help, you are not very collaborative…
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#10

[quote pid="388512" dateline="1626203444"]
Sorry in advance, maybe you don't understand what I mean.

I use multi query inside Store Procedure
the underlined word is store procedure

[/quote]
Reply




Theme © iAndrew 2016 - Forum software by © MyBB