Jump to content

mr cracker

Members
  • Posts

    14
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

mr cracker's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for your reply. You are right, i didn't have an active connection, i tried your way and it works great and more effectively , i will use it from now on, but it's still not clear for me why do i have to return $con. (I know i must do it because i don't have an active connection but i don't get why, i don't know what $con is equal to or why is it important) So the way i'm seeing this is that without returning $con like this: class Connect { public static function con() { $con=mysql_connect("localhost","root","");// Connects to DB??? mysql_query("SET NAMES 'utf8'"); // Sets charset to UTF8 mysql_select_db("blog"); // Selects the DB } } And when running this: mysql_query($somequery,Connect::con());// Entire method con() is run? or is it just passing the returned value if any? whatever that is Wouldn't php run all 3 lines inside the method/function con() and start a new connection when the the first line is run? with no need to return anything. Thanks for your time.
  2. Hello all. I'm learning Object oriented php and found this simple piece of code online but i don't understand why the variable $con must be returned: class Connect { public static function con() { $con=mysql_connect("localhost","root","");// Connects to DB??? mysql_query("SET NAMES 'utf8'"); // Sets charset to UTF8 mysql_select_db("blog"); // Selects the DB return $con; // Don't know why $con must be returned, but it wont work without this. } } $con is later used in the script like this from another class to run a Query: mysql_query($somequery,Connect::con()); Thanks for your help.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.