Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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.

Code:
<?php
    /************************
    * CLASS.SESSION.PHP
    * Handles user login.
    ************************/
    require_once("DB.php");

    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;
                $this->_authenticate();
            }
        }


        // 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.
Reply With Quote
  #2 (permalink)  
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
Default

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

Quote:
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,

Nik
http://www.bigaction.org/
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:06 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.