使用IONIC获取MySQL数据
Get MySQL data with IONIC
我第一次尝试从MySQL表中获取一些数据。
我使用ionic, PHP和AngularJS来尝试它,但我的查询没有返回任何东西。当我第一次开发它时,我遵循本教程从bd获取数据。虽然,当我运行我的代码时,我的文件只是返回给我另一个文件的内容,除了包含我想要的所有内容的json文件。
基本上我有一个函数在我的应用程序控制器和我调用它(测试)在一个按钮。这个函数通过Angular向另一个文件发出$http请求。这个包含查询的文件调用另一个文件打开数据库连接,并通过Json返回数据。
但是我只是打开了第一个文件作为该过程的返回。有人能帮我吗?
app.js
// Ionic Starter App
// angular.module is a global place for creating, registering and
retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a
<body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
var secompApp = angular.module('starter', ['ionic', 'ngCordova'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory
bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
secompApp.controller("SeCompController", function($scope,
$cordovaBarcodeScanner, $http){
$scope.scanBarcode = function(){
$cordovaBarcodeScanner.scan().then(function(imageData){
//imageData = barcode content
//TRANSFORMAR ALERT POR FUNÇÃO QUE ENVIA imageData(DADO LIDO) PARA O BD
alert(imageData.text);
console.log("format: " + imageData.format);
}, function(error){
console.log("Ocorreu um erro, tente novamente. Erro:" + error);
});
}
$scope.getMinicursos = function(){
$http.get("ajax/getMinicursos.php").success(function(data){
$scope.minicursos = data;
alert(data);
});
}
});
getMinicursos()。php
<?php
require_once '../includes/config.php'; // The mysql database connection script
if(isset($_GET['name'])){
$task = $_GET['name'];
$status = "0";
$created = time();
$query="SELECT * from course";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
$result = $mysqli->affected_rows;
echo $json_response = json_encode($result);
}
?>
config。
<?php
$servername = "localhost";
$username = "abc";
$password = "123";
try {
$conn = new PDO("mysql:host=$servername;dbname=test", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
?>
我的错误是在Ionic localhost中使用PHP,我没有注意到没有在服务器中运行PHP,并安装了它来正确"编译"我的文件并获取我正在寻找的数据。
如果您要返回整个PHP文件,而不是由服务器处理,则应确保服务器中安装了PHP,甚至是本地/localhost。
相关文章:
- 使用jquery将mysql数据获取到新的表行中
- 从MySQL数据库中获取输入数据需要两次页面刷新
- 在php和mysql中选择选项.一旦选择了选项,就列出我的sql数据库数据
- 更新从Mysql查询检索到的数据?Node.js节点mysql
- 单击鼠标,用MySQL数据填充html表单输入字段
- HTML表单将数据POST到MySQL
- 如何在没有额外空格的情况下从MySQL中检索字符数据
- 我的地图数据's不会使用php存储在mysql数据库中
- 将Laravel5.0中的谷歌图表与mysql数据库中的数据集成
- 将动态feild数据存储到jquery-mobile和php-mysql中的数据库中
- 数组数据排序类似mysql查询
- PHP MySQL 在一个页面和一个查询中插入具有多行的数据
- 使用 mysql 数据创建条形图
- 使用 Ajax 将 PHP 嵌入到 JavaScript 中,以便将 MySQL 数据存储在 JavaScript 对象
- 如何从javascript访问MySql数据库的数据
- 如何在 JavaScript 函数中使用 MySQL 数据库数据
- HTML按钮(onlick)在将数据发送到MySQL表时不起作用
- 用 MySql 数据填充 JavaScript 数组
- 有没有一种方法可以通过列类型/属性来格式化MySQL单元格数据
- 如何创建视图和获取数据mysql PHP javascript