Mantis Bugtracker
  

Viewing Issue Advanced Details Jump to Notes ] View Simple ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0001859 [Quercus] minor always 07-09-07 18:37 08-01-07 08:46
Reporter toomasr View Status public  
Assigned To nam
Priority normal Resolution fixed Platform
Status closed   OS
Projection none   OS Version
ETA none Fixed in Version 3.1.3 Product Version 3.1.2
  Product Build
Summary 0001859: JSR223: mysql_connect: Can't find database for driver
Description 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 :)
Steps To Reproduce
Additional Information
Attached Files  patch.txt [^] (4,077 bytes) 07-10-07 15:55

- Relationships

- 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.
 

- Issue History
Date Modified Username Field Change
07-09-07 18:37 toomasr New Issue
07-09-07 18:38 toomasr Issue Monitored: toomasr
07-10-07 15:55 toomasr File Added: patch.txt
07-10-07 15:55 toomasr Note Added: 0002107
08-01-07 07:05 nam Status new => assigned
08-01-07 07:05 nam Assigned To  => nam
08-01-07 08:46 nam Status assigned => closed
08-01-07 08:46 nam Note Added: 0002170
08-01-07 08:46 nam Resolution open => fixed
08-01-07 08:46 nam Fixed in Version  => 3.1.3
02-14-08 01:08 taho Issue Monitored: taho


Mantis 1.0.0rc3[^]
Copyright © 2000 - 2005 Mantis Group
35 total queries executed.
28 unique queries executed.
Powered by Mantis Bugtracker