I am developing an Android and iOS app using HTML, CSS, PHP to interact with MySQL database through JSON for integration with PhoneGap. All functionalities work smoothly on a browser, but I'm unsure how to upload the app and its server-side functions to a GitHub repository in order to utilize PhoneGap cloud services. With previous apps that did not involve MySQL, I simply uploaded the code to GitHub.
If I were to host the MySQL database on a remote server and the app code on GitHub, how can I establish a connection between them?
Below is my PHP script for database connection:
<?php
header('Access-Control-Allow-Origin: *');
$user="root";
$pass="xxxx";
$dbh = new PDO('mysql:host=localhost;dbname=uxxxmobile', $user, $pass);
?>
Here is my login function:
<script>
$(document).ready(function(){
$('#loginForm').on('submit',function(e){
var myForm = new FormData($(this)[0]);
var host = 'http://example.com/uixxxmobile/connections';
$.ajax({
type:'POST',
url: host + '/login.php',
data : new FormData($(this)[0]),
cache: false,
contentType:false,
processData: false,
beforeSend: function(){
$("div#divLoading").show();
},
success: function(response){
$("div#divLoading").hide();
console.log(response);
if(response.success == true)
{
window.location.href = "profile.html";
}
else if( response.success == false ){
alert('please enter a correct email & password');
}
else if(response.matric =="") {
alert('email is wrong');
}
else if(response.password==""){
alert('password is wrong');
}
},
error: function(data){
alert('Login fail. Check your login details correctly');
$("div#divLoading").hide();
}
});
return false;
});
});
</script>
And here is my profile function:
<script>
$(document).ready(function(){
var host = 'http://example.com/uixxxmobile/connections';
$.ajax({
type: 'GET',
url: host + '/profile.php',
data: 'param=no' ,
dataType: 'JSON',
success: function (response) {
console.log(response);
var input ="";
input +='<b>' + response.name + '</b><br>';
input += response.faculty + '<br>';
input += response.dept + '<br>';
input +=response.school + '<br>';
var cumgrade= response.cumgpa;
var currentgrade= response.currentgpa;
$('#basicContent').html(input);
$('#cumgpa').html(cumgrade);
$('#currentgpa').html(currentgrade);
$('#level').html(response.level + ' Level ' +response.semester+ ' Semester')
},
error: function (e){
alert (e);
}
});
$('#mycourses').load('connections/user-course.php');
});
</script>