1.使用PHP从MySQL中读取数据:

<div ng-app="myApp" ng-controller="customersCtrl" >

<table>

  <tr ng-repeat="x in names" >

    <td>{{x.Names}}</td>

    <td>{{x.Country}</td>

  </tr>

</table>

</div>

<script>

var app=angular.module('myApp',[]);

app.controller('customersCtrl',function($scope,$http){

  $http.get(http://www.runoob.com/angularjs/data/Customers_MySQL.php)

  .success(function(response){$scope.names=response.records});

});

</script>

2.服务器端代码:

**使用PHP和MySQL,返回JSON;

**使用PHP和MS Access,返回JSON;

**使用ASP.NET,VB,及MS Access,返回JSON;

**使用ASP.NET,Razor(Razor 不是编程语言。它是服务器端标记语言。)及SQL Lite,返回JSON;

**Razor 是一种允许您向网页中嵌入基于服务器的代码(Visual Basic 和 C#)的标记语法。

当网页被写入浏览器时,基于服务器的代码能够创建动态内容。在网页加载时,服务器在向浏览器返回页面之前,会执行页面内的基于服务器代码。由于是在服务器上运行,这种代码能执行复杂的任务,比如访问数据库。

Razor 基于 ASP.NET,它为 web 应用程序的创建而设计。

**SQLite是一个嵌入式SQL数据库引擎,与其它大多数SQL数据库不同的是,SQLite没有独立的服务进程。它的设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它,它占用资源非常的低,在嵌入式设备中,可能只需要几百K的内存就够了。

3.跨域HTTP请求:如果你需要从不同的服务器(不同的域名)上获取数据就需要使用跨域HTTP请求;

**跨域请求在网页上非常常见,很多网页从不同服务器上载入CSS,图片,JS脚本等;

**PHP Ajax跨域问题最佳解决方案:通过设置Access-Control-Allow-Origin来实现跨域:

(1)允许单个域名访问:指定客户端的域名为(http://client.runoob.com)跨域访问,则只需在请求的域名(http://server.runoob.com/server.php)文件头部添加以下代码:

header('Access-Control-Allow-Origin:http://client.runoob.com')

(2)允许多个域名访问:指定多个域名(http://client1.runoob.com,http://client2.runoob.com等)跨域访问,则只需在(http://server.runoob.com/server.php)文件头部添加如下代码:

$origin=isset($_SERVER['HTTP_ORIGIN'])? $_SERVER['HTTP_ORIGIN'] : ' ';

$allow_origin=array(

  'http://client1.runoob.com',

  'http://client2.runoob.com'

);

if(in_array($origin,$allow_origin)){

  header('Access-Control-Allow-Origin:'.$origin);

}

(3)允许所有域名访问:允许所有域名访问只需在http:.//server.runoob.com/server.php文件头部添加如下内容:

herder('Access-Control-Allow-Origin:*');

4.PHP和MySQL代码示例:

<?php

header("Access-Control-Allow-Origin:*");

header("Content-Type:application/json;charset=UTF-8");

$conn=new mysqli("myServer","myUser","myPassword","Northwind");

$result=$conn->query("SELECT CompanyName,City,Country FROM Customers");

$outp="";

while($rs=$result->fetch_array(MYSQL_ASSOC)){

  if($outp!=""){$outp .=",";}

  $outp .='{   "Name":    " '.$rs["CompanyName"] .'  " , ' ;

   $outp .='     "City"  :    " ' .$rs["City"]                .'  " ,  ';

  $outp .='     "Cpuntry": " '.$rs["Country"]           .' "

}';

}

$outp='{  "records"  :  ['.$outp'.]   }';

$conn->close();

echo($outp);

?>

AngularJS学习之SQL的更多相关文章

  1. Angularjs学习---官方phonecat实例学习angularjs step0 step1

    接下来一系列的文章都是学习https://docs.angularjs.org/tutorial的笔记,主要学习的angular-phonecat项目的实现,来介绍angularjs的使用. 1.下载 ...

  2. angularJS学习资源最全汇总

    基础 官方: http://docs.angularjs.org angularjs官方网站已被墙,可看 http://www.ngnice.com/: 官方zip下载包 https://github ...

  3. 我的AngularJS 学习之旅

    我的AngularJS 学习之旅 基础篇 1.Angular的 起源 2.比较Web 页面实现的几种方式 3.一些基本术语 4.Angular与其他框架的兼容性 5.总结 6.综合实例   很早之前就 ...

  4. 推荐10个很棒的AngularJS学习指南

    AngularJS 是非常棒的JS框架,能够创建功能强大,动态功能的Web app.AngularJS自2009发布以来,已经广泛应用于Web 开发中.但是对想要学习Angular JS 的人而言,只 ...

  5. Angularjs学习---ubuntu12.04中karma安装配置中常见的问题总结

    karma启动时出现了很多问题: 1.安装karma前提条件 安装karma首先要安装nodejs,npm然后才可以安装karma.nodejs,npm的安装过程可以参考文章:Angularjs学习- ...

  6. AngularJs学习总结-了解基本特性(-)

    现在的前端项目中基本上都会用到angularjs框架,之前并不了解这个框架,也是因为最近接手的项目,所以打算好好的学习下它.之前都是搞pc端,现在接手的是移动端的项目,移动端UI框架用的是ionic+ ...

  7. [整理]AngularJS学习资源

    https://angular.io/docs/js/latest/(2.0官方网站) http://www.linuxidc.com/Linux/2014-05/102139.htm(Angular ...

  8. AngularJs学习笔记--Forms

    原版地址:http://code.angularjs.org/1.0.2/docs/guide/forms 控件(input.select.textarea)是用户输入数据的一种方式.Form(表单) ...

  9. AngularJs学习笔记--expression

    原版地址:http://code.angularjs.org/1.0.2/docs/guide/expression 表达式(Expressions)是类Javascript的代码片段,通常放置在绑定 ...

随机推荐

  1. monitor system

    #!/bin/bash # #Snapshot_Stats - produces a report for system stats # This report will mail to root. ...

  2. windows下ftp命令大全

    FTP Server: home4u.at.china.com User: yepanghuang Password: abc123 打开Windows的开始菜单,执行“运行”命令,在对话框中输入ft ...

  3. 【leetcode】Text Justification(hard) ☆

    Given an array of words and a length L, format the text such that each line has exactly L characters ...

  4. Spring面向切面编程(AOP)方式二

    使用注解进行实现:减少xml文件的配置. 1 建立切面类 不需要实现任何特定接口,按照需要自己定义通知. package org.guangsoft.utils; import java.util.D ...

  5. September 30th 2016 Week 40th Friday

    Elegance is the only beauty that never fades. 优雅是唯一不会褪色的美. Even the most beautiful apperance may los ...

  6. nVivo highlight code中的文本

    要highlight nvivo中的code一颗在如图highlight中下拉菜单选择,如coding for all nodes,所有的有归属code的文本都会被高亮.如果选择coding for ...

  7. 1.4 算法 - algorithm

    1)概述 2)示例 //algorithm find演示 #include <vector> #include <algorithm> #include <iostrea ...

  8. Android Programming: Pushing the Limits -- Chapter 7:Android IPC -- AIDL

    服务端: 最终项目结构: 这个项目中,我们将用到自定义类CustomData作为服务端与客户端传递的数据. Step 1:创建CustomData类 package com.ldb.android.e ...

  9. 清空mysql的历史记录

    # vi ~/.mysql_history show tables; show databases; 清空里面的内容,并不用退出当前shell,就可以清除历史命令!!

  10. DOM – (w3school)1.DOM 方法 + 2.DOM属性 + 3.DOM 元素

      1.DOM 方法   一些 DOM 对象方法 这里提供一些您将在本教程中学到的常用方法: 方法 描述 getElementById() 返回带有指定 ID 的元素. getElementsByTa ...