PEAR Packages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPEAR Packages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old July 20th, 2005, 02:27 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 25
need PEAR DB help

Hi,

I need help on using PEAR and PEAR DB. Please help me out.

------------------------------
First of all, these are the steps I have already taken.

I installed PEAR on my website via ftp (with go-pear.php that is on pear.php.net) because Network Solutions, (my host) does not allow me to access php.ini

I am 80% sure that PEAR DB came with go-pear. I see DB.php and DB folder in my /htdocs/libs/PEAR directory as I chose.

I read examples from a book and wrote DBManager class and did some queries.

***** Note: My site uses PHP 4, not PHP 5. So, I wrote my classes without __CONSTRUCTOR, private and public keywords
------------------------------

Okay, so here is my problem.

My website is going to be online store and well, the departments aren't displaying! (This is driving me nutz.)

I get no errors and none of my database connection error messages are printed on the website so I assume DB connected fine.


-----------------------------

Here is some of my code that is relevant to this. (I use the SMARTY template engine which I had no problems with so far)

// config.inc.php
php Code:
Original - php Code
  1.  
  2. <?php       
  3. // SITE_ROOT contains the full path to the tshirtshop folder
  4. define("SITE_ROOT", dirname(dirname(__FILE__)));
  5. // Settings needed to configure the Smarty template engine
  6. define("SMARTY_DIR", SITE_ROOT."/libs/smarty/");
  7. define("TEMPLATE_DIR", SITE_ROOT."/templates");
  8. define("COMPILE_DIR", SITE_ROOT."/templates_c");
  9. define("CONFIG_DIR", SITE_ROOT."/configs");
  10.  
  11. if ((substr(strtoupper(PHP_OS), 0, 3)) == "WIN")
  12.   define("PATH_SEPARATOR", ";");
  13. else     
  14.   define("PATH_SEPARATOR", ":");
  15. ini_set('include_path', SITE_ROOT . '/libs/PEAR' .
  16.          PATH_SEPARATOR . ini_get('include_path'));
  17. // database login info
  18. define("USE_PERSISTENT_CONNECTIONS", "true");
  19. define("DB_SERVER", "214.298.196.65");
  20. define("DB_USERNAME", "scrooge");
  21. define("DB_PASSWORD", "bah");
  22. define("DB_DATABASE", "humbug");
  23. define("MYSQL_CONNECTION_STRING", "mysql://" . DB_USERNAME . ":" .
  24.         DB_PASSWORD . "@" . DB_SERVER . "/" . DB_DATABASE);
  25.  
  26.  
  27. ?>           


// database.php
php Code:
Original - php Code
  1.  
  2. <?php     
  3.  
  4. // reference the PEAR DB library
  5. require_once SITE_ROOT.'/libs/PEAR/DB.php';
  6. // class providing generic data access functionality
  7. class DbManager
  8. {         
  9.   var $db
  10.  
  11.   // open database connection in the constructor 
  12.   function DbManager($connectionString)         
  13.   {                                               
  14.     $this->db = DB::connect($connectionString,   
  15.                                 USE_PERSISTENT_CONNECTIONS);
  16.     if (DB::isError($this->db))                   
  17.        trigger_error($this->db->getMessage(), E_USER_ERROR);
  18.     $this->db->setFetchMode(DB_FETCHMODE_ASSOC)
  19.   }     
  20.   // close the connection                         
  21.   function DbDisconnect()                 
  22.   {                                               
  23.     $this->db->disconnect();                     
  24.   }   
  25.   function DbQuery($queryString)           
  26.   {                                               
  27.     $result = $this->db->query($queryString);     
  28.     if (DB::isError($result))                     
  29.        trigger_error($result->getMessage(), E_USER_ERROR);
  30.     return $result;                               
  31.   } 
  32.   // wrapper class for PEAR DB's getAll() method 
  33.   function DbGetAll($queryString)         
  34.   {                                               
  35.     $result = $this->db->getAll($queryString);   
  36.     if (DB::isError($result))                     
  37.        trigger_error($result->getMessage(), E_USER_ERROR);
  38.     return $result;                               
  39.   }   
  40.   // wrapper class for PEAR DB's getRow() method
  41.   function DbGetRow($queryString)
  42.   {     
  43.     $result = $this->db->getRow($queryString);
  44.     if (DB::isError($result))
  45.        trigger_error($result->getMessage(), E_USER_ERROR);
  46.     return $result;
  47.   }     
  48.   // wrapper class for PEAR DB's getOne() method
  49.   function DbGetOne($queryString)
  50.   {     
  51.     $result = $this->db->getOne($queryString);
  52.     if (DB::isError($result))
  53.        trigger_error($result->getMessage(), E_USER_ERROR);
  54.     return $result;
  55.   }     
  56.                      
  57.                        
  58. }
  59.                                                  
  60. ?>                   



