No announcement yet.

Changing MySQL DB Connection at run time

  • Filter
  • Time
  • Show
Clear All
new posts

  • Changing MySQL DB Connection at run time


    I am using SC 7.1 and MySql 5.6.11 and PHP version 5.4.22

    I wanted to understand how to change the database connection during run time. Lets say that I want to have one single application which needs to connect to different database (however the tables and structure are going to be the same).

    Lets look at the following in my first screen I will have something like this

    Customer : <Dropdown / Combo box to list down the customer list>
    Login Name:
    Password :

    Now based on Customer; I want to be able to connect to different database schema in MySQL. Is that possible? Or is there any other workaround for this scenario.

    Your help would be highly appreciated.


  • #2
    I would appreciate if someone can answer this question please.


    • #3
      It is only possible if you hack into the generated code (as far as I know). But you would get some problems if you want one person to connect with database 1 and one with database 2 at the same time as far as I can see...
      If you use advanced deployment you will see that in the generated code the name of the connection is placed <your application name>.php file.
      $_SESSION['scriptcase']['grid_filestorage']['glo_nm_perfil'] = "";
      $_SESSION['scriptcase']['grid_filestorage']['glo_nm_path_prod'] = "/scriptcase/prod";
      $_SESSION['scriptcase']['grid_filestorage']['glo_nm_path_imagens'] = "/scriptcase/file/img";
      $_SESSION['scriptcase']['grid_filestorage']['glo_nm_path_imag_temp'] = "/scriptcase/tmp";
      $_SESSION['scriptcase']['grid_filestorage']['glo_nm_path_doc'] = "c:/storage";
      $_SESSION['scriptcase']['grid_filestorage']['glo_nm_conexao'] = "conn_oracle";

      So you would need to change the last session variable in your code somewhere..
      Be warned this is untested, may not work and is at your own risk...
      Last edited by rr; 03-03-2014, 09:17 AM.


      • #4
        There is a macro for that

        sc_change_connection("Old_Connection", "New_Connection")

        Well explained in

        So you have to develop using a "default" connection ad change dynamically in production.
        Never used but seems to be what you are searching.
        Giorgio Bravi
        Dolphin Software & Thinkware


        • #5
          You can follow this thread

          Giorgio Bravi
          Dolphin Software & Thinkware


          • #6
            Cool I didnt know that.