connect to a database
dblink = DbConnect(provider,connectionString) dblink = DbConnect(connectionStruct)
A string - name of the provider. Must have one of the following values : "MYSQL" - MySQL, "PSQL" - PostgreSQL (versions 7.3 and above), "OCI" - Oracle Call Interface Driver, "SQLITE" - SQLite version 3, "TDS" - Sybase Adaptive Server, "IBASE" - Borland InterBase, "ODBC" - Open Database Connectivity (ODBC) - Microsoft SQL Server and other ODBC-compliant databases, "DB2" - IBM DB2 (version 7.1 and above)
Connection string, specific for provider, given as first argument at function call. See connection string formats for providers you use.
A scilab struct, containing connection parameters. Must at least field 'provider', which has the same values as 'provider' - parameter. Other provider-independent values of struct: host, port, database, user, password. But format if this can also vary depending on provider. For Firebird(InterBase) provider and SQLite providers you must five the name of file of the database, for server-oriented databases you must specify the name of the database on server. Examples of connection struct for different providers:
For Firebird:
connStr = struct ('provider', 'IBASE', 'database', 'D:\TEST.FDB', 'user', 'SYSDBA', 'password', 'masterkey') | ![]() | ![]() |
For SQLite:
connStr = struct ('provider', 'SQLITE', 'database', 'addressbook') | ![]() | ![]() |
For PostgreSQL:
connStr = struct ('provider', 'QPSQL', 'user', 'postgres', 'database', 'test') | ![]() | ![]() |
For ODBC:
For local Access database
connStr = struct('provider', 'ODBC', 'database', 'DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=Dbt.mdb') | ![]() | ![]() |
For remote connection to MSSQL database:
connStr = struct('provider', 'ODBC', 'database', 'DRIVER={SQL Native Client};SERVER=11.111.11.111,33301;DATABASE=remote_db', 'user', 'remote_user', 'password', 'remote_user_password') | ![]() | ![]() |
For trusted connection to local MSSQL database:
connStr = struct('provider', 'ODBC', 'database', 'DRIVER={SQL Native Client};SERVER=localhost;DATABASE=local_database; Trusted_Connection=yes') | ![]() | ![]() |
For MySQL:
connStr2 = struct ('provider', 'MYSQL', 'database', 'mytest', 'user', 'root', 'password', 'admin') | ![]() | ![]() |
For OCI (Oracle):
connStr2 = struct ('provider', 'OCI', 'database', 'XE', 'user', 'HR', 'password', 'hr') | ![]() | ![]() |
For ODBC:
SQL_ATTR_ACCESS_MODE
SQL_ATTR_LOGIN_TIMEOUT
SQL_ATTR_CONNECTION_TIMEOUT
SQL_ATTR_CURRENT_CATALOG
SQL_ATTR_METADATA_ID
SQL_ATTR_PACKET_SIZE
SQL_ATTR_TRACEFILE
SQL_ATTR_TRACE
SQL_ATTR_CONNECTION_POOLING
SQL_ATTR_ODBC_VERSION
For MySQL:
CLIENT_COMPRESS
CLIENT_FOUND_ROWS
CLIENT_IGNORE_SPACE
CLIENT_SSL
CLIENT_ODBC
CLIENT_NO_SCHEMA
CLIENT_INTERACTIVE
UNIX_SOCKET
MYSQL_OPT_RECONNECT
For PostgreSQL:
connect_timeout
options
tty
requiressl
service
For DB2:
SQL_ATTR_ACCESS_MODE
SQL_ATTR_LOGIN_TIMEOUT
For OCI:
OCI_ATTR_PREFETCH_ROWS
OCI_ATTR_PREFETCH_MEMORY
For SQLite:
QSQLITE_BUSY_TIMEOUT
QSQLITE_OPEN_READONLY
QSQLITE_ENABLE_SHARED_CACHE
For Interbase:
ISC_DPB_LC_CTYPE
ISC_DPB_SQL_ROLE_NAME
DbConnect(...)
opens a connection to database and returns a pointer to connection object or results in an error if it is not possible to open a connection.
Last succesfull connection becomes default.
// Opens a “PostgreSQL” connection with a connexion string DbConnect("PSQL", .. "Server=127.0.0.1;Database=myDataBase;User Id=myUsername;Password=myPassword;"); | ![]() | ![]() |
// Opens a “PostgreSQL” connection with a structure connexionStruct = struct(); connexionStruct.provider = "postgresql"; connexionStruct.database = "myDataBase"; connexionStruct.hostname = "127.0.0.1" ; connexionStruct.use = "myUsername"; connexionStruct.password = "myPassword"; DbConnect(connexionStruct); | ![]() | ![]() |