I do have an SQL Table looking like:
uid price timestamp account
and I want to write to this table via php. I do have this code:
function test($uid,$price){
if($price>1){
test2($uid,$price,2);
else($price<1){
test2($uid,$price,1);
}
}
function test2($uid,$price,$accountNumber){
$time = time();
$conn = new PDO('sqlite:sql.db');
$stmt = $conn -> prepare("INSERT INTO table (uid,price,timestamp,account) VALUES (:uid,:price,:timestamp,:accountNumber)");
$stmt -> bindParam(':uid', $uid);
$stmt -> bindParam(':price', $price);
$stmt -> bindParam(':timestamp', $time);
$stmt -> bindParam(':accountNumber', $accountNumber);
$stmt -> execute();
$conn = NULL;
}
This request takes a huge amount of time and the serveer doesn't respond to anything during that time. However. When I don't call the function and instead replace test2($uid,$price,2);
with
$time = time();
$conn = new PDO('sqlite:sql.db');
$stmt = $conn -> prepare("INSERT INTO table (uid,price,timestamp,account) VALUES (:uid,:price,:timestamp,2)");
$stmt -> bindParam(':uid', $uid);
$stmt -> bindParam(':price', $price);
$stmt -> bindParam(':timestamp', $time);
$stmt -> execute();
$conn = NULL;
The code runs way faster. The request doesn't take around 1 minute, but a few ms to process. Is there anything I am doing wrong while calling the test2 function?