Accessing mySQL DB using php

I’m getting the following error: GET http://localhost:8100/json.php 404 (Not Found). However, whenever I go to http://localhost:8100/json.php I also get the error Error: Cannot match any routes. URL Segment: ‘json’.

this.http.get("http://localhost:8100/json.php").subscribe( data => {
  this.productList = JSON.parse(data["_body"]);
}, err =>{

json.php is under the directory src/app/db/json.php

Any help is greatly appreciated!

What u try will never work this way

An angular app will never serve php pages and a database nor should u want to try to do so.

The database and url endpoint will have to be published on a separate webserver (Php and mysql)

I do like the total mixup of concepts in your code. Very creative!!!

1 Like

Apologies for this, I’m quite new to all of it. I’ve been following this tutorial:, would you not recommend it?

Sorry! I did not intend to sound mean.

That tutorial seems fine and sufficient for me, but does not explain very explicitly you need to put the php stuff on a server

The tutorials says: Requirement:* we need to create JSON based Web service with PHP & MySQL. I already created simple web service using PHP. Note: It’s a very simple code which is not included any security.

That simple line is the hidden instruction to install one before continuing

And looking at the ionic code, it was installed on the local machine

Look for configuring php and mysql on your pc, for example using a WAMP installation. Google is your best friend here

1 Like

@Tommertom is far more polite than I am, so I’ll say it. That “tutorial” is a flaming pile of garbage - it’s sloppy, out-of-date, poorly organized, insecure (at least it’s honest about this part), and breaks all sorts of conventions.

Lets try to find something for the poor OP!

I really appreciate this guys, thank you!

@rapropos, better?

Bit oldish but at least fairly elaborate and conplete

Marginally. At least it’s using HttpClient, but still way too much any abuse and mashing stuff into pages that should go into services. I hate PHP with the fury of a thousand white-hot suns, so can’t speak to that part, but here is something that purports to be a PHP backend for use with the good old Tour of Heroes. That should at least set OP up with some better idiomatic Angular for the Ionic side.