一般错误:使用sqlite在PDO中锁定了5个数据库

时间:2016-02-05 11:59:07

标签: php mysql sqlite pdo

我被困住了,我不知道为什么我会收到这个错误。我的选择查询工作正常并给我结果,当我尝试upadte它给我

  

SQLSTATE [HY000]:常规错误:5数据库已锁定

更新查询的打印值及其直接在mysqlite中工作

UPDATE settings SET ViewMode = 5,ZoomAmount = 1,PixelRatio = 1 WHERE idFile = 3

我也提到了这个链接但没有发生

Sqlite3, SQLSTATE[HY000]: General error: 5 database is locked

这是我的代码

ini_set('max_execution_time', 300);
try {
    /*     * *************************************
     * Create databases and                *
     * open connections                    *
     * ************************************ */

    // Create (connect to) SQLite database in file
    $file_db = new PDO('sqlite:/home/guest/.kodi/userdata/Database/MyVideos93.db');
    // Set errormode to exceptions
    $file_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    /*     * ************************************
     * Play with databases and tables      *
     * ************************************ */
    // pattern for 3D
    $pattern = "([-. _](3D|sbs|HSBS|tab|HTAB))i";
    // Select idFile,strFilenamedata from file db files table 
    $result = $file_db->query('SELECT idFile,strFilename FROM files');
    /* Begin a transaction, turning off autocommit */

    foreach ($result as $data) {
        // condition to check 3D movie 
        if (!empty($data['strFilename']) && !empty($data['idFile'])) {
            if (preg_match($pattern, $data['strFilename'])) {
                $id = $data['idFile'];
                // Prepare Update statement to MyVideos93 file db
                $file_db->beginTransaction();
                $update = "UPDATE settings SET ViewMode = :ViewMode,ZoomAmount = :ZoomAmount,PixelRatio = :PixelRatio  WHERE idFile = :idFile";
                $stmt = $file_db->prepare($update);
                if ($stmt === false) {
                    echo "\nPDO::errorInfo():\n";
                    print_r($file_db->errorInfo());
                }
                // Bind parameters to statement variables
                $stmt->bindParam(':ViewMode', 5, PDO::PARAM_INT);
                $stmt->bindParam(':ZoomAmount', 1, PDO::PARAM_INT);
                $stmt->bindParam(':PixelRatio', 1, PDO::PARAM_INT);
                $stmt->bindParam(':idFile', $id, PDO::PARAM_INT);
                $stmt->execute();
                sleep(1);
                $file_db->commit();
                $file_db->exec('UNLOCK settings');
            }
            /* Database connection is now back in autocommit mode */
        }
    }
} catch (PDOException $e) {
    // Print PDOException message
    echo $e->getMessage();
}
$file_db->close();
unset($file_db);

0 个答案:

没有答案