PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » MDB2 » Bug #5195

DB Wrapper adds double quotes

Details

Submitted2005-08-24 10:21 UTC
Fromo dot persson at gmail dot com
Assignedlsmith
StatusClosed
PackageMDB2
PHP Version5.0.4
OSLinux
Roadmaps(Not assigned)

Comments

[2005-08-24 10:21 UTC] o dot persson at gmail dot com

Description:
------------
Not 100% sure that this is a bug, but it's causing problems for me. Using the DB wrapper with the Log-package gives me problem.

This will need a small patch applied to Log/sql.php. Otherwise, the Log package will require the DB.php which contains a DB class as MDB2/Wrapper/peardb.php does.

Below is also the propsed patch for peardb.php. I don't know if this is only a behaviour of the MySQL driver.

Test script:
---------------
require_once('Log.php');
require_once('MDB2.php');
MDB2::loadFile('Wrapper/peardb');

$dsn = 'mysql://user:pass@host/log-db';
$conf = array('dsn' => $dsn, 'sequence' => 'log_seq');
$logger = &Log::singleton('sql', 'log', 'ident', $conf);
$logger->log('test');

Index: Log/sql.php
===================================================================
--- Log/sql.php (revision 20)
+++ Log/sql.php (working copy)
@@ -8,7 +8,8 @@
*/

/** PEAR's DB package */
-require_once 'DB.php';
+if (!class_exists('DB'))
+ require_once 'DB.php';

Index: MDB2/Wrapper/peardb.php
===================================================================
--- MDB2/Wrapper/peardb.php (revision 23)
+++ MDB2/Wrapper/peardb.php (working copy)
@@ -363,7 +363,7 @@
if (is_null($string)) {
return 'NULL';
}
- return "'".$this->db_object->quote($string)."'";
+ return $this->db_object->quote($string);
}

function escapeSimple($str)

Expected result:
----------------
Data insterted into table log.

Actual result:
--------------
Error: 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 'ident'', 3, ''MDB2 Error: syntax error'')' at line 1

Generated query: insert into log (id, logtime, ident, priority, message)values(189, CURRENT_TIMESTAMP, ''ident'', 3, ''MDB2 Error: syntax error'')