Welcome Guest, Not a member yet? Register   Sign In
Query Binding
#7

[eluser]axelitus[/eluser]
I would love to see this implemented!

[quote author="alboyd" date="1251261182"]Just out of curiosity can you tell me why you would want to do this? I'm scratching my head...[/quote]
The answer is in this post: http://crynobone.com/codeigniter-for-ora...erecord/4/
Quote:As a programmer, when writing a long SQL with multiple bind parameter you will have some headache to manually calculate the position of each parameter.

So it's better to use named query bindings where you would have something similar as this:
Code:
$sql = 'SELECT @column FROM @table LIMIT @limit';
$this->db->bind('@column', 'username');
$this->db->bind('@table', 'users');
$this->db->bind('@limit', 10);
$query = $this->db->query($sql);

This way it would be so much easier to manage the code as it is much more clearer.

Taking flavin example:
[quote author="flavin" date="1267938719"]
Code:
$sql = 'SELECT ? FROM ? LIMIT ?';
$this->db->bind('username1', 'user1', 10);
$this->db->bind('username2', 'user2', 10);
$this->db->bind('username3', 'user3', 10);
$this->db->bind('username4', 'user4', 10);
$query = $this->db->query($sql);
[/quote]

I would not know what this would be used for as your are generating 4 different queries binding all parameters 4 times using different values... it would be much easier using a for loop at PHP level:
Code:
$query = array();
$sql = 'SELECT ? FROM ? LIMIT ?';
for($i = 1; $i<5; $i++) {
  query[$i] = $this->db->bind("username{$i}", "user{$i}", 10);
}

So you would end up with all four query results in the array...

Hope this helps to get some attention to named parameter binding in queries using Code Igniter! It would be so helpful...


Messages In This Thread
Query Binding - by El Forum - 08-11-2009, 07:24 AM
Query Binding - by El Forum - 08-25-2009, 05:22 PM
Query Binding - by El Forum - 08-25-2009, 05:33 PM
Query Binding - by El Forum - 08-25-2009, 05:42 PM
Query Binding - by El Forum - 08-26-2009, 12:46 AM
Query Binding - by El Forum - 03-06-2010, 05:11 PM
Query Binding - by El Forum - 11-25-2010, 01:12 PM



Theme © iAndrew 2016 - Forum software by © MyBB