RESTful API With PHP & MySQL




In this video we will build a complete JSON RESTful API using PHP and MySQL. We will use the SlimPHP framework along with PDO to interact with the MySQL database. CODE -https://github.com/bradtrav…

Original source


34 responses to “RESTful API With PHP & MySQL”

  1. great tutorial! this and together with the article i read on laravel api development has really made me understand how APIs work more, the only questions i have left now are: what instances are APIs useful? when/how will i know i should be building one for an application? if anyone could answer, i would greatly appreciate it.

  2. Hi,
    After I add the tags in httpd-vhosts.conf the xampp apache server crashers with the following errors: Error:
    Apache shutdown unexpectedly.
    11:40:36 AM [Apache] This may be due to a blocked port, missing dependencies,
    11:40:36 AM [Apache] improper privileges, a crash, or a shutdown by another method.
    11:40:36 AM [Apache] Press the Logs button to view error logs and check
    11:40:36 AM [Apache] the Windows Event Viewer for more clues
    11:40:36 AM [Apache] If you need more help, copy and post this
    11:40:36 AM [Apache] entire log window on the forums

  3. thank you so much for this great tutorial, but i have a question that i really hope you answer for me:

    now i have three tables on mysql and they're connected by "foreign keys", my question is do i need to do a routes.php for each table to have post, get, put and delete working on them? i'm little confused about this! please clarify!

    appreciate you man!

  4. Why not use the $response param in order to generate the response instead of echo-ing ? i'd also singleton the DB connection to have it always available and ready for calls, all in all a great resource, thanks for the tut

  5. Great Vid. I am stuck with the following error and as I'm totally new to php and MySQL I'm not sure how to fix it.

    Error:
    {"error": { "text": SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)}

    I know its something to do with the password but after that no idea. Any help would be appreciated! Thanks

  6. I just want to point out that echoing your response is not the correct way to use this Framework.

    Instead of doing:
    echo json_encode($customers)

    Do:
    return $response->withStatus(200)
    ->withHeader('Content-Type', 'application/json')
    ->write(json_encode($customers));

    This will allow you to send custom status codes and custom headers.

  7. I please request another video on consuming this API from Angular. I think you need the Angular app to be on the same domain in order to use the API, but there are ways around that. So it would be really helpful to know how to structure the Angular app to work with these API files. Maybe cover the situation where the API is on the same server as the front end app, and another situation where it's not. 🙂

    Also, for Anguar, all other Youtube videos assume the backend is Node, but many like me just use a regular non-Node supported hosting company that supports PHP.

  8. Nice tutorial to understand the basics of the slim framework I really Wonder if you could implement a MVC structure in a little project for another tutorial, keep it up! and hope you do a tutorial of what I told you.

Leave a Reply