vaylain
vaylain

Reputation: 57

PHP PDO SQLITE - error "attempt to write a readonly database"

I have setup an sqlite database file on my Windows Server 2012 R2 box.

both the database file and the directory it resides in have full control Access (modify, read & execute, read, and write) and I am able to query data from my database with out issue but I am unable to write to the database.

exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 8 attempt to write a readonly database' in C:\inetpub\wwwroot\newWebsite\dbConnection.php:43 Stack trace: #0 C:\inetpub\wwwroot\newWebsite\dbConnection.php(43): PDOStatement->execute() #1 {main}

What do I need to do to ensure that my php scripts will have full read/write access to the database file?

Here is my test statement:

    function addUser($uname,$pass,$color) {
        include("dbConnection.php");

        try {
            $sql = "INSERT INTO tbl_users (col_uname, col_pass, col_color) VALUES (?,?,?)";
            $results = $db->prepare($sql);
            $results->bindParam(1,$uname,PDO::PARAM_STR);
            $results->bindParam(2,$pass,PDO::PARAM_STR);
            $results->bindParam(3,$color,PDO::PARAM_STR);
            $results->execute();
        } catch (Exception $e) {
            echo $e . " :Unable to add user";
            exit;
        }
    }

The dbConnection.php file looks like this:

    try {
        $db = new PDO("sqlite:".__DIR__."/users.db");
        $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        echo '<br>Connection successful.';
    } catch(Exception $e) {
        echo $e->getMessage();
        echo '<br>Connection to the database was unsuccessful. Please check that path to the database file exists.';
        die();
    }

Sincerely, Vaylain

Upvotes: 0

Views: 2817

Answers (1)

vaylain
vaylain

Reputation: 57

For anyone following this post...

I was able to resolve my issue by assigning both the dbConnections.php and the folder it resides in, with the USERS group to include write access.

Upvotes: -1

Related Questions