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[‘server’]
$arr_conn[‘user’]
$arr_conn[‘password’]
$arr_conn[‘database’]
$arr_conn[‘persistent’] – The value “Y” or “N”
$arr_conn[‘encoding’]

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[‘user’]
$arr_conn[‘password’]
$arr_conn[‘database’]
$arr_conn[‘persistent’] – Valor “Y” ou “N”
$arr_conn[‘encoding’]

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

a

You might also like…

AI-Driven Software Development: The Role of ChatGPT

In the rapidly evolving world of technology, artificial intelligence (AI) is playing an increasingl...

Low-Code: The Key to Accessible Digital Transformation

Digital transformation is imperative for companies wishing to remain competitive in the current era...

Low-code: Simplifying Development Without Sacrificing Quality

In today's agile and competitive world, productivity is crucial for the success of any business. Th...

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 sales@scriptcase.net. Learn more about our Privacy Police.