Re: Examples for PHP4 DB class? Anyone?
| From: | Matt McClanahan | Date: | Tue, 30 May 2000 18:51:49 +0000 |
| Subject: | Re: Examples for PHP4 DB class? Anyone? | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-103@lists.php.net to get a copy of this message | ||
On Tue, 30 May 2000, Adam W. Dace wrote:
> Hello everyone!
>
> I'm not as familiar with PHP's OO extensions as I should be, and I'd
> love to start using the new pear/DB class that's include in PHP 4.0.0.
> Unfortunately I can't for the life of me figure it out! I get no
> errors, no warnings, just a script that plain stops processing.
Well, a very crude example would be
require 'DB.php';
require 'DB/mysql.php';
$db = new DB_mysql();
// Pear is using a DSN format that can be applied to any method of data
// storage. See the documentation for the parseDSN method in DB.php for
// the various formats that a DSN can use.
$con = $db->connect('mysql://user:pass@host/database');
if( $con )
{
echo 'There was an error: ' . $db->errorcode_map[$con];
return;
}
$res = $db->simpleQuery('select * from table');
while( ($row = $db->fetchRow($res)) )
echo "<li>$row[0] $row[1]";
$db->freeResult($res);
$db->disconnect();
That's using the simpleQuery method. There's also the normal query
method, which returns a DB_result object rather than a QL result
identifier.
HTH,
Matt