Using Scriptcase is possible to create applications that will work with multiple connections to different database (also different types of database) on the same project, changing it dynamically in run-time.

Check the example running

In this tutorial we will review a practical example of use for the macros sc_connection_edit and sc_connection_new on Scriptcase. On that example, Scriptcase will identify the company of the user who is logging in, changing the connection data dynamically for that user to access his company’s database. In a second step, Scriptcase will create a new connection dynamically to fetch data that will be used by a Grid application.

sc_connection_edit Macro

That macro can be used by any Scriptcase application, the changes in the connection will take effect the next time you connect to the database.

How to use sc_connection_edit:

sc_connection_edit(“conn_name”, $arr_conn);

1st parameter: connection name
2nd parameter: array of items you want to change the current connection.
The array can have the following indexes:
$arr_conn[‘persistent’] – The value “Y” or “N”

You can only use the index you want to change, but it is not required to give all of them.


Macro sc_connection_new

The macro can be used on any Scriptcase event and application.

How to use sc_connection_new

sc_connection_new(“new_conn_mysql”, $arr_conn);

1st parameter: the connection name. If a connection physically exists with the same name, this macro will have no effect. Physically created connections are stronger, sc_connection_edit should be used to change an existing connection.
2nd parameter: array of items. Mandatory to have all indexes except persistent and encoding that are optional
The array can have the following indexes:
arr_conn[‘drive’] – See the full list of drives below. .
$arr_conn[‘persistent’] – Valor “Y” ou “N”

List of drivers (see descriptions in the connection interface according to the database): access, ado_access, odbc, db2, db2_odbc, odbc_db2, odbc_db2v6, firebird, borland_ibase, ibase, firebird, pdo_informix, informix, informix72, maxsql, ado_mssql, pdo_sqlsrv, mssqlnative, odbc_mssql, mssql, pdo_mysql, mysqlt, mysql, oci805, odbc_oracle, oci8, oci8po, oracle, postgres7, pdo_pgsql, postgres64, postgres, pdosqlite, sqlite, sybase


Tutorial example

1 – onValidate Event

The login system is a control application Scriptcase (app_Login), with the following code snippet in your ONVALIDATE event:

2 – onRecord Event

Below we see the code used in the query of employees in onRecord event:

Reminding that onRecord event will be executed once for each row in the query load.


Do you want to see more examples using Scriptcase? Click on this LINK and check all our online examples.

By ,

December 9, 2015


You might also like…

12 IT Trends to Keep an Eye on in 2023

The year 2023 has already started in full swing bringing news and projecting trends for the web dev...

Low-code: it’s the future, not a passing trend

Low-code tools enable professionals to develop fast, efficient, and precise systems. Low-code ha...

What’s new in PHP 8.1

In this article, we will talk a little about the new features, changes, and improvements coming wit...

You might also like…

Get new posts, resources, offers and more each week.

We will use the information you provide to update you about our Newsletter and Special Offers. You can unsubscribe any time you want by clinck in a link in the footer of any email you receive from us, or by contacting us at Learn more about our Privacy Police.