简体   繁体   English

将数据从本地MySQL服务器加载到Phonegap应用程序中

[英]Loading Data from local MySQL server into Phonegap application

I'm trying to connect a MySQL server to my phonegap application. 我正在尝试将MySQL服务器连接到我的phonegap应用程序。 I currently have a localhost MySQL and Apache Server running on XAMPP. 我目前在XAMPP上运行localhost MySQL和Apache Server。 Here is my PHP script that I am using to call a simple SELECT statement on my server: 这是我用来在服务器上调用简单SELECT语句的PHP脚本:

<?php
$host="localhost";
$port=3306;
$socket="";
$user="root";
$password="";
$dbname="mydb";

$con = new mysqli($host, $user, $password, $dbname, $port, $socket)
    or die ('Could not connect to the database server' . mysqli_connect_error());

$sql = "SELECT * FROM users";
$result = $conn->query($sql);

$array = $result->fetch_row($result); 

echo json_encode($array);
mysqli_close($con);
?>

Next, I make an jQuery JSON call within my javascript in order to obtain the information and simply print it out on my page. 接下来,我在JavaScript中进行了jQuery JSON调用,以获取信息并将其简单地打印在页面上。

$.ajax({
        url: 'js/users.php',
        dataType: 'json',
        success: function(data){
            var id = data[0];              
            var fName = data[1];
            var lName = data[2];

            $('#output').html("<b>id: </b>"+id+"<b> first name: </b>"+fname+"<b> last name: </b>"+lname);
        },
        error: function(data){
            alert(JSON.stringify(data));
        }
    });

Yet whenever I attempt to run this code, the ajax call errors out and my browser returns a Status:200 and statusText:OK. 但是,每当我尝试运行此代码时,ajax调用都会出错,并且我的浏览器返回Status:200和statusText:OK。

I would really appreciate any help on this matter. 我真的很感谢在此问题上的任何帮助。 Thanks! 谢谢!

Thanks to @jcesarmobile, I was able to figure out my problem. 多亏@jcesarmobile,我才能够解决我的问题。 You cannot store your .php scripts within your project's directory. 您不能将.php脚本存储在项目目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Javascript未加载mysql数据phonegap - Javascript not loading mysql data phonegap Phonegap:使用来自外部服务器的数据填充本地数据库 - Phonegap: populate local database with data from external server 运行本地网络并更新在线数据服务器的PHP MySQL应用程序 - PHP MySQL Application Running Local Network and Update Data Online Server 将MySQL数据库从实时服务器MySQL数据恢复到本地服务器MySQL数据 - Recovering MySQL database from live server MySQL data to local server MySQL data 创建php文件以同步来自某些本地服务器的mysql数据 - Create php file to sync mysql data from some local server 通过 phonegap 应用程序从同一网络中的移动设备与本地服务器通信 - Communicate with local server from a mobile in the same network through a phonegap app 将数据从本地SQL Server同步到Internet上的MySQL服务器(实时服务器) - Sync data from local SQL Server to MySQL Server on Internet (live server) 在MySql中插入phonegap数据 - Inserting phonegap data in MySql 从其他CORS请求中保护我的phonegap应用程序的服务器代码 - Securing server code of my phonegap application from other CORS request 如何从本地服务器应用程序更新远程服务器应用程序 - How to update remote server application from local server application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM