I want to use PEAR:😃B to abstract my db layer. I want to keep all the config values (dbname, dbuser, dbpass) and the DB::connect($dsn) line in an include file that loads when the web page is opened. How do I set up my config file so that my 'News.inc' class functions simply call db->query($sql) to execute a query? Right now, my page_open.inc looks like this:
...
$dbtype = "mysql";
$dbuser = "username";
$dbpass = "PaSsWoRd";
$dbhost = "localhost";
$dbname = "mydb";
require_once("DB.php");
$db = DB::connect( "$dbtype://$dbuser:$dbpass@$dbhost/$dbname" );
...
Here's the flow:
1. newspage.php is called by the user, prepended by the included page_open.inc.
2.user requests to view a newsclip by $id, which calls news->view($id), which should return the article.
the result now is that i get an error saying: "Fatal error: Call to undefined function: query() in /u/r/rednaxel/lib/News.inc on line 34". Line 34 is: $newsResult = $db->query($sql);
I really want to keep my News.inc class as abstract as possible by not committing any of its code to one database, so i'd like to stick to PEAR (also b/c I hear PHPLIB is merging into PEAR) and keep db settings in a seperate include file.
Big thanks.