binumathew Posted March 6, 2009 Share Posted March 6, 2009 How Can we use more than one Data Base Access in One Page Can u show me some examples? or code snippets?? Quote Link to comment https://forums.phpfreaks.com/topic/148217-solved-how-can-we-use-more-than-one-data-base-access-in-one-page/ Share on other sites More sharing options...
Mchl Posted March 6, 2009 Share Posted March 6, 2009 what do you mean by "more than one Data Base Access in One Page"? Quote Link to comment https://forums.phpfreaks.com/topic/148217-solved-how-can-we-use-more-than-one-data-base-access-in-one-page/#findComment-778039 Share on other sites More sharing options...
binumathew Posted March 6, 2009 Author Share Posted March 6, 2009 Means,i can able to Connect one or more table and DB's at same time can it possible??? Quote Link to comment https://forums.phpfreaks.com/topic/148217-solved-how-can-we-use-more-than-one-data-base-access-in-one-page/#findComment-778050 Share on other sites More sharing options...
Mchl Posted March 6, 2009 Share Posted March 6, 2009 Yes you can. The exact way to do it depends on what database you use. Quote Link to comment https://forums.phpfreaks.com/topic/148217-solved-how-can-we-use-more-than-one-data-base-access-in-one-page/#findComment-778056 Share on other sites More sharing options...
binumathew Posted March 6, 2009 Author Share Posted March 6, 2009 i am using MySQL 5, Can u gave me a code snippet??? Quote Link to comment https://forums.phpfreaks.com/topic/148217-solved-how-can-we-use-more-than-one-data-base-access-in-one-page/#findComment-778058 Share on other sites More sharing options...
Mchl Posted March 6, 2009 Share Posted March 6, 2009 Sure. //create connection to database1 $connection1 = new mysqli("server1","user1","password1","database1"); //create connection to database2 $connection2 = new mysqli("server2","user2","password2","database2"); //this is the query we want to send to databases $sql = "SELECT * FROM table1"; //query database1 $result1 = $connection1->query($sql); //query database2 $result2 = $connection2->query($sql); Quote Link to comment https://forums.phpfreaks.com/topic/148217-solved-how-can-we-use-more-than-one-data-base-access-in-one-page/#findComment-778063 Share on other sites More sharing options...
binumathew Posted March 6, 2009 Author Share Posted March 6, 2009 Ok Is it important that we need to close each connection..??? Quote Link to comment https://forums.phpfreaks.com/topic/148217-solved-how-can-we-use-more-than-one-data-base-access-in-one-page/#findComment-778065 Share on other sites More sharing options...
Mchl Posted March 6, 2009 Share Posted March 6, 2009 All connections are closed when script ends execution .Closing them manually is recommended though (less strain on MySQL server). Quote Link to comment https://forums.phpfreaks.com/topic/148217-solved-how-can-we-use-more-than-one-data-base-access-in-one-page/#findComment-778067 Share on other sites More sharing options...
binumathew Posted March 6, 2009 Author Share Posted March 6, 2009 Can u gave me code for that???as i am beginner in PHP i dont know well about PHP Quote Link to comment https://forums.phpfreaks.com/topic/148217-solved-how-can-we-use-more-than-one-data-base-access-in-one-page/#findComment-778070 Share on other sites More sharing options...
Mchl Posted March 6, 2009 Share Posted March 6, 2009 Connections are closed using $connection1->close(); It's all in manual for mysqli Quote Link to comment https://forums.phpfreaks.com/topic/148217-solved-how-can-we-use-more-than-one-data-base-access-in-one-page/#findComment-778072 Share on other sites More sharing options...
binumathew Posted March 6, 2009 Author Share Posted March 6, 2009 i am using MYSQL not MYSQLI One more Question,i am using two tables from one database.on that time can i use the same connection,how to?? Quote Link to comment https://forums.phpfreaks.com/topic/148217-solved-how-can-we-use-more-than-one-data-base-access-in-one-page/#findComment-778074 Share on other sites More sharing options...
Mchl Posted March 6, 2009 Share Posted March 6, 2009 Then check the manual for mysql (although be aware, that mysqli should be used for MySQL 4.1 and higher). If you need to send two or more queries within one connection... just do it! $sql1 = "SELECT * FROM table1"; $result1 = $connection->query($sql1); $sql2 = "SELECT * FROM table2"; $result2 = $connection->query($sql2); Quote Link to comment https://forums.phpfreaks.com/topic/148217-solved-how-can-we-use-more-than-one-data-base-access-in-one-page/#findComment-778088 Share on other sites More sharing options...
binumathew Posted March 6, 2009 Author Share Posted March 6, 2009 How it is possible??beacause already a connection is open na?? Quote Link to comment https://forums.phpfreaks.com/topic/148217-solved-how-can-we-use-more-than-one-data-base-access-in-one-page/#findComment-778101 Share on other sites More sharing options...
binumathew Posted March 6, 2009 Author Share Posted March 6, 2009 I am using MYSQL 5 is it important that i should use MYSQLi()???? Quote Link to comment https://forums.phpfreaks.com/topic/148217-solved-how-can-we-use-more-than-one-data-base-access-in-one-page/#findComment-778102 Share on other sites More sharing options...
Mchl Posted March 6, 2009 Share Posted March 6, 2009 Yes... once you open the connection, you can use it to send as many queries as you wish (or as many as MySQL server permits you). mysqli is recommended for MySQL 4.1 and up. You can still use the 'old' mysql extension, but mysqli gives you several important advantages. Read this excellent article http://www.charlesrowe.com/2007/06/15/the-four-major-benefits-of-mysqli/ Quote Link to comment https://forums.phpfreaks.com/topic/148217-solved-how-can-we-use-more-than-one-data-base-access-in-one-page/#findComment-778105 Share on other sites More sharing options...
binumathew Posted March 6, 2009 Author Share Posted March 6, 2009 The link is not working Quote Link to comment https://forums.phpfreaks.com/topic/148217-solved-how-can-we-use-more-than-one-data-base-access-in-one-page/#findComment-778110 Share on other sites More sharing options...
Mchl Posted March 6, 2009 Share Posted March 6, 2009 Aww... man!... It was such a good article... I hope it's just a server problem and the article will be available soon... Anyway, there even is a tool for automated conversion from mysql to mysqli http://forge.mysql.com/wiki/Converting_to_MySQLi Quote Link to comment https://forums.phpfreaks.com/topic/148217-solved-how-can-we-use-more-than-one-data-base-access-in-one-page/#findComment-778111 Share on other sites More sharing options...
binumathew Posted March 6, 2009 Author Share Posted March 6, 2009 Thks...... Quote Link to comment https://forums.phpfreaks.com/topic/148217-solved-how-can-we-use-more-than-one-data-base-access-in-one-page/#findComment-778113 Share on other sites More sharing options...
Mchl Posted March 6, 2009 Share Posted March 6, 2009 And another informative article from Zend http://devzone.zend.com/node/view/id/686 Quote Link to comment https://forums.phpfreaks.com/topic/148217-solved-how-can-we-use-more-than-one-data-base-access-in-one-page/#findComment-778115 Share on other sites More sharing options...
binumathew Posted March 6, 2009 Author Share Posted March 6, 2009 Can u gave me a full snippet for ACCESSING 2 TABLES @ SAME TIME,LIKE CONECTING,ACCESSING AND SO ON?? Quote Link to comment https://forums.phpfreaks.com/topic/148217-solved-how-can-we-use-more-than-one-data-base-access-in-one-page/#findComment-778116 Share on other sites More sharing options...
Mchl Posted March 6, 2009 Share Posted March 6, 2009 I gave you links to sources with code examples. Try them. Modify them. If you have problems, post your code and say what's going wrong. Quote Link to comment https://forums.phpfreaks.com/topic/148217-solved-how-can-we-use-more-than-one-data-base-access-in-one-page/#findComment-778119 Share on other sites More sharing options...
binumathew Posted March 6, 2009 Author Share Posted March 6, 2009 I need code in PHP by MYSQL. not MYsqli Quote Link to comment https://forums.phpfreaks.com/topic/148217-solved-how-can-we-use-more-than-one-data-base-access-in-one-page/#findComment-778123 Share on other sites More sharing options...
Mchl Posted March 6, 2009 Share Posted March 6, 2009 The syntax is close to identical: mysql Quote Link to comment https://forums.phpfreaks.com/topic/148217-solved-how-can-we-use-more-than-one-data-base-access-in-one-page/#findComment-778126 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.