StrongFaith II
Member
- 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 :
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
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