675Chapter 36PEAR Database FunctionsOnce you have the values (Photography web hosting)

675Chapter 36PEAR Database FunctionsOnce you have the values available, stringing them together into a properly formatted DSN ispretty simple. The standard format looks like this: $dsn = $phptype://$username:$password@$hostspec/$database ; There are more obscure options available for use in defining DSNs. They re described indetail at http://pear.php.net/manual/en/package.database.db.intro-dsn.php. As always, we recommend storing database connection variables outside the Web tree forgreater security. ConnectionWhen you have a valid DSN, it s a simple matter to tell PEAR DB to establish a connection tothe database the DSN describes. The line of code you need looks like this: $db = DB::connect($dsn); If the connection attempt succeeds, everything s great $dbcontains an object representinga connection to the database, and you can run queries against that object (among other amus- ing and educational activities). Because you re a good programmer, though, you should allowfor errors. Here s how: if (DB::isError($db)) { die($db->getMessage()); } The isError()method returns true if the database object $dbin this case represents aconnectivity error, and false if not (meaning, if the connection succeeded). In this case, thecode aborts if the database connection wasn t successfully established. TipValid Database Identifiers for DSNsHere s a list of all the database management servers supported by PEAR DB, complete with thestrings you should use to identify them in DSNs. .FrontBase (fbsql) .InterBase (ibase) .Informix (ifx) .Mini SQL (msql) .Microsoft SQL Server (mssql) .MySQL (mysql) .Oracle 7/8/8i (oci8) .ODBC (odbc) .PostgreSQL (pgsql) .SyBase (Sybase)
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.

Leave a Reply