How to Connect PHP Mysql & perform CRUD Operation in Hybrid application


#1

Hi Guys…

I am a beginner to Ionic …I try to connect mysql database but blank response are out …

How to perform CRUD operation in Ionic application


#2

I don’t understand. If you use PHP and MySQL, I think you have to connect to the database with PHP on server side, create functions for CRUD operations in PHP (like http://myurl/getUser/id/x). The function get the user from the database and return it. In ionic, you just have to call that url and it should return the data you need.


#3

Thanks for replying mr.Alex …i am connecting my php file using URL .the response is blank …like blank white alertbox


#4

What do you use for testing?
If this is a physical device and your web server is running in local computer then no response will come
If the testing is from browser, double check the link(API), you may add port i.e. http://localhost:80 depending your setup
If alls well, then try to open the link (API) from browser and see the result.
P.S. it can also be some authentication issue.


#5

I am running the hybrid app on Localhost Xampp Server …For Testing …after i build APK…

is it wrong method for testing ?


#6

sorry for the late reply…
When you call the server API with the local ip i.e. localhost or something, it may not be available to your device.
Try to open the server link in browser in mobile (chrome or whatever available)
If the response comes then the server API is accessible from your device


#7

Your device cannot access your localhost.
Instead of using localhost in your API url use the ip address of the computer where you are running the xampp server.
Make sure your device is connected to same network as the computer and your device will be able to access the API.
Using IP address you can test from both your browser and the device.
The way I handle this is using a Dev/Test mode and Prod Mode. Based on the mode I set I change my url destination.
Hope this helps.


#8

Thanks For Sharing Ideas …

I Have One More Doubt …I am Upload and Set header(Access-Control-Allow-Origin : “*”);

But its say cross domain access block on url … Why this problem occur . Even Iam Set header access in root folder in hosting …

what iam do frds ?


#9

Have you followed any tutorial for performing CRUD in PHP and MySQL? To perform CRUD you must know that you can use prepared statement which is used to execute same query multiple times with high efficiency.

Here is an example of how you can open connection

function PreQuery($fname,$lname,$email,$subj)
{
	$conn = OpenCon();
	$query = $conn->prepare("INSERT INTO myguests(firstname, lastname, email, subject) VALUES (?,?,?,?)");
	$query->bind_param("ssss", $fname,$lname,$email,$subj);
	
	if($query->execute())
	{
		CloseCon($conn);
		return true;
	}
	else
	{
		return $conn->error;
	}
	

}

Source: Crud in Operations PHP and MySQL