Jump to content

[SOLVED] Database Connection from within a function


Recommended Posts

Guest upirate

I have a page that has a connection to a database.

 

I also call a function that makes a connection to a new database, outputs some data and closes.

 

The problem:        When I call the function, the main page database seems to not pull any data at all.

 

 

Im using all new database connection variables and closing them. Still the main connection stops working.

When you say you are using all new database connection variables, you need to also make sure you are telling mysql to open a new connection. So, within your function, you need to make sure you have declared TRUE within your mysql_connect() function call for your fourth parameter:

<?php
$con1 = mysql_connect($host, $user, $pass); // First connection
$con2 = mysql_connect($host, $user, $pass, TRUE); // force a new connection
?>

 

Hope this helps.

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.