[TUT] How to make custom functions [PHP , MySQL]

Status
Not open for further replies.
Nov 23, 2010
307
2
Hello today i will show you how to make custom functions like $db->connect() (placing mysql_connect()), $db->query (placing mysql_query()) etc. Hope you understand me.

Okay watch and learn :
PHP:
<?php // starting
class MySQL // lets make the class. Class is going to complete whole custom function !
{ // starting class
function connect($host, $user, $pass) // that will complete $db variable so like that : $db->connect(THAT FUNCTION)
{ // starting
$host = "localhost"; 
$user = "root"; // MySQL user
$pass = "abc123"; // MySQL pass
mysql_query($host, $user, $pass); // So , we will write the current function for mysql connect only in the function
} // end *function*
} // end *class*
$db = new MySQL; // lets connect $db variable to class MySQL where the function connect() is there!
$db->connect($host, $user, $pass); // that will connect mysql same as it connects with mysql_connect($host, $user, $pass). So $db variable has been already connected to Class MySQL , now its going to complete the function "connect()".
?>

The same thing goes with other functions!

Thank you.
StronG

Credits to me - 100% for the tut

This is tested ONLY IN XAMPP so that might not work in other hosts
 

Kieren

The OGz
Aug 4, 2010
2,957
751
Thanks for the tutorial, but I wouldn't really call this a tutorial I mean you have just jotted a code down? you have not shown us what the codes are for, I don't have a clue on what you have just tried to show us.
 

Kryptos

prjRev.com
Jul 21, 2010
2,205
1,252
Thanks for the code, but please show why the code is for, not just //start class, etc.
I know you have commented all, but edit the post and cover everything please.
 

Deion

Posting Freak
Jul 3, 2010
1,273
300
Is this suppose to be something dealing with Xampp? Please give us some info.

OFT: Can you tell JasonOsborn I said Heya. Tell him i'm from T-Storm
 
Nov 23, 2010
307
2
Thanks for your feedback , i will edit the post now!

EDIT : post edited , i think now it's more detailed! (PHP code edited , read all line comments).

@Jack {
Yeah , this is tested only in XAMPP , might not work in other hosts!
}
 
Status
Not open for further replies.

Users who are viewing this thread

Top