如何将intel xdk中的混合应用程序与mysql数据库连接?有什么好资源吗?

时间:2015-03-29 20:23:15

标签: intel-xdk

我一直在寻找将我的intel xdk应用程序与mysql数据库连接的示例,但我找不到任何东西。我已经阅读了这些信息http://qnimate.com/create-a-intel-xdk-app-with-php-and-mysql-backend/,但他们没有解释有关文件和信息来源的任何信息。 如果有人拥有良好的资源,对我来说将是一个很大的帮助。谢谢!

1 个答案:

答案 0 :(得分:1)

好的,我是怎么做的

    // php script. Make sure this file is in your www folder if you are using wamp 

    <?php
        $data = array(); // array to store data
        $con = mysql_connect('localhost','root','wtf'); // connection to database
    if(!$con){
        die('Error Occured ' . mysql_error());
    } // checking if connection was successfully 

    $sel_db = mysql_select_db('church',$con); // select database
    if(!$sel_db){
        die("Failed to select database". mysql_error());
    }
    // query 
    $query = "Select * from clist"; 
    $result_set = mysql_query($query,$con);
    if(!$result_set){
        die("Failed to Execute Query ". mysql_error());
    }

    while($re = mysql_fetch_array($result_set)){
     $data[] =$re; // store data in array
    }

    echo json_encode($data); // this will send the array to the ajax call
    mysql_close();
    ?>

   // in XDK


    function onAppReady()
    {
        if( navigator.splashscreen && navigator.splashscreen.hide )
        {
        // Cordova API detected
        navigator.splashscreen.show() ;
        }
     getServer(); 
    }

     // using ajax to communicate with the server
    function getServer(){
        $.get("http://localhost/others/server.php",function(data,status){
             if(status == 'success')
             {
                var result = new Array();
                result = JSON.parse(data); // getting the array from the php
                var i;
              // what your want to do with the data.
             }
        });
    }

//这对我有用