Re: db connection php & mssql & win2k
| From: | jsWalter | Date: | Fri, 29 Aug 2003 07:00:29 +0000 |
| Subject: | Re: db connection php & mssql & win2k | ||
| References: | 1 | Groups: | php.db php.windows |
| Request: | Send a blank email to php-db+get-30211@lists.php.net to get a copy of this message | ||
This is what I use...
// Pull in DB PEAR Collection
require_once 'DB.php';
// What kind of database server are we connecting too?
$db_type = 'mysql';
// local connectivity data
$db_host = 'localhost';
$db_user = 'dbUsername
$db_pass = 'dbUserPW';
$db_name = 'dbName';
// Data Source Name: This is the universal connection string
$dsn = "$db_type://$db_host/$db_name";
// DB::connect will return a PEAR DB object on success
// or an PEAR DB Error object on error
$db = DB::connect($dsn);
// With DB::isError you can differentiate between an error or
// a valid connection.
if (DB::isError($db))
die ($db->getMessage());
// Build Query
$strSql = 'SELECT * ';
$strSql .= ' FROM tableName ';
$strSql .= ' WHERE feild_1 = x ';
// Query the db
$result = $db->query($strSql);
// Always check that $result is not an error
if (DB::isError($result))
die ($result->getMessage());
// close conection
$db->disconnect();
// Now you have the returned results in $results.
// Do as you will
Walter