ODBC
From RadPHP XE2 Documentation
ODBC is an interface through which you can access several database management systems using the same SQL language. ODBC accomplishes DBMS by using a driver, a translation layer between the application and the DBMS.
Note: To set up a database with ODBC is easy, but performance will always be worse than native access, so use native access if possible.
Contents |
Initial Setup
DSN Setup
- Open ODBC Data Sources:
- On Windows 7 or Vista, click Start, search for ODBC Data Sources and click it.
- On Windows XP, go to Start > Control Panel > Administrative Tools > Data Sources (ODBC).
- On the User DSN tab, click Add….
- On the new dialog, select your desired ODBC driver from the list and click Finish.
- A setup wizard for your ODBC driver will pop up. Follow its instructions to setup the driver with the proper data. Once you are done, the connection will be added to User Data Sources list.
- Back to the User DNS tab, click OK.
Usage
To connect to a database using ODBC in RadPHP, you first need to setup a Data Source Name.
Database Setup
Now, on your RPCL Application, add a Database component, and set it up with the information below:
- DriverName: odbc.
- Host: The name you gave to the ODBC Data Source before.
There is no need to fill the DatabaseName property, but do not forget to fill UserName and UserPassword also with the proper values, that is, those of an user with access to the database.
Work With PHP
// Set Connection Data $database = 'database'; // Data Source Name. $user = 'user'; // Username to access the database, if any. $password = 'password'; // Password for the user, if any. // Establish Connection $connection = odbc_connect($database, $user, $password); // Perform a Query $query = 'SELECT * FROM table'; $result = podbc_exec($connection, $query); while($row = (odbc_fetch_array($result))) { var_dump($row).'<br />'; }