I am currently working on a Joomla website on a Unix server. There are no users connected at the moment because I'm the only one who can access it (so no heavy traffic).
During testing, I proceed to make several MySQL INSERT
s or UPDATE
s on a table in my DB. When the Ajax is triggered, data is sent to a php file which connects using jFactory::getDBO()
, executes a query, and returns a success response.
Everything works perfectly, until I run several tests in rapid succession. After a while, even though I still get a success response in Ajax, there are no affected rows (not on this table, not on any other table).
It's like MySQL blocks all the connections (and yet I don't get any error message). I tried opening a different browser and magically the queries execute perfectly/successfully from there. I think I also noticed that it starts working again when I close the original browser and open it again.
What could the issue be? And how can I solve it? I was looking for a way to close the getDBO()
connections after each query, but all I found online is that on a Unix server, this type of connection is automatically closed after each query.
This is the Ajax Call:
jQuery.ajax({
type:"POST",
url:"/models/ajax.php",
data:{"sid":sid, "steid":steid, "answer":answer, "function_to_call":21},
dataType: "json",
cache: false,
success: function(data){
console.log(JSON.stringify(data));
},
error: function(msg){
console.log(JSON.stringify(msg));
}
});
This is how the insert/updates are performed:
if(isset($step) && !empty($step) && trim($step) != ""){
$sql = "UPDATE #__thamatho_student_mistakes SET
date_mistake='".$date."', answer='".addslashes($answer)."' WHERE
student=".$userid." and step=".$steid;
$db->setQuery($sql);
$db->query();
}else{
$sql = "Insert into #__thamatho_student_mistakes (`student`,
`step`, `answer`, `date_mistake`) values (".$userid.", ".$steid.",
'".addslashes($answer)."', '".$date."')";
$db->setQuery($sql);
$db->query();
}