lundi 6 juillet 2015

get data from json and save in sqlite

i use php language to extraction data from mysql table and use json_encode to convert in json format

<?php
$hostname='localhost';
$username='xxxxxxxxx';
$password='xxxxxxxxx';
$response = array();
try {

    $dbh=new PDO("mysql:host=$hostname;dbname=dbtest",$username  ,$password);

    $response["allnews"] = array();

    /*** QUERY ****/
    $sql='SELECT * FROM test';

    $stmt=$dbh->query($sql);

    $objs = $stmt->fetchAll(PDO::FETCH_OBJ);

    foreach($objs as $object) {
        $news = array();        
        $news["id"]=$object->id;
        $news["Onvan"]=$object->title;
        $news["Matn"]=$object->text;

        array_push($response["allnews"], $news);
    }

    echo json_encode($response);

    /*** close connection ***/
    $dbh=null;

}catch(PDOException $e) {
 echo $e->getMessage();
}
?>

now how i can get this json data format and insert in my app myslite? i use DataBaseHelper to connect mysqlite tnx

Aucun commentaire:

Enregistrer un commentaire