Welcome Guest, Not a member yet? Register   Sign In
problem binding query values
#1

[eluser]Unknown[/eluser]
Hi,

I'm a new member in CI community and i'm having problems with bindings variables in SQL queries.
In a model when i use this code

Code:
$sql = "INSERT INTO exp_passager (pass_account, pass_civ, pass_nom) VALUES('{$this->account_id}', '$civility', '$name')";
$query = $this->db->query($sql);

all works fine but when i try to bind inserted values like below,

Code:
$sql = "INSERT INTO exp_passager (pass_account, pass_civ, pass_nom) VALUES(?, ?, ?)";
$query = $this->db->query($sql, $this->account_id, $civility, $name);

a mysql error occurs

Code:
Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

INSERT INTO exp_passager (pass_account, pass_civ, pass_nom) VALUES('TOTO',

If there's something i missed could someone tell me what's wrong.

Thanks by advance
#2

[eluser]TheFuzzy0ne[/eluser]
For query binding $this->db->query() needs only two parameters - The string, and either a single value, or an array of values.

Code:
$sql = "INSERT INTO exp_passager (pass_account, pass_civ, pass_nom) VALUES(?, ?, ?)";
$query = $this->db->query($sql, array($this->account_id, $civility, $name));
#3

[eluser]Unknown[/eluser]
it works fine now thanks for lightning response :lol: :lol:




Theme © iAndrew 2016 - Forum software by © MyBB