Reply With Quote
  #2  
Old July 20th, 2005, 02:30 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 25
RE: need PEAR DB help

// department_list.tpl
// using SMARYY template engine

{* departments_list.tpl *}
{load_departments_list assign="departments_list"}
{* start departments list *}
<table border="0" cellpadding="0" cellspacing="1" width="200">
<tr>
<td class="DepartmentListHead"> Choose a Department </td>
</tr>
<tr>
<td class="DepartmentListContent">
{* loop through the list of departments *}
{section name=i loop=$departments_list->mDepartments}
{* verify if the department is selected
to decide what CSS style to use *}
{if ($departments_list->mSelectedDepartment ==
$departments_list->mDepartments[i].department_id)}
{assign var=class_d value="DepartmentSelected"}
{else}
{assign var=class_d value="DepartmentUnselected"}
{/if}
{* generate a link for a new department in the list *}
<a class="{$class_d}"
href="{$departments_list->mDepartments[i].onclick}">
» {$departments_list->mDepartments[i].name}
</a>
<br/>
{/section}
</td>
</tr>
</table>
{* end departments list *}

Reply With Quote
  #3  
Old July 20th, 2005, 02:32 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 25
RE: need PEAR DB help

// do_catalog.php

php Code:
Original - php Code
  1.  
  2. <?php 
  3. // data tier class
  4. class DoCatalog
  5. {     
  6.   // class constructor
  7.   function DoCatalog()
  8.   {   
  9.     // get the global DbManager instance (created in app_top.php)
  10.     $this->dbManager = $GLOBALS['gDbManager'];
  11.   }   
  12.   // retrieves all departments
  13.   function GetDepartments()
  14.   {   
  15.     $query_string = "SELECT department_id, name FROM department";
  16.     $result = $this->dbManager->DbGetAll($query_string);
  17.     return $result;
  18.   }   
  19. } //end DoCatalog
  20. ?>     


// bo_catalog.php

php Code:
Original - php Code
  1. <?php                                             
  2. // reference the data tier                       
  3. require_once SITE_ROOT.'/data_objects/do_catalog.php';
  4. // business tier class for reading product catalog information
  5. class BoCatalog                                   
  6. {                                                                             
  7.   var $mDoCatalog;                           
  8.   // class constructor initializes the data tier object
  9.   function BoCatalog()
  10.   {   
  11.     $this->mDoCatalog = new DoCatalog();
  12.   }   
  13.   // retrieves all departments
  14.   function GetDepartments()
  15.   {   
  16.     $result = $this->mDoCatalog->GetDepartments();
  17.     return $result;
  18.   }   
  19. } //end BoCatalog
  20. ?>     

Reply With Quote
  #4  
Old July 20th, 2005, 02:33 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 25
RE: need PEAR DB help

// function.load_departments_list.php

