Two database connections

Author Message

Sjoerd van Steijn

Tuesday 21 December 2004 12:41:13 am

I want to use a dedicated database for an extension so i can use the same extension in different ez sites. When i try to connect to the extension database for inserting data, the site data will not be shown. What do i do wrong or is it impossible to have 2 database connections at once.

When i use getDB the ez content won't be shown.

* * * script * * * * * * * * *

function getDB($dbname = "") {

global $arrdbaccess;
if ($dbname == "") {
$dbname = $arrdbaccess["dbname"];
}

if (mysql_select_db ( $dbname )) {
return true;
} else {
return false;
}
}

function run_thisquery($query, $strid = "") {
global $arrdbaccess, $objconn;
$dbname = $arrdbaccess["dbname"];

#voer een insert of update query uit. retourneer bij een insert het autoincrement id
openConnection($objconn);
mysql_select_db ( $dbname );
mysql_query($query);

if (($strid == "") or ($strid == "0")) {
$strid = mysql_insert_id();
}
mysql_query("COMMIT");
closeConnection($objconn);
return $strid;
}

Shafiq Far

Wednesday 02 February 2005 7:44:04 am

Hi-

I'm having the same problem - <i>except using PostgreSQL.</i>

If anyone around knows how to get around this please let me know.

Thanks,

Sjoerd van Steijn

Tuesday 15 February 2005 6:03:47 am

I think the reason why i can't make two database connections is to protect other websites. I have found a solution to work around this problem. I removed the getDB function in the module and used the global variable arrdbaccess["dbname"] in the queries (in my module classes) to contact the database correctly. for example

function functionname($var1,$var2) {
global $arrdbaccess;

$sql="SELECT field1 FROM ".$arrdbaccess['dbname'].".table WHERE field2='".$var1."' and field3='".$var2."' ";

$result = run_rentequery($sql);
return $result;
}

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 19 2025 09:11:57
Script start
Timing: Jan 19 2025 09:11:57
Module start 'layout'
Timing: Jan 19 2025 09:11:57
Module start 'content'
Timing: Jan 19 2025 09:11:59
Module end 'content'
Timing: Jan 19 2025 09:11:59
Script end

Main resources:

Total runtime1.4127 sec
Peak memory usage4,096.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0087 589.1797152.6250
Module start 'layout' 0.00870.0041 741.804739.4453
Module start 'content' 0.01281.3981 781.2500477.2031
Module end 'content' 1.41090.0018 1,258.453112.1641
Script end 1.4127  1,270.6172 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00340.2408160.0002
Check MTime0.00130.0945160.0001
Mysql Total
Database connection0.00160.112710.0016
Mysqli_queries1.353395.7937570.0237
Looping result0.00060.0454550.0000
Template Total1.371697.120.6858
Template load0.00200.143920.0010
Template processing1.369596.942720.6848
Template load and register function0.00020.015810.0002
states
state_id_array0.00130.095110.0013
state_identifier_array0.00180.127420.0009
Override
Cache load0.00160.1162450.0000
Sytem overhead
Fetch class attribute can translate value0.00080.056020.0004
Fetch class attribute name0.00160.115630.0005
XML
Image XML parsing0.00020.017320.0001
class_abstraction
Instantiating content class attribute0.00000.000530.0000
General
dbfile0.00080.0560100.0001
String conversion0.00000.000740.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
9content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
6content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 20
 Number of unique templates used: 5

Time used to render debug report: 0.0001 secs