Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This patch lets Drupal handle multiple database layers. I think this closes the "TODO: Allow more than one database API to be present", so I've deleted that line.
Comment | File | Size | Author |
---|---|---|---|
#8 | database.inc_1.patch | 672 bytes | chx |
database.inc_0.patch | 647 bytes | chx | |
Comments
Comment #1
moshe weitzman CreditAttribution: moshe weitzman commentednice simple patch... i suggest explaining to the user what to do to fix his problem. For example, change your $dbtype URL in your includes/conf.php file
Comment #2
chx CreditAttribution: chx commentedThanks. But I do not really understand -- what shall I explain to who and where? I found the two examples (for mysql and pgsql) in conf.php pretty self-explaining, and if things go well, there will be a third soon: sqlite://database/sqlite/drupal.db -- as I have written, I already have an alpha-quality sqlite database layer.
Comment #3
tostinni CreditAttribution: tostinni commentedWell, regarding these patches, I have to mention a few point I faced when I try to add my Oracle database...
First of all, I don't think it's possible to include this patch without changing th structure of the files database.*.inc. The big problem is that the functions have the same name, so if you include more than one DB handler, you will got this error
Fatal error: Cannot redeclare db_connect() (previously declared in c:\archivos de programa\easyphp1-7\www\drupal2\includes\database.mysql.inc:23) in c:\archivos de programa\easyphp1-7\www\drupal2\includes\database.pgsql.inc on line 23
when you will activate second DB because all functions are already declared in previous database.inc.
Then you don't mention pear connector. And for those who use oracle, you use a connector DB (pear librairy) like "oci8://" or "oracle://"...
Comment #4
chx CreditAttribution: chx commentedIt's not about including several include files at once. It's about introducing new database.*.inc files. So, you have oci8:// in $db_url? My code will try to include database.oci8.inc and nothing else. The original version would try to include database.pgsql.inc in this case -- actually in any case, when it's not mysql://
Comment #5
tostinni CreditAttribution: tostinni commentedHum, but your first post mention the TODO :
So I think this TODO is exactly what this deals about : "more than one".
Regarding of my problem for oracle, normally you have to deal with the database.pear.inc, so I suggest this code :
But it won't solve the problem with multiple declarations and it doesn't activate database too...
Comment #6
chx CreditAttribution: chx commentedMaybe I misunderstood that TODO then. But still, this patch is needed to use pear:// or sqlite:// or whatever anyone will write a database.whatever.inc .
Comment #7
adrian CreditAttribution: adrian commentedI have a more complete patch (for CVS) that I am working on, which allows you to use a postgresql and mysql (and oracle and sqllite) connection in the same site.
The problem is currently that the database.*.inc files specify db_* functions. Which conflict with each other when more than one is loaded.
I added the db_* functions to database.inc , and use a new function db_invoke($function, $args, ...) which calls the functions in the format of db_$dbtype_$function.
I still need to clean the patch up some more, but the previous item was also assigned to me.
Comment #8
chx CreditAttribution: chx commentedI resubmit, I changed the title, and kept that TODO in database.inc 'cos there was a misunderstaning what it "multiple". I thought "multiple" was "mysq, pgsql, sqlite and whatever" while others thought "multiple at the same time". I am not that ambitous to face the second challenge, all I need is this patch to get into core to be able to move forward with sqlite.
Comment #9
nmarci CreditAttribution: nmarci commentedWe could use classes for each database driver, so there would be no namespace problem.
e.g.: the file includes/database.mysql.inc would contain
class database_mysql {
function db_connect($url) {
...
}
...
}
and the database.inc could be a wrapper:
function db_connect($url) {
$db_conns['name']['conn']->db_connect($url);
}
This would result the same as comment #7 would, but using the php's class feature.
Comment #10
Gábor HojtsyPlease do not hijack the issue title... Drupal tries to stay away from using classes, to look simple, and to be generally faster.
Comment #11
Dries CreditAttribution: Dries commentedCommitted to HEAD.
Comment #12
(not verified) CreditAttribution: commented