Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-07-2010, 01:07 PM   PM User | #1
FIA2008
New to the CF scene

 
Join Date: Jun 2009
Location: Utrecht, Holland
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
FIA2008 is an unknown quantity at this point
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?
FIA2008 is offline   Reply With Quote
Old 09-07-2010, 03:07 PM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,046
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
I don't understand the problem ...

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

What is the purpose of the function?
mlseim is offline   Reply With Quote
Old 09-07-2010, 03:17 PM   PM User | #3
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,882
Thanks: 9
Thanked 291 Times in 287 Posts
Dormilich is on a distinguished road
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
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Old 09-07-2010, 10:09 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,661
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
class, function, mysql_query, php, variable

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:50 AM.


Advertisement
Log in to turn off these ads.