Angularjs an introductory tutorial on SQL examples _angularjs

Source: Internet
Author: User
Tags chr mysql code php and mysql

Angularjs SQL

The code in the previous section can also be used to read data from the database.

Get data from MySQL using PHP

Angularjs instance

 <! DOCTYPE html>  
 

Run Result:

Alfreds Futterkiste Germany
Ana Trujillo Emparedados y helados Mexico
Antonio Moreno Taquería Mexico
Around the Horn UK
B ' s Beverages UK
Berglunds Snabbköp Sweden
Blauer Delikatessen Germany
Blondel père et fils France
Bólido Comidas Preparadas Spain
Bon app ' France
Bottom-dollar Marketse Canada
Cactus Comidas para Llevar Argentina
Centro Comercial Moctezuma Mexico
Chop-suey Chinese Switzerland
Comércio Mineiro Brazil

Execute SQL fetch data in asp.net

Angularjs instance

 <! DOCTYPE html> 

Run Result:

Alfreds Futterkiste Germany
Berglunds Snabbköp Sweden
Centro Comercial Moctezuma Mexico
Ernst Handel Austria
Fissa Fabrica Inter. Salchichas S.A. Spain
Galería del Gastrónomo Spain
Island Trading UK
Königlich Essen Germany
Laughing Bacchus Wine Cellars Canada
Magazzini Alimentari Riuniti Italy
North/south UK
Paris spécialités France
Rattlesnake Canyon Grocery USA
Simons Bistro Denmark
The Big Cheese USA
Vaffeljernet Denmark
Wolski Zajazd Poland

Service-side code

The following list of service-side code types is listed below:

Use PHP and MySQL. Returns JSON.

Use PHP and MS Access. Returns JSON.

Use ASP.net, VB, and MS Access. Returns JSON.

Use ASP.net, Razor, and SQL Lite. Returns JSON.

Cross-domain HTTP request

Cross-domain HTTP requests are required if you need to obtain data from different servers (different domain names).
Cross-domain requests are very common on Web pages. Many web pages from different servers uploaded into CSS, pictures, JS scripts and so on.
In modern browsers, for data security, all requests are strictly restricted to the same domain name, and if you need to invoke data from different sites, you need to solve them across domains.
The following PHP code runs using a Web site for cross-domain access.

Header ("Access-control-allow-origin: *");

More Cross-domain Access solutions refer to the best solution for PHP Ajax cross-domain problems.

1. PHP and MYSQL code examples

<?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 (MYSQLI_ASSOC)) {
  if ($outp!= "") {$outp. = ",";}
  $outp. = ' {' Name ': '. $rs ["CompanyName"]. '",';
  $outp. = ' City ': '  . $rs ["City"]    . '",';
  $outp. = ' Country ': "'. $rs ["Country"]   . '"}'; 
}
$OUTP = ' {Records ': ['. $outp. ']} ';
$conn->close ();

Echo ($OUTP);
? >

2. PHP and MS Access code instances

<?php
Header ("Access-control-allow-origin: *");
Header ("Content-type:application/json; Charset=iso-8859-1 ");

$conn = new COM ("ADODB. Connection ");
$conn->open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=northwind.mdb");

$rs = $conn->execute ("Select CompanyName, City, Country from Customers");

$OUTP = "";
while (! $rs->eof) {
  if ($outp!= "") {$outp. = ",";}
  $outp. = ' {' Name ': '. $rs ["CompanyName"]. '",';
  $outp. = ' City ': '  . $rs ["City"]    . '",';
  $outp. = ' Country ': "'. $rs ["Country"]   . '"}'; 
  $rs->movenext ();
}
$OUTP = ' {Records ': ['. $outp. ']} ';

$conn->close ();

Echo ($OUTP);
? >

3. ASP.net, VB and MS Access code examples

<%@ Import namespace= "System.IO"%> <%@ Import namespace= "System.Data"%> <%@ import namespace= " System.Data.OleDb "%> <% response.appendheader (" Access-control-allow-origin "," * ") Response.appendheader (" Content-type "," Application/json ") Dim conn As OleDbConnection Dim objadapter As OleDbDataAdapter Dim objtable As DataTabl E Dim Objrow As DataRow Dim objdataset As New DataSet () Dim outp Dim c Conn = New OleDbConnection ("Provider=microsoft.jet". Oledb.4.0;data Source=northwind.mdb ") Objadapter = New OleDbDataAdapter (" Select CompanyName, City, Country from Customers ", conn) Objadapter.fill (Objdataset," myTable ") objtable=objdataset.tables (" myTable ") OUTP =" "c = Chr for  Each x in Objtable.rows if OUTP <> "" Then Outp = OUTP & ", OUTP = outp &" {"& C &" Name "& C  & ":" & C & X ("CompanyName") & C & "," OUTP = OUTP & C & "City" & C & ":" & C & X ("City") & C & "," OUTP = OUTP &   C & "Country" & C & ": & C & X (" Country ") & C &"} "next outp =" {"& C &" Recor DS "& C &": ["& Outp &"]} "Response.Write (OUTP) Conn.close%>

4. ASP.net, VB Razor and SQL Lite code instance

@{
response.appendheader ("Access-control-allow-origin", "*")
Response.appendheader ("Content-type", " Application/json ")
var db = Database.open (" Northwind ");
var query = db. Query ("Select CompanyName, City, Country from Customers");
var outp = ""
var c = chr (a)
}
@foreach (var row in query)
{
if outp <> "then Outp = Outp +" , "
OUTP = outp +" {"+ C +" Name "  + C +": "+ C + @row. CompanyName + C + ","
outp = outp +    C + "city"  + C + ":" + C + @row. City    + C + ","
outp = outp +    C + "Country" + C + ":" + C + @row. Country   + C + "}"
}
outp = "{" + C + "records" + C + ": [+ OUTP +]}"
@outp

The above is ANGULARJS SQL data collation, follow-up continue to add, hope to help learn friends.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.