Course 3: Talking to a MySQL Database in PHP

Woh, this is episode 3 of our Epic PHP series!

Yep, and this one is all about databases:

  • What the heck is a database anyways?
  • Connecting to MySQL
  • Creating a database and tables
  • INSERT queries
  • SELECT queries
  • UPDATE and DELETE queries
  • Using PDO in PHP to run queries
  • Limiting Results
  • Avoiding SQL Injection Attacks
  • Prepared Statements
  • Optional Function Arguments

Your Guides

Ryan Weaver Leanna Pelham

Questions? Conversation?

  • 2016-07-17 Anne Bonham

    Love the series, thanks! Can't wait to learn how to connect the form submissions to the db!

  • 2016-06-22 Victor Bocharsky

    Yes, it's a standalone component, which required only PHP 5.5.9 or newer and a small "symfony/polyfill-mbstring" package which is just a polyfill for the Mbstring PHP extension. So you can use it in any PHP project!

    BTW, If you want to use it in Symfony projects, better use a DebugBundle instead, it's a bundle for varDumper component which already has integrations for WebDebugToolbar and Twig. But Symfony 3 already has it out-of-the-box, you can just use it from the start.

    Cheers!

  • 2016-06-22 Euclides Cohen

    Hey Victor, thanks for replying. I had to inspect the source code.

    Can you use the VarDumper Component on non Symfony projects?

  • 2016-06-22 Victor Bocharsky

    Hey, Euclides!

    Yes, it's totally unreadable! The easiest way is to open Source Code in your browser (command+option+U on Mac). The output will be preformatted vertically.

    If you want something more cool, you need to install xDebug. This is a PHP extension, which you can install from your package manager ( like APT-GET on Ubuntu). After you install and enable it, your var_dump output will look much pretty. But keep in mind, that xDebug a bit reduce page performance, maybe it's not you want to be installed on production but only in development.

    You could also check the coolest Symfony's VarDumper Component which does not required any PHP extension and has a nice output with ability to expand nested nodes.

    And let me know what you chose! :)

    Cheers!

  • 2016-06-22 Euclides Cohen

    Hey guys, I am very happy to be back to Knp University. One question: Is there a way to clean up the output of my database array, mine looks horrible (one line)? Take a look to this screenshot to see what I mean:

    http://imgur.com/V5qpKfl

  • 2016-01-13 Gilron Charles

    I would really love to see an episode 4 also

  • 2015-12-28 weaverryan

    Hey Neal!

    Yes, we have a lot of threads going :). I promise we'll be looking more into this series to make sure it's complete. And thanks for the nice words - I want people to be able to go from zero to hero all in one place. The specifics for ep4 aren't planned yet - but I just added your suggestions to our planning document.

    Thanks!

  • 2015-12-26 Neal Ostrander

    Is there going to be a 4 episode for the PHP series that covers inserting, updating and deleting data? Your tutorials are the best I have found on the web but several seem to be stuck in limbo with lots of unfinished sections. I would challenge you to look at all the available tutorials and finish them before throwing out more Symfony 3 stuff. Probably could be accomplished in a months time. Looking forward to a productive new year learning with KnpUniversity.