php Code:
Original - php Code
  1.  
  2. <?php           
  3. // plugin functions inside plugin files must be named: smarty_type_name
  4. function smarty_function_load_departments_list($params, $smarty)
  5. {               
  6.   $departments_list = new DepartmentsList();
  7.   $departments_list->init();
  8.   // assign template variable
  9.   $smarty->assign($params['assign'], $departments_list);
  10. }               
  11. // Manages the departments list
  12. class DepartmentsList
  13. {               
  14.   /* public variables available in departments_list.tpl Smarty template */
  15.   var $mDepartments;                           
  16.   var $mSelectedDepartment;                   
  17.   /* private members */                           
  18.   var $mBoCatalog;                           
  19.   // constructor initializes business tier object
  20.   // and reads query string parameter             
  21.   function DepartmentsList()                         
  22.   {                                               
  23.     // creating the middle tier object           
  24.     $this->mBoCatalog = new BoCatalog();         
  25.     // if DepartmentID exists in the query string, we're visiting a department
  26.     if (isset($_GET['DepartmentID']))             
  27.        $this->mSelectedDepartment = (int)$_GET['DepartmentID'];
  28.     else                                         
  29.        $this->mSelectedDepartment = -1;           
  30.   }                                               
  31.   // calls business tier method to read departments list
  32.   // and create their links                       
  33.   function init()                                 
  34.   {                                               
  35.     // get the list of departments from the business tier
  36.     $this->mDepartments = $this->mBoCatalog->GetDepartments();
  37.     // create the department links               
  38.     for ($i = 0; $i < count($this->mDepartments); $i++)
  39.        $this->mDepartments[$i]['onclick'] = "index.php?DepartmentID=" .
  40.                                 $this->mDepartments[$i]['department_id'];
  41.   }                                               
  42. } //end class                                     
  43. ?>                                               
  44.  

Reply With Quote
  #5  
Old July 20th, 2005, 02:40 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 25
RE: need PEAR DB help

// index.tpl
// SMARTY template

