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 8 of 8
  1. #1
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    358
    Thanks
    19
    Thanked 2 Times in 2 Posts

    Question arcade_db->query not working

    Okay. trying to find out why the query isnt working, the database is loaded and functions are included.


    query I want to load. (just doesnt seem to work)
    PHP Code:
    $sql_query "SELECT * FROM games_info WHERE g_id = $g_id AND g_status = 1 LIMIT 1";
    $sql_result mysql_query($arcade_db->query($sql_query)); 
    in the config.php (connect DB)
    PHP Code:
     $arcade_db = new mysql
     
    $arcade_db->connect('IP''USER''PASS''DB'); 

    in the mysql.php (class)
    PHP Code:

    class mysql {
        
        var 
    $link=null;
            
        function 
    connect($host$user$pass$db) {
           
    $this->link mysql_connect($host$user$pass) or die("SQL Connection Error");
           
    mysql_select_db($db$this->link) or die("SQL Database Selection Error");
        }
      
        function 
    query($query) {
            
            
    $result mysql_query($query$this->link);
            
            if (!(
    $result)) {
                
    ob_end_clean();
                die(
    "SQL Error: ".mysql_error($this->link)."<br /> Query: $query<br />");
            }
        return 
    $result;
        }

    Thanks

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You're trying to query a query here: $sql_result = mysql_query($arcade_db->query($sql_query)); . Remove the outter mysql_query, you'll need to either use a custom iterator for fetching, or the equivilent database (mysql in this case) function for fetch.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,291
    Thanks
    13
    Thanked 345 Times in 341 Posts
    out of curiousity, why using this mysql class when you can use the MySQLi class?
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #4
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    358
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Fou-Lu View Post
    You're trying to query a query here: $sql_result = mysql_query($arcade_db->query($sql_query)); . Remove the outter mysql_query, you'll need to either use a custom iterator for fetching, or the equivilent database (mysql in this case) function for fetch.

    Thank you. I didn't even notice I was trying to double query.

  • #5
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    358
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Dormilich View Post
    out of curiousity, why using this mysql class when you can use the MySQLi class?

    Thats because I've tried out the mysqli and it never worked for me, I am thinking maybe its my clients server that doesn't allow that yet.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by sitNsmile View Post
    Thats because I've tried out the mysqli and it never worked for me, I am thinking maybe its my clients server that doesn't allow that yet.
    That is definitely possible. The custom MySQL class written here was also from an older version of php (notice the use of the var keyword for members instead of the public/private/protected scope of PHP5+). MySQLi interfacing itself requires PHP5+ AND MySQL 4.1.13+.
    Now, this likely was, and possibly still is the limiting factor for why the MySQLi is not in use. If I were you sitNsmile, I would actually look at interfacing everything on you're current class to match the definitions of the MySQLi class. This is a matter of simply renaming necessary functions (both in the class and in calls) and adding / removing / modifying necessary code to match the MySQLi method signatures. Level of work involved would be dependant on the size of you're project itself, but I can assure you (assuming you're using a local development environment in case you need to blow it away), this will actually be more search and replace than anything.
    What you gain: given the sufficient technology, an immediate drop from new MySQL(...); to new MySQLi(...); without needing to alter any other code.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #7
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    358
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Fou-Lu View Post
    That is definitely possible. The custom MySQL class written here was also from an older version of php (notice the use of the var keyword for members instead of the public/private/protected scope of PHP5+). MySQLi interfacing itself requires PHP5+ AND MySQL 4.1.13+.
    Now, this likely was, and possibly still is the limiting factor for why the MySQLi is not in use. If I were you sitNsmile, I would actually look at interfacing everything on you're current class to match the definitions of the MySQLi class. This is a matter of simply renaming necessary functions (both in the class and in calls) and adding / removing / modifying necessary code to match the MySQLi method signatures. Level of work involved would be dependant on the size of you're project itself, but I can assure you (assuming you're using a local development environment in case you need to blow it away), this will actually be more search and replace than anything.
    What you gain: given the sufficient technology, an immediate drop from new MySQL(...); to new MySQLi(...); without needing to alter any other code.

    Thank you. I will build a 2nd version calling it mysqli.php and test out both.

    But on a note, what are the advantages of having mysqli instead of mysql class?

  • #8
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,291
    Thanks
    13
    Thanked 345 Times in 341 Posts
    Quote Originally Posted by sitNsmile View Post
    But on a note, what are the advantages of having mysqli instead of mysql class?
    MySQLi is native PHP code (runs faster) and has a lot of useful methods, including
    - Prepared Statements
    - Transactions
    - Database Information
    - Query Information
    there’s nearly nothing about MySQL you can’t find out with MySQLi.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

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