Home > Blockchain >  Unable to open sqlite DB file from js axios.get request
Unable to open sqlite DB file from js axios.get request

Time:05-13

Unable to open sqlite DB file from js axios.get request:(console.log outputs exception message). The request may call my PHP controller to select data from DB and return it json-encoded.

An another side, PHP contoller makes it's job good: screenshot

In this way i trying send an axios request from Vue form: screenshot or code:

Vue.createApp({
    data: () => ({
        processors:'',
        memory:'',
        drives:'',
        motherboards:'',
        cases:'',
    }),
    methods:{
        fetchProcessors:function (){
            axios.get('/src/controllers/getProcessors.php').then(
                (response) => {
                    this.processors = response.data;
                    console.log(response);
                });
        }
    },
    created:function (){
        console.log('vue is ok');
        this.fetchProcessors();
    }
}).mount(".js-form");

PHP controller code:

<?php

require_once __DIR__ . '/../../vendor/autoload.php';
use Doctrine\DBAL;

$connectionParams = [
    'url' => 'sqlite3:///db/calc_db.sqlite3'
];


try {
    $conn = DBAL\DriverManager::getConnection($connectionParams);
    $data = $conn->fetchAllAssociative('SELECT name, cost FROM processors');
    echo json_encode($data, JSON_THROW_ON_ERROR);
} catch (Exception $e) {
    echo $e->getMessage();
}

I've tryed to:

  • give chmod 777 to whole project
  • make request with phpstorm tools (returns same exception message)
  • send const json from controller - it wotks good, proofs that js request and php controller working together normaly, trouble is in connection to DB file (i think so)
  • use sqlite driver instead of sqlite3

full stack trace

CodePudding user response:

The problem was in 'path' param: i've launched my script from project root (working directory), so relative path to my DB builds correctly.

On web-server WD was a path, that i gave in request (controllers dir), so relative path to my DB builds incorrectly.

I've replaced path param like this and everything is OK:

$connectionParams = [
    'path' => dirname(__DIR__, 2) . '/db/calc_db.sqlite3',
    'driver' => 'pdo_sqlite'
];
  • Related