vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   ((( Two Simultaneous Database Connections ))) (https://vborg.vbsupport.ru/showthread.php?t=298812)

MacroPhotoPro 06-06-2013 07:34 PM

((( Two Simultaneous Database Connections )))
 
I am trying to access two databases on the same php page - one that I created, and the other being the vBulletin database.

Code:

        // On Server Development
        $host = 'localhost';
        $user = 'user";
        $pass = 'passwerd';

        // Define the databases
        $user_database = 'forum';
        $cust_database = 'custom_database';

        // Establish the connections
        $user_con = mysql_connect($host,$user,$pass) or die(mysql_error());
        $cust_con = mysql_connect($host,$user,$pass) or die(mysql_error());

        // Connect to the databases
        mysql_select_db($user_database, $user_con);
        mysql_select_db($cust_database, $cust_con);

        // Close the connections
        mysql_close($user_con);       
        mysql_close($cust_con);       

        // Demonstrate that the connections didn't throw an exception
        phpinfo();


It's not working and there seems to be some mechanism preventing it from working.

Why can I not have two simultaneous connections? Is there some prohibition against having two simultaneous database connections with MYSQL? If you require additional information, please let me know.

Thank you,

Jack

nhawk 06-06-2013 07:58 PM

MySQL returns the same connection ID if you connect to two databases at once. So if you do need to connect to two databases, you need to do so before each query.

In your case, $user_con will be the same as the $cust_con connection ID.

You can also avoid this by passing the 4th connect parameter to the second connection like this...

Code:

$cust_con = mysql_connect($host,$user,$pass,true) or die(mysql_error());

MacroPhotoPro 06-07-2013 10:21 AM

That is great; I will try it :)

Thank you for your time!

Jack


All times are GMT. The time now is 08:24 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01519 seconds
  • Memory Usage 1,708KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete