# PHP ODBC Setup Guide

Guide to setting up php-odbc for connection to Registrar database. Example for RedHat EL 5.

Create file tds.datasource.template:

```
<br></br>[Registrar]<br></br>Driver  = FreeTDS<br></br>Description  = <span class="caps">UCLA</span> Registrar (<span class="caps">SRDB</span>)<br></br>Trace  = No<br></br>Server  = srdb.registrar.ucla.edu<br></br>Port  = 1433<br></br>
```

Create file tds.datasource.template:

```
<br></br>[FreeTDS] <br></br>Description     = v0.63 with protocol v8.0 <br></br>Driver          = /usr/lib/libtdsodbc.so<br></br>
```

*Make sure Driver points to an existing file.*

Run the following command:  
 sudo yum install php-odbc   
 sudo odbcinst -i -d -f tds.driver.template   
 odbcinst -i -s -f tds.datasource.template   
 sudo cp ~/.odbc.ini /etc/odbc.ini

Test the connection:

```
<br></br><? <br></br>$conn = odbc_connect(‘Registrar’, $username, $password); <br></br>$result = odbc_exec($conn, “<span class="caps">EXECUTE</span> CIS_facultyCourseStudentsGetAlpha2 ‘254049110’, ‘081’”); <br></br>?> <br></br>
```

Note on programming: do not nest odbc\_exec() calls! Make one call, copy records into array, odbc\_free\_result() it, and then move on. Second odbc\_exec() will fail otherwise.

More info on settings at [http://www.unixodbc.org/doc/FreeTDS.html](http://www.unixodbc.org/doc/FreeTDS.html)