When you use the ODBC API in PHP, Python script, Java, C, C++ or any programming language, you can connect without using a DSN by means of a connection string.
Example using Python:
import pyodbc
conn = pyodbc.connect(‘Driver={4D ODBC Driver 64-bit} ;Server=187.145.45.23 ;UID=Designer ;PWD=123456’)
curs = conn.cursor()
curs.execute('select (id,name) from table_1')
curs.fetchone()
curs.close()
conn.close()
This example uses the following keywords:
- Driver: set to use the 4D ODBC Driver
- Server: set to use the 4D Server on the machine with the IP address= "187.145.45.23"; no port is specified so the default (19812) will be used.
- UID and PWD: set to connect as "Designer" using "123456" as password.
Keywords are not case sensitive and can be used in any order, with the exception of "Driver", which must come first if it is used. Whenever you do not specify a keyword, its default value is used.
A connection string can also use a DSN. When you create a DSN using the 4D Configuration window, it saves the settings in the registry or in the odbc.ini file using the same keywords.
For example, if you use the connection string:
conn=pyodbc.connect('DSN=My_4D_DSN')
... it is the equivalent of a connection string using all the same values set in the 'My_4D_DSN' DSN.
A description of all the keywords used in a connection string, or when configuring a DSN, is shown below.