php Code:
Original - php Code
  1. {* smarty *}                                                 
  2. {config_load file="site.conf"}                               
  3. <!DOCTYPE html                                               
  4. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"             
  5. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
  6. <html>                                                       
  7.   <head>                                                     
  8.     <title>{#sitetitle#}</title>     
  9.     <link href="tshirtshop.css" type="text/css" rel="stylesheet"/>                       
  10.   </head>                                                   
  11.   <body>                                                     
  12.     <table cellspacing="0" cellpadding="0" width="750" border="0">
  13.        <tr>                                                 
  14.          <td width="200" height="100%" valign="top">         
  15.            <table  width="100%" cellspacing="0" cellpadding="0">
  16.               <tr>                                           
  17.                 <td valign="top" height="100%">             
  18.                 <br/> 
  19.                 {include file="departments_list.tpl"}           
  20.                 </td>                                       
  21.               </tr>                                         
  22.            </table>                                         
  23.          </td>                                               
  24.          <td>&nbsp;&nbsp;&nbsp;</td>                         
  25.          <td valign="top" width="550"><br />                 
  26.            {include file="header.tpl"}                       
  27.            Place contents here                               
  28.          </td>                                               
  29.        </tr>                                                 
  30.     </table>                                                 
  31.   </body>                                                   
  32. </html>                 


that's all of the templates and php files that uses PEAR DB. Other files are not relevant

Please show me what I am doing wrong and why my queried-department list of my webaite are not showing up.

- John


Reply With Quote
  #6  
Old July 20th, 2005, 02:46 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 25
RE: need PEAR DB help

by the way, u might be wondering where header.tpl is. i do have it

this problem has to be an installation or algorithmic mistake. my syntax are all correct i believe

a lot of the code i got from a book i am reading

- John

Reply With Quote
  #7  
Old July 20th, 2005, 05:53 AM
lig's Avatar
lig lig is offline
"Forum Nazi"
Click here for more information.
 
Join Date: Apr 2007
Location: Jacksonville, Fl
Posts: 4,775 lig User rank is Private First Class (20 - 50 Reputation Level)lig User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 13 h 47 m 18 sec
Reputation Power: 7
RE: need PEAR DB help

This is more for my information -

Quick question - why did you make a wrapper class out of the DB class? All you are adding is another layer of abstraction with no (to me) added advantage.

Oh - I also didn't see any references. Without them you are copying the data not getting a reference.

Reply With Quote
  #8  
Old July 20th, 2005, 11:55 AM
johnny johnny is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: NJ, USA
Posts: 7 johnny User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: RE: need PEAR DB help

Quote:
This is more for my information -

Quick question - why did you make a wrapper class out of the DB class? All you are adding is another layer of abstraction with no (to me) added advantage.

Oh - I also didn't see any references. Without them you are copying the data not getting a reference.


Well, it contains the error-handling code so after writing DBManager Class, I don't need to bother with that detail ever again


I forgot to also show this. (I think this is the reference that you mean. I also have app_botton.php that simply closes the mysql

// app_top.php
php Code:
Original - php Code
  1. <?php                                                                                 
  2. // include utility files                                                               
  3. require_once 'config.inc.php';   
  4.  
  5. require_once 'setup_smarty.php'
  6. require_once 'database.php';                                 
  7. // global DbManager instance                                 
  8. $gDbManager = new DbManager(MYSQL_CONNECTION_STRING);                                                                                                                     
  9. ?>                   

Reply With Quote
  #9  
Old July 20th, 2005, 04:32 PM
johnny johnny is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: NJ, USA
Posts: 7 johnny User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: need PEAR DB help

what exactly did you mean by reference?

im not sure

Reply With Quote
  #10  
Old July 20th, 2005, 11:25 PM
lig's Avatar
lig lig is offline
"Forum Nazi"
Click here for more information.
 
Join Date: Apr 2007
Location: Jacksonville, Fl
Posts: 4,775 lig User rank is Private First Class (20 - 50 Reputation Level)lig User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 13 h 47 m 18 sec
Reputation Power: 7
RE: need PEAR DB help

http://www.php.net/manual/en/language.references.php

And you might also want to see here - http://www.php.net/manual/en/language.oop.php

I assume you are using php4

Reply With Quote
  #11  
Old July 20th, 2005, 11:58 PM
johnny johnny is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: NJ, USA
Posts: 7 johnny User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: need PEAR DB help

Yes, I am using php4

Ok, I have thoroughly read those pages but I don't see why it wouldn;t work without references

I am using $this operator

and it says on the site
"Note: There is no performance loss (since PHP 4 and up use reference counting) returning copies instead of references. On the contrary it is most often better to simply work with copies instead of references, because creating references takes some time where creating copies virtually takes no time (unless none of them is a large array or object and one of them gets changed and the other(s) one(s) subsequently, then it would be wise to use references to change them all concurrently). "




Reply With Quote
  #12  
Old July 21st, 2005, 12:53 AM
johnny johnny is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: NJ, USA
Posts: 7 johnny User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: need PEAR DB help

i made a dummy file testPEAR.php that doesn't use my DBManager class and just query a column

All it does is display Object on the screen

php Code:
Original - php Code
  1.  
  2. <?php
  3.     include_once('DB.php');
  4.     $db = DB::connect("mysql://hthth:kkyukyk@215.158.178.13/departments");
  5.    
  6.     if (DB::isError($db)) {
  7.         print $db->getMessage();
  8.         exit;
  9.     } else {
  10.    
  11.         $allnames = $db->getCol("SELECT name FROM departments;");
  12.         print $allnames . '<BR />';
  13.      
  14.     }
  15.  
  16.     $db->disconnect();
  17. ?>
  18.  



ok so what is going on?

Reply With Quote
  #13  
Old July 21st, 2005, 12:57 AM
johnny johnny is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: NJ, USA
Posts: 7 johnny User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: need PEAR DB help

why the heck is 'Object' being printed on the screen when i use PEAR's getCols() function?

Reply With Quote
  #14  
Old July 21st, 2005, 01:38 AM
johnny johnny is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: NJ, USA
Posts: 7 johnny User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: need PEAR DB help

wow, holy crap it's not recognizing a dam function in PEAR

...

Reply With Quote
  #15  
Old July 21st, 2005, 01:55 AM
johnny johnny is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: NJ, USA
Posts: 7 johnny User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: need PEAR DB help

it passed the db::isError test so it is connected but WHY ON EARTH IS NOT RECOGNIZING numCols, numRows, getCols,, getRows etc


Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPEAR Packages > need PEAR DB help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek