私は PHP に精通していますが、PHP でオブジェクト指向のことを少し始めたばかりです。シングルトン データベース接続を作成したかったのですが、問題とエラーが発生しました。私が実行しているクエリは
$con = getConnection();
$stmt = $con->prepare("SELECT gene_name,jgi_protein_id FROM jgi_transcriptid_proteinid_match where our_protein_id = ?");
これがクラスのコードです。
class Connection
{
// Store the single instance of connection
private static $connection;
private function __construct()
{
$connection = new mysqli(HOSTNAME, DBUSER, PASSWORD, DBNAME);
if ($connection->connect_errno)
die("Failed to connect to MySQL: (" . $connection->connect_errno . ") " . $connection->connect_error);
}
public static function getInstance()
{
if (!self::$connection)
self::$connection = new Connection();
return self::$connection;
}
public function prepare($query)
{
$statement = $this->prepare($query);
return $statement;
}
}
データベースにはmysqliを使用しています。