mysql connection & resource types

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

mysql connection & resource types

Post by Luke »

Code: Select all

$link_id = @mysql_query($sql);
What would be the benefit of storing this in $link_id... what can you do with that variable??
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

Code: Select all

if (!$link)
{
   echo "uh oh. this did not work..damn..";
}
else
{
   echo "yay.it worked.";
}
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Why not just do this...

Code: Select all

if(mysql_query($sql)){
    //yay it worked
}
else{
    //damn I suck
}
I am wondering what the benefit is of doing it the other way as opposed to this.
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

Code: Select all

function mybooleanfunc () {

  if (rand() > 0.5) return true;
  else return false;
}

/************************/

if (mybooleanfunc()) echo "yes";
else echo "no";

//is equivalent to:

$foo = mybooleanfunc();

if ($foo) echo "yes";
else echo "no";
No difference. Just look at what's happening in the code.
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

Without a resource link indentifier, you will have no way of discovering stats for your query. i.e. Issue a select query then tell me how many rows are in that select query?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

redmonkey wrote:Without a resource link indentifier, you will have no way of discovering stats for your query. i.e. Issue a select query then tell me how many rows are in that select query?
Thank you.
Post Reply