Welcome Guest, Not a member yet? Register   Sign In
Database query with where clause for column string is in error
#1

[eluser]Unknown[/eluser]
I'm trying to code a query statement to DB2 database on Windows.

My code is

$sql = "select userid, name, surname from adminuser where userid = ? and password = ?";
$query = $this->db->query($sql, array($userid, $password));

==============================================================

I've got an error like this:

A Database Error Occurred
Error Number:

select userid, name, surname from adminuser where userid = 'user1' and password = 'passw0rd'

Filename: C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Code\system\database\DB_driver.php

Line Number: 330

==============================================================

If I copy the SQL statement to query directly with DB2, it works.

I tried querying another table using where clause with integer column, it works fine.

Please help,
Thank you.
#2

[eluser]Unknown[/eluser]
I found the cause of the problem.
The _execute function in db2c_driver.php call _prep_query function which call @db2_escape_string($sql).
The @db2_escape_string function will modify ' to '' that caused the error.

Commenting out the _prep_query function solved the problem.

function _execute($sql)
{ /* comment the following line out */
// $sql = $this->_prep_query($sql);
if (!$this->conn_id) echo "**** CONNECTION NOT ACTIVE ****";
$sql = str_replace("\n", ' ', $sql);
log_message('debug', "SQL: $sql");
return @db2_exec($this->conn_id, $sql);
}




Theme © iAndrew 2016 - Forum software by © MyBB