Jump to content

including my php file breaks the db connection of parent script


Recommended Posts

Hi there guys,

I originally asked this on another forum, but I've either worn out my welcome, or I've stumped them all.

I created a script that uses a mysql connection, and it's intended to be inserted as a block in other scripts.  I'm attempting to insert it into a forum system, but it's breaking the mysql connection of the forum script when I try to use it. The db connection is made in a config file, and it's called by the block script.

forum db is roughing_forum
my script is roughing_automonial
db client is the same for both

The connection string for my script(config.php):

[code=php:0]
$autoconn = mysql_connect("$dhost","$dusername","$dpwd") or die ("Unable to connect to database.");

$dbi=mysql_select_db($dbname,$autoconn) or die("Unable to make master connection to database from the config file!" . mysql_error());
[/code]

When I insert the script into the forum via include, I get an error that shows me that the forum is now trying to use my script's db for data:

[quote]
Fatal error: Database error: 1146: Table 'roughing_automonial.v_pm' doesn't exist - File: /home/roughing/public_html/templates/1/header.html(54) : eval()'d code on line 26 in /home/roughing/public_html/classes/database/mysql.inc.php on line 291
[/quote]

So I added the following to the very last line of my block script:

[code=php:0]
mysql_close($autoconn);
[/code]

With this setup, the error I receive makes it look like my script has now shut down all mysql connections:

[quote]
Fatal error: Database error: : - File: /home/roughing/public_html/templates/1/header.html(54) : eval()'d code on line 26 in /home/roughing/public_html/classes/database/mysql.inc.php on line 291
[/quote]

I don't know what else to do.  I tried

[code=php:0]
$autoconn = null;
[/code]

but that put me back to the first error.

Any help in solving this would be greatly appreciated.

thanks,
json
You will either need to go through all the scripts in the forum and explicitly tell each database call to use a particular link (the forums conection), or, as a quick workaround, do as you have done and close your connection, but afterwoods re open the forums connection explicitly.

Understand?
Hi thorpe and thanks very much for the reply.

I think I understand what you are saying, but this won't work for my needs.

I am writing the script to be an automated testimonial block that people can install on their sites, and their needs will all differ.  Some may be integrating it into a home-brew site, some phpBB, etc.

Is there no way to integrate an out of the box script install into an existing site?  I would be quite surprised to find that was the case.

Thanks very much for your time,
json
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.