Re: Native Error 1064 with PEAR DB and mysql

From: Date: Fri, 20 Sep 2002 10:54:41 +0000
Subject: Re: Native Error 1064 with PEAR DB and mysql
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-2354@lists.php.net to get a copy of this message
Henrik, Do you really have to quote table "person" in the SQL statement. I don't think this is necessary and phpMyAdmin could handle the issue while PEAR doesn't. Try it without the quotes. Best regards, Stanislav HK> Hello, HK> I have a strange problem with PEAR DB class. I use PHP with PEAR on a HK> Windows XP machine and I use MySQL as database. HK> The following code doesn't realy work as i expect it to: HK> // Use the standard DSN HK> $dsn = getDSN(); HK> // Connect to the databse and check for errors HK> $db = DB::connect($dsn,true); HK> if (DB::isError($db)) { HK> echo "Could not connect!"; HK> die ( $db->getMessage() ); HK> } HK> // All we have tod do is to select a few columns from the person table HK> $sql = "SELECT personID, firstname, surname, title FROM HK> person WHERE personId>0 ORDER BY surname"; HK> $psql = $db->quote($sql); HK> // Get the data with getAll HK> $result = $db->query($psql); HK> if (DB::isError($result)) { HK> echo "<p>DSN: $dsn"; HK> echo "<p>Query failed</p>"; HK> echo "<p>".$result->getUserInfo()."</p>"; HK> die ($result->getMessage()); HK> } else { HK> .... HK> It fails after the query with the following error: HK> ************** HK> DSN: mysql://xxx:yyy@localhost/persondatabas HK> Query failed HK> 'SELECT personID, firstname, surname, title FROM person HK> WHERE personId>0 HK> ORDER BY surname' [nativecode=1064 ** You have an error in your SQL syntax HK> near ''SELECT personID, firstname, surname, title FROM HK> person WHERE personId>>0 ORDER' at line 1] HK> DB Error: syntax error HK> *************** HK> The SQL works in phpMyAdmin. The problem might be realy easy but i don't HK> see it. Could some one please help me? HK> -- HK> Henrik Karlsson | www.henriks.org HK> Studying Automation Engineering | ICQ: UIN 2785561 HK> at Chalmers University of Technology | +46-707-99 50 31 HK> "Coughlin's law - anything else is always something better." Best regards, Stanislav mailto:stanis@sibfair.nsk.su

« previous php.pear.general (#2354) next »