Hello smarty pants people
I've got a question to ask. what is the best way to connect to a database using oop in php?
this is how i've done it. but is there a better way?
[php]
class MyClass {
const host = 'localhost';
const user = 'username';
const pass = 'password';
const db = 'database';
public static function connect(){
$con = mysql_connect(self::host,self::user,self::pass)or die(mysql_error());
$db = mysql_select_db(self::db,$con)or die(mysql_error());
}
}
$obj = new MyClass();
$obj->connect();
[/php]
You could always use the PHP5 MySQLI object.
Yer Good point i've only realy bean looking into MySQL Function
[url=http://php.net/manual/en/book.pdo.php]PHP Data Objects[/url]
[QUOTE=Wyzard;17756547][url=http://php.net/manual/en/book.pdo.php]PHP Data Objects[/url][/QUOTE]
I second that! PDO is awesome
Sorry, you need to Log In to post a reply to this thread.