Re: db connection php & mssql & win2k

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux