How to connet Ionic mobile application with MySQL database


#1

hello I just started to developed with Ionic and I want to know how to connet Ionic mobile application with MySQL database please?
thank u :slight_smile:


#2

If you’re using Ionic 2 you can check this out: http://www.joshmorony.com/using-http-to-fetch-remote-data-from-a-server-in-ionic-2/

Specifically the “Pulling data from your own server” section.


#3

this is our code i would like to connect ionic mobile with mysq database for a wordpress site:

newsletter.html

Adresse email
            <button type="submit" class="register button button-block" ng-click="Newsletter(input)" ng-disabled="signup_form.$invalid">

              S'inscrire
            </button>
            <p ng-show="error" class="message error">{{error}}</p>
      </div>
    </form>

controller.js

.controller(‘NewsletterCtrl’, function($scope, $http) {

 $scope.Newsletter = function(input) {

 $http.post("http://www.dev.leclubdesjuristes.com/api/page-inscriptionnewsletter.php/?email="+input+"");

}})
app.js

.state(‘app.new’, {
url: “/newsletter”,
views: {
‘menuContent’: {
templateUrl: “views/app/newsletter.html”,
controller: ‘NewsletterCtrl’
}
},
data: {
authenticate: true
}
})

page-inscriptionnewsletter.php

<?php /* Template Name: Inscription newsletter mobile */ ?> <?php get_template_part('templates/header'); ?>
<?php if (have_posts()) : ?>

	<?php while (have_posts()) : the_post(); ?>

		<h1 class="title-post"><?php the_title(); ?></h1>

		<?php the_breadcrumb(); ?>

		<div class="content-post">
            <?php 
            
                 $data = json_decode(file_get_contents("php://input"));
                 $email = mysql_real_escape_string($data->email);
                 $qry = 'INSERT INTO lcdjwp_newsletter (email) values ("'.$email.'")';

                 $qry_res = mysql_query($qry);
                 if ($qry_res) {
                    $arr = array('msg' => "Email Created Successfully!!!", 'error' => '');
                    $jsn = json_encode($arr);
                    print_r($jsn);
                } else {
                    $arr = array('msg' => "", 'error' => 'Error In inserting');
                    $jsn = json_encode($arr);
                    print_r($jsn);
                }
            ?>
			<?php the_content(); ?>
		</div>
		<!-- .content-post -->

	<?php endwhile; ?>

<?php else : ?>

	<!-- Si il n'y a pas de Post, j'affiche cette partie -->

<?php endif; ?>
<?php get_template_part('templates/sidebar'); ?> <?php get_template_part('templates/footer'); ?>

#4

you can refer to the link.


#5

just follow this tutorial in this clear all the sites