Welcome Guest, Not a member yet? Register   Sign In
Query Bindings Problem
#1

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??
Reply
#2

@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/gener...pplication ) to see what query CI generates and then see if it actually works in the database?
Reply
#3

(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/gener...pplication ) 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.
Reply
#4

(This post was last modified: 06-12-2020, 10:18 AM by dave friend.)

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?
Reply
#5

(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!!
Reply
#6

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

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

after
Reply
#7

(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!!
Reply
#8

@abelhermar,

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




Theme © iAndrew 2016 - Forum software by © MyBB