| ADOdb Library for PHP Manual | ||
|---|---|---|
| Prev | Data Source Names |
Next |
We now support connecting using PEAR style DSN's. A DSN is a connection string of the form:
$dsn = "$driver://$username:$password@$hostname/$databasename";
You pass the DSN to the static class function DB::Connect, or directly to ADONewConnection(). An example:
<?php
$username = 'root';
$password = '';
$hostname = 'localhost';
$databasename = 'xphplens';
$driver = 'mysql';
$dsn = "$driver://$username:$password@$hostname/$databasename";;
$db =& ADONewConnection($dsn);
# DB::Connect($dsn); also works if you include 'adodb/adodb-pear.inc.php' at the top
$rs = $db->Execute('select firstname,lastname from adoxyz');
$cnt = 0;
while ($arr = $rs->FetchRow()) {
print_r($arr); print "<br>";
}
?>
More info and connection examples on the DSN format.
| Prev | Home | Next |
| Using Custom Error Handlers and PEAR_Error | Up | Caching of Recordsets |