Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: OOP Problem

  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    97
    Thanks
    10
    Thanked 0 Times in 0 Posts

    OOP Problem

    Well trying to do simple querys with oop, heres my script

    getting this error

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\register_oop\database.php on line 24
    PHP Code:
    <?php

    class Database {
        var 
    $conn;
        var 
    $dbs;
        
        public function 
    connect() {
            
    $this->conn mysql_connect('localhost','root','');
            
    $this->dbs mysql_select_db('test',$this->conn);
        }
        
        public function 
    query($sql) {
            
    $res mysql_query($sql);
            
    $this->conf_query($res);
        }
        
        public function 
    conf_query($res) {
            if(!
    $res) {
                die(
    "Database query error "mysql_error());
            }
        }
        
        public function 
    fetch_array($result_set) {
            return 
    mysql_fetch_array($result_set);
        }
        
        
        public function 
    num_rows($result_set) {
            return 
    mysql_num_rows($result_set);
        }
    }

    $database = new Database();
    $database->connect();

    ?>
    heres my query

    PHP Code:
    <?php
    require_once('database.php');

    $sql "SELECT * FROM test WHERE id = 1";
    $result_set $database->query($sql);
    $found_user $database->fetch_array($result_set);



    ?>

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,858
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    You need to return the result set,
    PHP Code:
    public function query($sql) {
            
    $res mysql_query($sql);
            
    $this->conf_query($res);
            return(
    $res);
        } 
    for your
    PHP Code:
    $result_set $database->query($sql); 
    statement.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    Kev0121 (03-28-2009)

  • #3
    New Coder
    Join Date
    Mar 2009
    Posts
    97
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Thanks alot!!!

    Kevin


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •