My problem is, that I don't know if I should choice "Option 1" or "Option 2" in index.php
Can someone point me to the right direction?
Thank you very much!
Code: Select all
//Database class that handle all insert/update/delete/etc...
class Database {
function __construct { init the connection }
function connect('host','user','pass','database')
function insert()
function delet()
function disconnect()
etc...
}
index.php
//so, now I can gain access to database using the following function...
$db = new Database();
$db->insert(...);
//Here I am trying to build a function in index.php
//Option 1: pass $db into method
function doSomething($db) {
$db->getUserInfo()....
}
//Option 2: create new database object within the function.
function doSomething() {
$db = new Database();
$db->getUserInfo()....
unset($db);
}