CodeIgniter Forums
Query Bindings Problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: Query Bindings Problem (/thread-76695.html)



Query Bindings Problem - abelhermar - 06-10-2020

Hello!!

I have the next sentence, using pdo:

I have a problems where in the array parameters appear a variable type string:


$var1 = 1;
$var2 = 2;
$var3 = 'A';

$sentence = "SELECT column1, column2, column3 FROM table WHERE column1 = ? AND column2 = ? and column3 = ?";
$query = $this->db->query($sentence, array(intval($var1), intval($var2), strval($var3)));

And I get the next response:

A Database Error Occurred
Unsupported feature of the database platform you are using.


Where is the error??


RE: Query Bindings Problem - php_rocs - 06-10-2020

@abelhermar,

What version of CI are you using? Also, have you tried running your query directly in the database to make sure it actually works? Also, have you tried using the CI profiler ( https://codeigniter.com/userguide3/general/profiling.html?highlight=benchmark#profiling-your-application ) to see what query CI generates and then see if it actually works in the database?


RE: Query Bindings Problem - abelhermar - 06-12-2020

(06-10-2020, 09:15 PM)php_rocs Wrote: @abelhermar,

What version of CI are you using?  Also, have you tried running your query directly in the database to make sure it actually works?  Also, have you tried using the CI profiler ( https://codeigniter.com/userguide3/general/profiling.html?highlight=benchmark#profiling-your-application ) to see what query CI generates and then see if it actually works in the database?

Hi!!, I use CodeIgniter 3.1.10.

The problem in query is when I use a string value, for example:
$var1 = 1;
$var2 = 2;
$var3 = 3;

$sentence = "SELECT column1, column2, column3 FROM table WHERE column1 = ? AND column2 = ? and column3 = ?";
$query = $this->db->query($sentence, array(intval($var1), intval($var2), intval($var3)));

If only send a integer values, the query work's perfectly,

$var = "A";
I don´t know If I'm using correctly the parameters in sentence
$this->db->query($sentence, array(strval($var));

I'm going to read the documentacion about CI profiler, thank's.


RE: Query Bindings Problem - dave friend - 06-12-2020

If the items in the array are the data type that matches what the field handles, you don't need the inval() or strval() functions. If column1 handles integers then you should be able to use either the number 1 or the string '1' and have it work.

What is the datatype of column3?


RE: Query Bindings Problem - abelhermar - 06-12-2020

(06-12-2020, 10:17 AM)dave friend Wrote: If the items in the array are the data type that matches what the field handles, you don't need the inval() or strval() functions. If column1 handles integers then you should be able to use either the number 1 or the string '1' and have it work.

What is the datatype of column3?
Hi Dave friend: 

The column3 is char, and query fails only when I use a parameter different to int:

$var1 = 1;
$var2 = 2;

$sentence = "SELECT column1, column2, column3 FROM table WHERE column1 = ? AND column2 = ?";
$query = $this->db->query($sentence, array($var1, $var2));

I get the response ok.

In other case:
$var1 = 1;
$var2 = "A";

$sentence = "SELECT column1, column2, column3 FROM table WHERE column1 = ? AND column3 = ?";
$query = $this->db->query($[font=Tahoma, Verdana, Arial, sans-serif]sentence[/font], array($var1, $var2));
I get the error response.

Thank's for all!!


RE: Query Bindings Problem - dave friend - 06-12-2020

What do you see when, on a query you know will fail, you use

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

after


RE: Query Bindings Problem - abelhermar - 06-15-2020

(06-12-2020, 06:58 PM)dave friend Wrote: What do you see when, on a query you know will fail, you use

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

after

I get the next message:

Unsupported feature of the database platform you are using.
Filename: <project>/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php
Line Number: 171

The line contains a public funcion _escape_str($str), if I comment, the query work's perfectly!!



RE: Query Bindings Problem - php_rocs - 06-15-2020

@abelhermar,

What does the generated query look like when you add a string to the variable array?