Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
| Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 7th, 2003, 08:39 PM
Registered User
Join Date: Jul 2003
Location: Gilbert, AZ, USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to TreacherousDog Send a message via AIM to TreacherousDog Send a message via MSN to TreacherousDog Send a message via Yahoo to TreacherousDog
Default Using PEAR DB and Classes.

PEAR DB normally works fine for me but I'm trying to write a simple dummie class to test how it works within a class. I'm currently reading PHP mySQL Website Programing: Problem - Design - Solution from Wrox so that's where I'm learning most of this stuff.. Any way let me show you the code first.

    * Handles user login.

    class session {
        var $_strUserName;
        var $_strUserPass;
        var $_objConn;
        var $_objMail;

        // Class constructor...
        function session($name=' ',$pass=' ') {
            $this->_objConn =& DB::connect(DSN);

            if($_strUserName == ' ') {
                // Ensures a username was submitted...
                $this->_error("No user name was specified.");
                return FALSE;
            } else {
                $this->_strUserName = $name;
                $this->_strUserPass = $pass;

        // Authenticates the user...
        function _authenticate() {
            $sql = "SELECT admin_id,admin_pass FROM administrators WHERE admin_name=" . $this->_strUserName;
            echo $sql;    
            $objRS = $this->_objConn->query($sql);
            $objRow = $objRS->fetchRow(DB_FETCHMODE_ASSOC);

            if($objRS->numRows() < 1) {
                $this->_error("The user name you entered does not exist.");
                return FALSE;
            } elseif($objRS['admin_pass'] != $this->_strUserPass) {
                $this->_error("The password you entered is incorrect.");
                return FALSE;
            } else {
                echo "<p><strong>CONGRATULATIONS!</strong><br/>You have successfully logged into the site as: " . $this->_strUserName . "</p>";

        // Generates an error...
        function _error($strMessage) {
            echo "<p><strong class=\"error\">ERROR you could no be logged:</strong><br>";
            echo $strMessage;
I know for a fact that the Pear object is working up to the point fetchRow is called becuase when I echo $objRS I get the response 'Object' as output. But for some reason the page generates a fatal error saying the function fetchrow is undefined... does anyone know what I can do?

- Jim J.
Old July 8th, 2003, 01:02 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts

Are you sure it's working? Read the manual:

quote:[i]From http://pear.php.net/manual/en/packag...ntro-query.php[i]
On failure you get a DB_Error object, check it with DB::isError(). On succes you get DB_OK or when you set a SELECT-statment a DB_Result object.
so echo $objRS doesn't tell you anything useful. It tells you that $objRS is an object -- to assume it's a valid DBResult object is a really poor assumption.

Take care,


Similar Threads
Thread Thread Starter Forum Replies Last Post
PEAR DB Connection failure bxh Beginning PHP 0 October 6th, 2005 10:25 PM
Anybody else learning to HATE pear::DB? biot023 BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 2 March 15th, 2005 04:58 AM
PEAR::Auth and PEAR::Auth_HTTP Ceriwaen Beginning PHP 1 February 18th, 2005 04:36 PM
pear db::connect turing PHP Databases 1 September 15th, 2004 05:22 PM
PEAR::DB Using Problem ruhin Beginning PHP 5 June 4th, 2004 12:50 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.