How to Connect to Multiple Database

PHP Syntax

Host can be localhost, or a web address like:

// connect to database
$db1 = mysql_connect( HOST, USERNAME, PASSWORD );
$db2 = mysql_connect( HOST2, USERNAME2, PASSWORD2 );

// select database
mysql_select_db( DATABASE NAME, $db1 );
mysql_select_db( DATABASE2 NAME, $db2 );

// set character set

// run a query on db1
mysql_query( QUERY, $db1 );

// run a query on db2
mysql_query( QUERY, $db2 );


Related articles

Email Validation

Email Validation


Learn how to validate email on client side with HTML5, Javascript and on server side with PHP.

Generate Thumbnail on the Fly with PHP

Generate Thumbnail on the Fly with PHP


In a previous artice I already showed you how to generate square thumbnails with PHP. Now I show you how to keep the original ratio of the image and how to control the alignment of the square image.

Facebook Upload Photo to User′s Profile

Facebook Upload Photo to User′s Profile


Learn how to upload a photo to Facebook user′s profile with PHP SDK via Graph API!

Leave a comment

We welcome any comment from you! Please keep in mind that comments are moderated and rel='nofollow' is in use. So, please do not use a domain as your name or a spammy keyword, or your comment will be deleted.

Name: *

E-mail: *

Message: *

Click on the apple *

Find us on Facebook



Back to Top