Re: 29_12_2005 - examples needed

From: Date: Fri, 30 Dec 2005 22:18:47 +0000
Subject: Re: 29_12_2005 - examples needed
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-22394@lists.php.net to get a copy of this message
i am a junior php developer, and i have a simple question: i have pear installed serverwide on a shared hosting server. Path is /usr/local/bin/pear as usual. Can you give me some working sample of Pear first test page ( how to include the packege files, etc...)
If you have access to the command line, try executing: /usr/local/bin/pear list This will show you which PEAR packages are installed (and their version number) If the PEAR_Info package shows up in the list (or you don't have terminal access), create a page called pear_info.php with: -- snip -- <?php include 'PEAR/Info.php'; $pi = new PEAR_Info(); $pi->show(); ?> -- snip -- If it's installed, this will give you a nicely formatted page with further info about the installed packages, as well as some PEAR config stuff. If not, it'll just freak out because, well, it's not installed. As you can see from the above, you don't need to have the entire path to the PEAR files *if* that path is in the PHP include path. To check that, make another page (info.php) with: -- snip -- <?php phpinfo(); ?> -- snip -- This will show the include path (under "Configuration PHP Core"). But the PEAR packages *should* be in the path, otherwise, well, it'd be pretty dumb. So, let's say you want to use the DB package. Here's a file i use, "get_dbi.php", which i include into pages that require a database interface. Username & password are kept in the "constants.php" file. -- snip -- <?php require 'DB.php'; require_once "${_SERVER['DOCUMENT_ROOT']}/includes/php/constants.php"; // you might want to do this if some scripts refer to tables which // should only have an admin INSERTing or otherwise fiddling with them. // Just set $admin to TRUE before including this page into your admin // script. // DO NOT DO THIS UNLESS YOU'RE USING SAFE MODE // AND register_globals IS OFF! $db_user = isset($admin) ? DB_ADMIN_USER : DB_USER; $db_pass = isset($admin) ? DB_ADMIN_PASS : DB_PASS; // host & port left out to force a UNIX socket connection $dsn = array(
        'phptype'  => 'pgsql',
        'database' => DB_DATABASE,
        'username' => $db_user,
        'password' => $db_pass
); $dbi =& DB::connect($dsn, Array('debug' => 4)); if (DB::isError($dbi)) { die ($dbi->getMessage()); } ?> -- snip -- DB_DATABASE is simply the name of the database, the 'pgsql' says to use the postgres interface. From there, you're script can do stuff like; $result = $dbi->query('SELECT foo from bar'); You can download the manual from : http://pear.php.net/manual/ or just view it online. hth, brian

« previous php.pear.general (#22394) next »