# Retrieving mysql data using json and php

**URL:** <https://forum.ionicframework.com/t/retrieving-mysql-data-using-json-and-php/5525>\
**Category:** ionic-v1\
**Created:** [June 11, 2014, 9:52pm UTC](https://forum.ionicframework.com/t/retrieving-mysql-data-using-json-and-php/5525 "2014-06-11T21:52:27Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ernie\_mac](https://avatars.discourse-cdn.com/v4/letter/e/e36b37/32.png) [@ernie\_mac](https://forum.ionicframework.com/u/ernie_mac)\
**Post date:** [June 11, 2014, 9:52pm UTC](https://forum.ionicframework.com/t/retrieving-mysql-data-using-json-and-php/5525/1 "2014-06-11T21:52:27Z")

</div>

any tutorials or sample project that retrieves data from mysql using php and json??

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [June 12, 2014, 1:12am UTC](https://forum.ionicframework.com/t/retrieving-mysql-data-using-json-and-php/5525/2 "2014-06-12T01:12:35Z")

</div>

php isn’t my strong point, but thankfully a lot of people out there have put examples together. Now it’s not specific to ionic, but it is angular so it shouldn’t but to much different.

> **[Simple task manager application using AngularJS PHP MySQL](http://angularcode.com/simple-task-manager-application-using-angularjs-php-mysql/)**
>
> This tutorial explains how to create a simple Task Manager application using AngularJS. Here I used PHP for server side communication and MySQL for database. Live Demo Download Our task manager app will have the following features Create a new task...

> <https://stackoverflow.com/questions/21467127/how-to-use-php-mysql-generated-json-in-angularjs-application>

---

<div class="post-metadata">

**Author:** ![edwrede\_ZA](https://avatars.discourse-cdn.com/v4/letter/e/b5ac83/32.png) [@edwrede\_ZA](https://forum.ionicframework.com/u/edwrede_ZA)\
**Post date:** [June 12, 2014, 7:25am UTC](https://forum.ionicframework.com/t/retrieving-mysql-data-using-json-and-php/5525/3 "2014-06-12T07:25:02Z")

</div>

Hi Ernie\_Mac

I’ve built an Ionic project on the same technologies.

If you need any specific examples maybe drop me a message and I’ll see if I can help you out? Or if you’d prefer, post some more specific questions here and I’ll do my best to answer and then hopefully people in future can benefit 😄

Ed

---

<div class="post-metadata">

**Author:** ![ernie\_mac](https://avatars.discourse-cdn.com/v4/letter/e/e36b37/32.png) [@ernie\_mac](https://forum.ionicframework.com/u/ernie_mac)\
**Post date:** [June 12, 2014, 10:11am UTC](https://forum.ionicframework.com/t/retrieving-mysql-data-using-json-and-php/5525/4 "2014-06-12T10:11:41Z")

</div>

Hi I am trying build a login, signup forms that links to mysql to save and retrieve user information and as well as creating user profiles for each registered user…

also building a daily deals app that retrieves all the deals stored in the database with view page to display more information for a specific deal when the user clicks…

am kinda new to ionic so if you know any tutorials or project with similar functionalities I would appreciate the help.

thanks

---

<div class="post-metadata">

**Author:** ![edwrede\_ZA](https://avatars.discourse-cdn.com/v4/letter/e/b5ac83/32.png) [@edwrede\_ZA](https://forum.ionicframework.com/u/edwrede_ZA)\
**Post date:** [June 12, 2014, 10:36am UTC](https://forum.ionicframework.com/t/retrieving-mysql-data-using-json-and-php/5525/5 "2014-06-12T10:36:51Z")

</div>

Ionic leverages AngularJS. So where you’d probably need to start is looking into Angular factories and the HTTP service.

```
YourModule.factory('fctryRegister',['$http', function($http)
{ 
  return {
    submitRegistration: function(userName, userEmail, userPhone, successcb) {
      var RegObj = {};
      RegObj["SP_Name"] = "prc_user_reg";      
      RegObj["userName"]= userName;
      RegObj["userEmail"]= userEmail;
      RegObj["userPhone"]= userPhone;
      
      $http.post('pathToYourPHP.php', RegObj)
          .success(function (data, status, headers, config) 
                {
                    successcb(data);
                    console.log(data);
                })
          .error(function (data, status, headers, config) 
                {
                  successcb("99");  
                  alert("Oops something went wrong. Please login and try again. Sorry for the inconvenience.");               
                });
    }
  }
}]);

```

So basically we have an Angular factory attached to my Angular module. I have a PHP page which I pass a stored procedure name as well as an array of parameters. Inside the PHP I strip out the parameters and pass them to the relevant stored procedure and return a result.

That result is stored in the data variable of the success method.

This example makes use of a callback which is passed to the factory, calling this from my controller would look something like this:

```
fctryRegister.submitRegistration($scope.userDetails.userName, $scope.userDetails.userEmail, $scope.userDetails.userPhone, function(uID)
{  
   

} 

```

function(uID) is the callback being passed to the factory. uID will hold the data passed back from the factory.

There may be other ways or better ways to do this, but it’s how I’ve built my app, works pretty well 😄

Let me know if I can help with anything else!  
Ed

---

<div class="post-metadata">

**Author:** ![macklindamon](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@macklindamon](https://forum.ionicframework.com/u/macklindamon)\
**Post date:** [August 9, 2014, 10:55am UTC](https://forum.ionicframework.com/t/retrieving-mysql-data-using-json-and-php/5525/6 "2014-08-09T10:55:18Z")

</div>

Did you have any joy with this Ernie??

Damon

---

<div class="post-metadata">

**Author:** ![Dennizh](https://avatars.discourse-cdn.com/v4/letter/d/a6a055/32.png) [@Dennizh](https://forum.ionicframework.com/u/Dennizh)\
**Post date:** [October 13, 2015, 2:14pm UTC](https://forum.ionicframework.com/t/retrieving-mysql-data-using-json-and-php/5525/7 "2015-10-13T14:14:38Z")

</div>

Hi Ed,

I am Dennizh, nice to meet you…  
I am newbie here and the problem was same like ernie, to retrieve data from my website that running on apache.

Did you have any blog or reference that write step by step to connect ionic with mysql on www (php) url (just sample only)

Thanks for your helps…

---

<div class="post-metadata">

**Author:** ![fabioferrero](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/fabioferrero/32/69781_2.png) [@fabioferrero](https://forum.ionicframework.com/u/fabioferrero)\
**Post date:** [October 13, 2015, 2:37pm UTC](https://forum.ionicframework.com/t/retrieving-mysql-data-using-json-and-php/5525/8 "2015-10-13T14:37:51Z")

</div>

It’s not so simple, because you can also need to check if connection is available and fall back if connection isn’t available.

However, google can help you, for example: [http://www.kodingmadesimple.com/2015/01/convert-mysql-to-json-using-php.html](http://www.kodingmadesimple.com/2015/01/convert-mysql-to-json-using-php.html)

---

<div class="post-metadata">

**Author:** ![Dennizh](https://avatars.discourse-cdn.com/v4/letter/d/a6a055/32.png) [@Dennizh](https://forum.ionicframework.com/u/Dennizh)\
**Post date:** [October 14, 2015, 2:08am UTC](https://forum.ionicframework.com/t/retrieving-mysql-data-using-json-and-php/5525/9 "2015-10-14T02:08:54Z")

</div>

Hi Fabio,

Thanks for the link, now I will try to view the json on the web to android app

---

<div class="post-metadata">

**Author:** ![trotterellone](https://avatars.discourse-cdn.com/v4/letter/t/779978/32.png) [@trotterellone](https://forum.ionicframework.com/u/trotterellone)\
**Post date:** [November 29, 2015, 1:54pm UTC](https://forum.ionicframework.com/t/retrieving-mysql-data-using-json-and-php/5525/10 "2015-11-29T13:54:03Z")

</div>

Hello @edwrede_ZA,  
please can you send me your example project?  
[simone.info.trash@gmail.com](mailto:simone.info.trash@gmail.com)
