Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

435
Vistas
Randomly get Error SQLSTATE[HY000] [14] unable to open database file - PHP PDO

This error appears randomly. I'm able to write and read the database file, but sometimes doesn't work, even with the same request.

I tried to test just one connection (to avoid multiple, thinking that could be the problem), and also randomly fails.

I checked the permissions of the file(windows), and all in order (if not I wouldn't be able to write the file)

This is the code to connect to database:

class Con{

    private $pdo;

    public function conex($db){

        try{

            // $pdo = $this->pdo;

            if ($this->pdo == null){

                sleep(0.1);
                $this->pdo = new PDO("sqlite:../../content/engine/" . $db,"","",array(
                    PDO::ATTR_PERSISTENT => true
                ));

                $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);      

            } 

            return $this->pdo;


        }catch(PDOException $e){

            die( $e->getMessage());

        } finally{

            $this->pdo = null;

        }
    }
}

class Q_General extends Con{

    protected $db;

    public function __construct($db){

        if ($this->db == null){

            $this->db = $this->conex($db);
        }
        
    } 

    public function get_query($sql){

        $query = $this->db->prepare($sql);
        $query->execute();

        $res = $query->fetchAll();
        $query->closeCursor();

        return $res;

    }
}

I do the request with ajax, so I can control the number and order of request and setup a queue for every request with the purpose of avoid write or read at the same time.

Any clue what can I be doing wrong?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda