How can combine two different MySQL connections in PHP?

184 views Asked by At

I followed many tutorials to set up a registration form on my site. Now I added file upload on a extra site and I'm not sure how to combine the MySQL connections. I want to make a PDO Solution.

database.php (MySQL Connection #1) for register form.

<?php
$server = 'localhost';
$username = 'xxx';
$password = '';
$database = 'auth';

try{
    $conn = new PDO("mysql:host=$server;dbname=$database;", $username, $password);
} catch(PDOException $e){
    die( "Connection failed: " . $e->getMessage());
}

dbconfig.php (MySQL Connection #1) for file upload.

<?php
$dbhost = "localhost";
$dbuser = "xxx";
$dbpass = "";
$dbname = "dbtuts";
mysql_connect($dbhost,$dbuser,$dbpass) or die('cannot connect to the server'); 
mysql_select_db($dbname) or die('database selection problem');
?>

I'm working with the Online IDE www.c9.io and using Bootstrap.

1

There are 1 answers

1
Your Common Sense On

You don't need it. Just create a single connection to a single database and then use it all the way through. Especially if it's your first attempt to work with PHP.