How to connect to MySQL with ionic?

I am using a MySQl database (the data is in csv form)from Pythonanywhere and want to connect the database using an apps.
I am still learning ionic but want to know how to connect and view it using ionic?
Can it view from csv or must be in json?
I want to know if this is possible before I go deep into Ionic.

Nope. Ionic 2 is client side.

It means there is no way i can query data which is in csv in mysql?
any suggestion?

Or is it any other way like i send the data to different type of database so that i can request the data via ionic frame work easily?

you can make a post to your server and get a json as response. a simple google can show you a lot of tutorial about it.

Ionic is a client-side framework and is written in javascript or typescript. This two languages are not able to connect to a mysql datavase itself. You need for example a server-side API written in e.g PHP or Ruby, which gathers the data from the mysql database. Via the HTTP module of angular you can call your server now and receive the data!

Thanks david,

Is it a cross site http request?

Besides, the http module form angular 2 only take json and can’t take for csv?

Yes, the request to your server will be a cross-site one and you will need to put the correct stuff in the header of your request.

Access-Control-Allow-Origin: *

The problem of sending back csv-formatted text, is the parsing on the client side. I would just parse it on the server and send it back as a JSON Array/Object.

Thanks David.
please let me know if the steps are correct

  1. convert MySQL data into json
  2. using Http request in

BTW, is the php file can be insert in ionic 2?Where should I put the file?
Besides, I want to query the data by searching the name of stocks (my database is stock name and price for 1000 stocks), i need to fetch the data in a whole(like the ecample in the link) or it can load one by one base on the query? Example, I search for AAPL, it will load for AAPL only? I a not sure a if a free MySQL database will allow high bandwidth if I fetch a large data.
Please help…thanks

You should use JSON + http calls.

Hi bkcollection,
I don’t have much experience in Ionic but i think i could help you->
step 1->get data from database in php
step 2-> make Rest API (you can use framework like apigility etc to save time .)
step 3 -> get your data in Ionic factory or where ever you want in Json form.


Thanks Aabir for the introduction of apigility. The concept of using api instead of mysql database straight away is for the flexibility for any changes in the future without changes in frontend?
What inputs needed for apigility?
i still wonder how php,apigility integrate in ionic code.

Let me be as clear as possible: They do not integrate.

You have your MySQL database on computer A (together with PHP or JS or Python or … that provide a Rest API to the MySQL db). And on a completely different computer - call it computer B - usually your mobile phone, you "consume"or query this data.

Computer A is called a server, because it serves data. It doesn’t care who consumes the data.
Computer B is called a client, it can (but doesn’t have to) consume data from some remote server. It displays stuff in a nice way to users and lets them interact with itself. ← this is what Ionic does.

Ionic is in no way related to anything database. That is because you have to write different code for computer A & B each. If you pick Ionic, then computer B runs mainly on Javascript. But for computer A you have complete freedom of programming language. You can also pick Javascript, but Ionic can’t help you because Ionic is not for servers.

P.S.: Apigility is only one example out of many many that make your MySQL database into a Rest API.
Other examples:
(PHP) Symfony, Zend Framework, or simply just raw PHP
(JS) Express, Restify, Loopback, or simply just raw Node JS

P.P.S.: just for correctness’ sake: you don’t convert your MySQL database into a JSON file one single time and then just display the JSON file in Ionic. You program Ionic to send queries for specific elements of the database and then the content you asked for, gets converted temporarily to JSON. But you don’t save this JSON somewhere as a file - your server reads some entries form the database, converts them to JSON in your RAM and then it immediately send them to the client (your Ionic app). Only in very rare cases is it a good idea to convert the entire database to a JSON file.


You are a little too early, native JSON support will be in the next version of mysql.

API is the way to go, I prefer RAILS over PHP because that what I been doing forever. Rails-api talks to mysql and i send my json queries into rails-api. You can use the Google Advance REST Client to practice your requests to the API backend before you struggle sending from IONIC

hello everyone,
I want to connect my login form ( created by using Ionic 2 framework & angular 2) with my phpmyadmin database.
please help me fort hat