Welcome Guest, Not a member yet? Register   Sign In
Different between method chaining query and my query.
#1

[eluser]sahanlak[/eluser]
Review these 2 methods of SQL query
Code:
$this->db->select('amount')->from('withdraw_request')->where('user_id', $ID)->limit(0, 1);
Code:
$this->db->query('SELECT amount FROM `withdraw_request` WHERE user_id=? LIMIT 0,1', $ID);

I get the number of rows, first one always return 0 means not working, 2nd one works perfect. What's the difference?
#2

[eluser]bretticus[/eluser]
Off the top of my head they look nearly identical but you do have the LIMIT and OFFSET values swapped. The AR limit() functions produces the SQL in the opposite order from MySQL.

Code:
$this->db->limit(0, 1);

Will produce

Quote:...LIMIT 1,0

Which if I'm not mistaken, that means start at the second record (offset) but then return no records. Try just swapping the arguments.

In the future, use

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

Or just enable the profiler to see how AR is rendering your queries before being sent to your database.
#3

[eluser]sahanlak[/eluser]
Yep, You're right. Thanks for the tip Smile




Theme © iAndrew 2016 - Forum software by © MyBB