1

PDO クラスでクエリを実行しようとしたところ、次のエラー メッセージが表示"There is no active transaction"されました。

これが私のコードです:

  public function runExQuery($sql) {
        $preparedQuery = $this->connect()->prepare($sql);
        $this->connect()->beginTransaction();
        $preparedQuery->execute();
        $this->connect()->commit();
}



private function connect() {
        return new PDO('mysql:host=' . $this->host . ';dbname=' . $this->database . '', $this->username, $this->password);
    }

このエラーの原因は何ですか? このタイプの質問の以前の投稿を調査しましたが、解決策は見つかりませんでした。

4

2 に答える 2