Mantis - Quercus
Viewing Issue Advanced Details
1859 minor always 07-09-07 18:37 08-01-07 08:46
toomasr  
nam  
normal  
closed 3.1.2  
fixed  
none    
none 3.1.3  
0001859: JSR223: mysql_connect: Can't find database for driver
Using Quercus (SVN trunk, the product version drop-down has no SVN branches) as a JSR-223 ScriptEngine.

-------------- PHP -------------
mysql_connect("host", "username", "password");
mysql_select_db("dbname");
----------- EOF PHP -------------

Produces:
com.caucho.quercus.QuercusModuleException: Can't find database for driver 'com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource' and url 'jdbc:mysql://localhost:3306/' [^] [mysql_select_db]

I went in with a debugger using the SVN trunk as reference. This is what I found out.

As the connection requires the name of the database but PHP mysql interface insists on two calls (connect and select_db) then on eval'ing the first line the database name is missing and eval'ing the mysql_select_db the host, username, password are missing.

In a container this is resolved by the QuercusServlet calling setDatabase on the Quercus object. Quercus object's database name is used in the lookup.

In standalone environment there is no servlet and hence incomplete connection string. The current workaround seems to be using QuercusScriptEngine explicitly (not the ScriptEngine interface) and calling setDatabase on the Quercus object.

The solution would be to provide a way of connecting to a database in two steps. First gather the information with mysql_connect and init the connection after mysql_select_db.

Or maybe I'm missing something here :)
 patch.txt [^] (4,077 bytes) 07-10-07 15:55

Notes
(0002107)
toomasr   
07-10-07 15:55   
I've been working on it a bit more. I've modified to source to get my things working and based on that I propose a solution.

Probably the requirements are:
* Not to break PHP interfaces (mysql_connect, mysql_select_db)
* From JSR223 point of view retain encapsulation (no manual injection through getting an instance of Quercus and providing the datasource)

Why not have mysql_connect accept a JDBC string optionally as the host part?
* It is easily detectable from the string
* Won't have to save state to worry about mysql_select_db
* Will provide somewhat confusion (people accidently not benefitting from acquiring a connection through the Context lookup in the container)

Will look like this:
mysql_connect("jdbc:mysql://host/db?user=user&password=pwd", [^] "user", "pwd");

I've attached a patch to explain my idea. I've also made getQuercus in QuercusScriptEngine.java public to provide workarounds.
(0002170)
nam   
08-01-07 08:46   
php/214a

Thanks for the comments. Database should work now with JSR 223 and other app servers.