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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Location
    Utrecht, Holland
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    mysql_query makes variable disappear

    I have the following code:
    PHP Code:
    class database{
        function 
    config($part){
            
    $sql    mysql_query("SELECT ".$part." FROM configuration");
            if(
    $sql){
                echo 
    'ok';
            }
            else{
                echo 
    'no sql';
            }
        }

    This doens't work for some reason...
    As soon as I remove the command mysql_query(); it says that $sql exists...
    Does anyone has a solution for this problem?

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,468
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    I don't understand the problem ...

    So, as it is right now, it displays "no sql"?

    What is the purpose of the function?

  • #3
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,244
    Thanks
    12
    Thanked 340 Times in 336 Posts
    there’s no database connection, thus the return value of mysql_query() is false.

    if you want to explore OOP, then you should consider using PDO or MySQLi (OOP style) instead of the outdated mysql extension
    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
    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
    We'll need confirmation on the run from the op, add an or die(mysql_error()); to end the mysql query call.
    Interestingly enough, the actual resource is global.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Tags for this Thread

    Posting Permissions

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