<?php
include_once('DB.php');
$conninfo = "mysql://username:password@localhost/phpdb";
$db = DB::connect($conninfo);
if (DB::isError($db)) {
print $db->getMessage();
exit;
} else {
$result = $db->query("SELECT * FROM people;");
while ($result->fetchInto($row, DB_FETCHMODE_ASSOC)) {
extract($row);
print "$Name: $NumVisits\n";
}
$result->free();
}
$db->disconnect();
?>
Notice how PEAR:😃B uses a URL-like connection string, often called a Data Source Name (DSN), to entirely define its connection. This is the same method as seen in JDBC, so it should be familiar to Java developers already. The string can be broken down like this:
mysql:// Connection type
Username Your username
Password Your password
@ The address of your server
/phpdb The database name to use
The connection type is for what kind of server to which you intend on connecting. You can choose from the following list:
fbsql FrontBase
ibase InterBase
ifx Informix
msql Mini SQL
mssql Microsoft SQL Server
mysql MySQL
oci8 Oracle 7/8/8i
odbc ODBC (Open Database Connectivity)
pgsql PostgreSQL
sqlite SQLite
sybase SyBase
http://hudzilla.org/phpwiki/index.php?title=Introducing_PEAR:😃B
So you change mysql:// to mssql:// and that's it...