PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Newbie question on prepare and execute

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> Database
View previous topic :: View next topic  
Author Message
Blackmajik



Joined: 29 Feb 2008
Posts: 1

PostPosted: Fri Feb 29, 2008 10:48 pm    Post subject: Newbie question on prepare and execute Reply with quote

Code:
<?php
require_once 'pear/MDB2.php';
require_once 'pear/PEAR.php';

   class dbManager {
      private static $dsn = array(
         'phptype' => 'oci8',
         'username' => 'stuff',
         'password' => 'stuff',
         'hostspec' => 'localhost',
      );
      private static $dbh;
      
      public function __construct() {
         dbManager::$dbh =& MDB2::connect(dbManager::$dsn);
         if(PEAR::isError(dbManager::$dbh)) {
            die(dbManager::$dbh->getMessage());
         }
      }
      
      public function dbCreateAccount($username, $password) {
         $types = array('text','text');
         $sth = dbManager::$dbh->prepare('INSERT INTO users (username, password) VALUES (?, ?)', $types);
         $data = array("$username","$password");
         $rows = $sth->execute($data);
         if(PEAR::isError($rows)) {
            die($rows->getMessage());
         }
      }
      
      public function dbDisconnect() {
         dbManager::$dbh->disconnect();
      }
   }   
?>


I get the error MDB2 Error: not found. I was getting this error also when trying to make a connection to database but I fixed that. Now i get it when i use isError on rows. I'm not sure if its the prepare or the execute that is messing up. is this the correct way of using prepare and execute. I test the value of the variable $data throughout the function using echo and the values are always in there. If anyone has any debug techniques or know why this isn't working I thank you. I'm also beginning at php so if there is a better way to write this I would apprecite also.

Kyle[/quote]
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1011

PostPosted: Sat Mar 01, 2008 3:00 pm    Post subject: Reply with quote

You're getting this error because your require_once calls are wrong (simply 'MDB2.php' and 'PEAR.php' are correct; the latter isn't really needed BTW), and most likely because you haven't adjusted your include_path setting.

Using getDebugInfo() in addition to the getMessage() calls will give you more reasonable error messages with MDB2.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> Database All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement

'Actiemonitor' online projectmanagement software