Answer the question
In order to leave comments, you need to log in
Transferring data from MySQL to WebSQL?
Hi all.
There are two tablets, one on the server, the other in the browser.
They work, everything is added to them, if for one task.
But, for some reason, it is not possible to insert json tasks from the server into the client.
Almost everything turns out (data comes) but they don’t want to be inserted into WebSQL. And I don’t understand what the problem is :-(
I took this code from some other script, where it seems to work.
Examples
sync.php
$result = mysql_query("SELECT name, age FROM user") or die(mysql_error());
$rows = mysql_fetch_all($result);
echo json_encode(array('success' => 1, 'count' => count($rows), 'items' => $rows));
function mysql_fetch_all($result) {
$all = array();
while ($all[] = mysql_fetch_assoc($result)) {
} if (empty($all[count($all) - 1]))
unset($all[count($all) - 1]);
return $all;
}
$.post("sync.php", {
//
}).done(function(data) {
console.log(data); //<-- ДАННЫЕ ПРИХОДЯТ И ЗАПИСЫВАЮТСЯ В КОНСОЛЬ
for (var i=0; i < data.count; i++) {
baza.init.db.transaction(function(tx){
tx.executeSql("INSERT INTO user (name, age) VALUES (?,?)", [data.items[i].name, data.items[i].age]);
});
}
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question