ksmatthews Posted October 10, 2007 Share Posted October 10, 2007 HI Gurus, I have a simple update form that creates a MySQL connection with a DB to display on the form all previous user preferences. I also need to dynamically populate various drop down lists (select objects) by running entirely different SQL commands based upon data in different tables in the same DB. I would need to set up more DB connections in order to do this. Q1. Can I use the same connection ID ? ie can I avoid re-connecting to the same DB ? Q2. Will not multiple connections like this degrade performance ? Q3. Is there an easy way of doing this ? (running multiple queries) regards, Steven M Quote Link to comment https://forums.phpfreaks.com/topic/72593-multiple-database-connections/ Share on other sites More sharing options...
micah1701 Posted October 10, 2007 Share Posted October 10, 2007 ...data in different tables in the same DB... if all the data is in one physical database, you only need to make one connection. <?php mysql_connect("localhost", $username, $password); mysql_db_connect("database_name"); //make multiple quiers now with the same connection $query = mysql_query("SELECT * FROM table WHERE column_x = 'foo_bar' "); $result = mysql_fetch_array($query); print_r($result); $query = mysql_query("SELECT * FROM table WHERE column_y = 'foo_bar' "); $result = mysql_fetch_array($query); print_r($result); $query = mysql_query("SELECT * FROM table WHERE column_z = 'foo_bar' "); $result = mysql_fetch_array($query); print_r($result); ?> Quote Link to comment https://forums.phpfreaks.com/topic/72593-multiple-database-connections/#findComment-366069 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.