CodeIgniter Forums
DB PDO Query Error - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: DB PDO Query Error (/showthread.php?tid=57340)

Pages: 1 2


DB PDO Query Error - El Forum - 03-07-2013

[eluser]xonorageous[/eluser]
Hi,

I'm developing a web application that queries an oracle database.
I've tried querying $this->db->get( 'utilisateur' ); and everything worked fine, I could see all the users in the table.



However when passing the where parameter nothing is being returned. My code for the query is:
Code:
$this->db->get_where( 'utilisateur', array( 'login' => 'A.Madison', 'mdp' => 'ju4Omr' ) );

When I checked the last query I saw that the values in the array are missing:
Code:
["queryString"] => string(72) "SELECT *
FROM utilisateur
WHERE login =  ''
AND mdp =  ''"

Does anyone know how to fix this? Is it a problem with the pdo driver for oracle or is the problem in the code ?

Thanks in advance


DB PDO Query Error - El Forum - 03-07-2013

[eluser]TheFuzzy0ne[/eluser]
Have you tried doing it any other ways? Perhaps see if it works when you use $this->db->where(array()) or $this->db->where('col', 'val')?

I agree, this is a strange issue. I'd be interested to know where the problem lies. I can't help thinking someone may have tampered with your system files.


DB PDO Query Error - El Forum - 03-07-2013

[eluser]xonorageous[/eluser]
Thanks for the reply.

I was the one who set up the framework, and for the moment, the only person to have worked on it.
None of the system files have been modified.

I've just tried setting up a test mysql database and run the same query with that and it worked. Not sure what the problem is.

I've already tried changing the query to have multiple where clauses but that didn't work either.


DB PDO Query Error - El Forum - 03-07-2013

[eluser]TheFuzzy0ne[/eluser]
You ran the same query using the Active Record class?

I would suggest making a copy of your system directory, and then seeing if you can trace the problem. Add some debug code to the active record class to make sure it's getting the arguments it's expecting, and trace it through the process.

Sorry I can't offer you any better advice, but the problem has to be somewhere, and that's probably the best place to start.


DB PDO Query Error - El Forum - 03-07-2013

[eluser]xonorageous[/eluser]
OK, thanks for the help Smile


DB PDO Query Error - El Forum - 03-08-2013

[eluser]xonorageous[/eluser]
I've just removed the entire system folder and replaced it with a fresh copy from the stable branch of codeigniter on github.
Still not working, I'm going to start debugging :/


DB PDO Query Error - El Forum - 03-08-2013

[eluser]xonorageous[/eluser]
I've just started debugging system/database/DB_active_rec.php and the problem seems to be there.

using the following code:

Code:
public function get_where($table = '', $where = null, $limit = null, $offset = null)
{
  dump( $where );
  if ($table != '')
  {
   $this->from($table);
  }

  if ( ! is_null($where))
  {
   dump( $this->where($where)); exit();
  }

  if ( ! is_null($limit))
  {
   $this->limit($limit, $offset);
  }

  $sql = $this->_compile_select();

  $result = $this->query($sql);
  $this->_reset_select();
  return $result;
}

The dump of $where is giving me
Code:
Dump => array(1) {
  ["login"] => string(9) "A.Madison"
}

However the second dump on $this->where($where) is returning
Code:
["ar_where"] => array(1) {
    [0] => string(11) "login =  ''"
  }

Why is the value of the login key disappearing ?


DB PDO Query Error - El Forum - 03-08-2013

[eluser]TheFuzzy0ne[/eluser]
I think you need to debug the where() method, since that's where things seem to be disappearing.


DB PDO Query Error - El Forum - 03-08-2013

[eluser]xonorageous[/eluser]
I've just finished debugging.
The problem is coming from system/DB/DB_active_rec.php in the _where method.
On line 426 it is written
Code:
$v = ' '.$this->escape($v);

By removing $this->escape :
Code:
$v = $v

the code is working correctly. I don't think it is recommended to remove the escape function inside the function though so is there any way to configure the escape method or render it null?


DB PDO Query Error - El Forum - 03-08-2013

[eluser]TheFuzzy0ne[/eluser]
I'm pretty sure that the leading space is required.

You can prevent escaping by passing FALSE as the third parameter to $this->db->where();

Code:
$this->db->where('some_col', 'some_value', FALSE);

I'm sorry you've had such an annoying problem. I'd appreciate it if you could file this as a bug.