drb0901500211 2017-06-21 15:03
浏览 36

too long

I've posted a question a few days ago, but I'm not sure I exposed properly my problem, so I'd like to expose it in another way. I want to send the content of MySQL database into an IndexedDB database. I have this, on the PHP side:

$con = mysqli_connect("localhost", "root", $mypassword, $myDB);
if (!$con) {
    die("Connection failed: " . mysqli_error($con));
}

$sql = "SELECT * FROM table1";

$result = mysqli_query($con, $sql);

$to_encode = array();
while($row = mysqli_fetch_array($result)) {
    $to_encode[] = $row;
}

echo json_encode($to_encode);

mysqli_close($con);

and on the javascript side:

$.getJSON('./php/database.php', function(data) {
    $.each(data, function (key, value) {
            // Populate the IndexedDB database here     
    });
});

I'm pretty new to development and especially with IndexedDB so I have a hard time to understand the process. I'm not even sure if it's possible to do what I want. Can somebody help please ?

  • 写回答

1条回答 默认 最新

  • douqianni4080 2017-06-22 06:42
    关注

    Without knowing anything about your database, is hard to give you a code that "just works".

    I suggest you take a look at the following example which shows you how to use the native IndexedDB API.

    Also, I suggest you (if you want to make it easier) to use a library to manage IndexedDB. For example Dexie.

    Just remember that first, you have to create a Schema which is the representation of your data (in mysql, the structure of the table) then once your schema is created, you can start adding data to the IndexedDB.

    I hope it helps

    评论

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch