1

in notorm documentation we know to get sql query use (string) $table but i didn't get any result when use it.

$data = array('name'=>'testing','age'=>'25')
$result = $db->table->insert($data);
echo (string) $result ;

i know the query is insert into table (name,age) values('testing','25'); i want to catch the query to variable. but echo (string) $result didn't show anything.

note:sorry for bad english

Dedi Ananto
  • 144
  • 2
  • 14

1 Answers1

2

Whenever you do insert(), update() or insert_update(), it will return last inserted row. So when you use $result = $db->table->insert($data); then $result will be an array. That's why you don't see anything. Try to use this:

echo "<pre>";print_r($result);echo "</pre>";exit;

When you will use select it will return a SQL query. When you want to get (string) $result it should return primary key value. I'm not sure, but I haven't needed that query before, so probably it works just for selects.

Patrik Krehák
  • 2,595
  • 8
  • 32
  • 62
  • thanks for your answer, I have not tried your suggestion... for now i write the query manually – Dedi Ananto Sep 29 '16 at 04:28
  • Ok, if you ever find a solution, let me know too, I'm wondering about that one too, even I don't need it :) – Patrik Krehák Sep 29 '16 at 06:48
  • `echo (string) $result` only work if $result is query to select table, so if `$result = $db->table()` and i use `echo (string) $result`, it showing **SELECT * FROM table**. not show anything if $result is query to insert like above – Dedi Ananto Oct 26 '16 at 02:57
  • Yea, that's it. But it would be very useful to make this works also on INSERT or UPDATE for debugging purposes. – Patrik Krehák Oct 26 '16 at 08:07