PDO implementation unexpected behaviour

26 views
Skip to first unread message

Simon Mottram

unread,
Apr 7, 2015, 11:16:12 AM4/7/15
to caucho-...@googlegroups.com
Not a PHP expert, but I'm pretty sure there's something up here.

I'm porting a well known PHP app to Quercus, so I am pretty confident that the code works under most PHP implementations.   The system attempts to determine if a schema exists by connecting to it, and checking for an exception.

            $driver_options = array(
                PDO
::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'",
                PDO
::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
               
);
           
           
try {
               
                $database
= new PDO($dsn, $values['dbUser'], $values['dbPass'], $driver_options);

               
// $database is false on quercus, the exception below isn't thrown
               
           
} catch(Exception $e) {
               
               
if($e->getCode() == 1049) {
                   
// If schema does not exist, try to create it
                    create
...

This code works fine under XAMPP for example.

On Quercus it returns false instead of throwing an exception.  Who's wrong here =)

Obviously I can work around this simply enough, but I thought it might be worth highlighting.

Cheers

S

Simon Mottram

unread,
Apr 7, 2015, 11:22:02 AM4/7/15
to caucho-...@googlegroups.com
my bad, $database is not false, it's a valid connection object even when the database name is invalid.

If you try and do any query, the query object is false. 

But still, I think it should throw an exception.

andro...@gmail.com

unread,
May 1, 2015, 3:08:53 AM5/1/15
to caucho-...@googlegroups.com
Does this actually works for you: "SET NAMES 'UTF8'" ?

I've tried it in many different ways, but nothing seems to work.

SET NAMES utf8
SET NAMES UTF8
SET NAMES 'utf8'
SET NAMES 'UTF8'

Also, the last download doesn't support PDO::MYSQL_ATTR_INIT_COMMAND, so I had to change to $database->exec("SET NAMES ..."); How did you make that actually work?
Reply all
Reply to author
Forward
0 new messages