PHP アプリケーションを MySQL に接続する最良の方法は何ですか。
これまでのところ、以下の接続クラスがありました。
class Connection{
private static $server = "127.0.0.1";
private static $catalog = "schemadb";
private static $username = "rootuser";
private static $password = "password";
public static $current = null;
public static function Open(){
self::$current = mysqli_init();
if(!self::$current){
die("Failed to initialize connection");
}
if(!self::$current->real_connect(self::$server,self::$username,self::$password,self::$catalog)){
die("Cannot connect to server");
}
return self::$current;
}
public static function Close(){
self::$current->close();
}
}
そしてまた私は持っています
abstract class abstractDAO
{
protected function getConnection()
{
$mysqli = new mysqli("127.0.0.1","rootuser","password","schemadb");
return $mysqli;
}
}
または、PHP アプリケーションを MySQL に接続するための他の最善の方法があるかどうか。アドバイスお願いします よろしくお願いします..