CodeIgniter Forums
Multi Query Problems in Codeigniter 3 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17)
+--- Thread: Multi Query Problems in Codeigniter 3 (/showthread.php?tid=79622)

Pages: 1 2


Multi Query Problems in Codeigniter 3 - sultantaspusat - 07-08-2021

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); 



RE: Multi Query Problems in Codeigniter 3 - includebeer - 07-09-2021

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?


RE: Multi Query Problems in Codeigniter 3 - sultantaspusat - 07-09-2021

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


RE: Multi Query Problems in Codeigniter 3 - superior - 07-11-2021

@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?


RE: Multi Query Problems in Codeigniter 3 - includebeer - 07-11-2021

(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.



RE: Multi Query Problems in Codeigniter 3 - superior - 07-11-2021

@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/insert-select.html


RE: Multi Query Problems in Codeigniter 3 - includebeer - 07-11-2021

(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/insert-select.html
I know you can insert the result of a select, but that's not what he's doing here...


RE: Multi Query Problems in Codeigniter 3 - sultantaspusat - 07-12-2021

[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]


RE: Multi Query Problems in Codeigniter 3 - includebeer - 07-13-2021

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…


RE: Multi Query Problems in Codeigniter 3 - sultantaspusat - 07-13-2021

[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]