Welcome Guest, Not a member yet? Register   Sign In
How to echo statement of query with Active Record
#1

Hello, 

how can I echo the statement of a query when I use code as this?
PHP Code:
$this->db->from($this->table); 

thank you
Reply
#2

(This post was last modified: 02-15-2016, 02:31 AM by XMadMax.)

(02-15-2016, 02:05 AM)SDir Wrote: Hello, 

how can I echo the statement of a query when I use code as this?
PHP Code:
$this->db->from($this->table); 

thank you

Use :

PHP Code:
echo $this->db->last_query(); 

Other usefull query utilities :
http://www.codeigniter.com/user_guide/da...ert_string
Reply
#3

(This post was last modified: 02-15-2016, 02:51 AM by SDir.)

(02-15-2016, 02:21 AM)XMadMax Wrote:
(02-15-2016, 02:05 AM)SDir Wrote: Hello, 

how can I echo the statement of a query when I use code as this?
PHP Code:
$this->db->from($this->table); 

thank you

Use :

PHP Code:
echo $this->db->last_query(); 

Other usefull query utilities :
http://www.codeigniter.com/user_guide/da...ert_string


Thank You for your answer.  But I can't use last_query() because of this unsolved probem (working with Oracle): http://forum.codeigniter.com/thread-64340.html

For example: if I write this code, I get no output from last_query(): 
PHP Code:
    $this->db->from($this->table);    
    
$this->db->last_query();  //no output with Oracle (but with MySql works fine) 

So, I'm looking for a different method to print the statement.



Thank You
Reply
#4

(This post was last modified: 02-15-2016, 03:17 AM by Avenirer. Edit Reason: ...maybe a select() method too... )

A query is generated only if... you generate it...

The from() ("$this->db->from($this->table);") method is not generating a query by itself. You must also have a result generating function like, for example, a "get()" method. So, if you want to have the last_query(), you must have:

PHP Code:
$this->db->select('*');
$this->db->from($this->table);
$this->db->get();
echo 
$this->db->last_query(); 

...or, even simpler...:

PHP Code:
$this->db->get($this->table);
echo 
$this->db->last_query(); 
Reply
#5

...or use get_compiled_select() https://codeigniter.com/user_guide/datab...led_select

PHP Code:
$this->db->from($this->table); 
$sql $this->db->get_compiled_select($this->tablefalse); 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB