How to connect mysql in Ionic mobile app with angularjs


I have tried server side PHP code it was working fine, but i cant store any data to mysql table… How to connect mysql. i am using phonegap interface to run ionic app in localhost. I am very new to ionic and phonegap. If know anybody help me on that… Thanks in advance…


it depends where you want to run mysql

Your backend is connected to a database… so you can checkout php + mysqli

If you want to store the data on the device as well --> you can use sqlite-cordova-plugin


Thanks for your reply, i want to store my data into mysql instead of mobile local storage, i am using Linux hosting,

my js code

  $, {username : $,email:$,password:$}).then(function (res){
    $scope.loading = false;

    $scope.response =;

php code:

$con = mysql_connect("localhost","root","");
if (!$con)
die('Could not connect: ' . mysql_error());
mysql_select_db("dbname", $con);

if (isset($_SERVER['HTTP_ORIGIN']))
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400');   

header("Access-Control-Allow-Methods: GET, POST, OPTIONS");  

$postdata = file_get_contents("php://input");
if (isset($postdata))
$request = json_decode($postdata);
$username = $request->username;
$email = $request->email;
$password = $request->password;
$enc_pwd = sha1($password);

if ($username != "") 

$result=mysql_query("insert into register values ('','$username','$email','$enc_pwd','$cur_date')");
echo "Successfully registered";

echo "Empty username parameter!";

echo "Not called properly with username parameter!";

Note: when i run the app from my mobile i am getting full php code as a response…


Please, could you beautify and format you code correctly ?


yes, i have beautified and formatted my code…


I want your email if possible