1

How can I perform a SQLite3 exec at the same time in PHP? I have this code (by example):

$bd = new SQLite3("database.db");
$bd->busyTimeout(5000);
$bd->exec("INSERT into 'foo' ('data') values ('bar')");
$bd->close();
unset($bd);

And it works, but the real problem is when I connect another computer to my server and I made the insert at the same time (really, I press the key that trigger the code at the same time in both computers) and it show an error "database is locked".

I know that with the pragma WAL the database works in multithread, but it even show the error. Thank you a lot! and sorry for my bad english.

4

1 回答 1

0

问题是使用数据库锁定,而不是像orsqlite3那样的行或列锁定。如果您想同时做两件事,请尝试使用mysqlpostgresql。在你将不得不创建数据库。您的代码将如下所示:mysqlpostgresqlmysql

$servername = "localhost";
$username = "username";
$password = "password";

try {
    $conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully"; 
    }
catch(PDOException $e)
    {
    echo "Connection failed: " . $e->getMessage();
    }

$count = $conn->exec("INSERT into 'foo' ('data') values ('bar')");
$conn = null // close connection
于 2015-10-22T19:58:02.323 回答