dynamically change connection

Hello everyone, i am discovering the wonderful possibilities of scriptcase, but i am faced to an issue i can’t find the solution, perhaps someone can help.

I am using a PDO Informix database. Is it possible to let the user set the login/password and THEN connect to database with those?

Also, is it possible to dynamically change the connection used by the application? I suppose i will have to use sc_change_connection but how can i get the “old connection” name?

Re: dynamically change connection

+1

Re: dynamically change connection

Hi,
click on the “Edit Connections” icon and you get all your “Old_Connections” listed.

Furthermore have a look at the end of the SQL section in WebHelp --> ScriptCase Macros. There you will find the variables you have to use to connect to your database with different users.

jsb

Re: dynamically change connection

hello, thanks for your help.

i already read the sc macros help section. I tried to change the variables they talk about, but no effect ocurred, maybe i missed something. someone already managed to get this working?

about the “old connection” i am talking about a dynamical way to get it so that the user can change the connection during the program.

Hi ouissem,
You can change the database connection using scriptcase. Please follow these steps:

#1 Example to execute a SQL query using other connection (ONLY for this SQL query)

sc_lookup(rs, "select field from table", 'MyNewConnection');

#2 Example to change connection (Applies to all your SQL querys and All Applications)

sc_change_connection ( "MyOldConnection",'MyNewConnection');

So if you want to switch a connection depending of the user you can use this script:


if($user=='jonh'){
     sc_change_connection ( "MyOldConnection",'MyNewConnection');
}

Note: When using sc_change_connection you need to reload the page or redir to another application to see the connection changes.
Note2: Your connection name is the name that you define in ScriptCase Database>NewConnection

If you want to change the connection dinamically you need first to define all the connections and then associate in a table the name of connection of each user. And reeplace the string for a varible ($user_connection), for example:

sc_change_connection ( "MyOldConnection",$user_connection);

🚀 Scriptcase 9.12 is now available! Check out the new features here 👉🚀 Next Monday (02/24), Scriptcase 9.12 will be released! Check out the new features before anyone else 👉