Re: DB stuff

From: Date: Tue, 07 Nov 2000 17:51:40 +0000
Subject: Re: DB stuff
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-24121@lists.php.net to get a copy of this message
PHP 4 comes with a database abstraction layer. You would use it like this: <? require_once 'DB'; $db = DB::connect('odbc://rasmus:pw@host/my_db'); $stmt = $db->prepare('select * from my_table'); $result = $db->execute($stmt); while($row = $db->fetchrow($result)) { while(list($key, $value) = each($row)) { echo "$field: $value<br>\n"; } } $db->disconnect(); ?> To change to a different database type the only thing you need to do is change the 'odbc' work in the DB::connect() call. You can of course read that database connection identifier string from anywhere you like and thereby configure your database access with a one-liner in any file you like. -Rasmus On Tue, 7 Nov 2000, Voitenko, Denis wrote: > I am wondering why wouldn't PHP support database connectivity like most > application servers do, e.g. something like a data source in JRun or > WebLogic where database connectivity is made DB server independent and all > the DB connectivity is configured in the guts of PHP? >

« previous php.general (#24121) next »