08-26-2013, 03:19 PM
I'm here today with a tutorial on Inserting and Retrieving Data with PDO. I wanted to stick with just basic SQL until I figured out by a friend how much easier and better PDO is. I recommend everyone try and switch over too it.
Alright, lets get started. Go to PhpMyAdmin and lets make a new table called 'People' with 3 columns. Here is the set up:
Next, lets add one item. Click insert, and leave the ID field blank. Enter in a first name and a last name and click go. You should see something like this when you click Browse now:
We are now on the PHP portion of this! Create a new file, and call it whatever you want.
Under the "<?php" you will want to add this and fill it in with your database info where it says change me!
Once you have done that, we will go ahead and create our query. Its very simple, and it will grab all the rows within the column we are selecting from.
That will execute the query, next we have to grab each row of info which can be done like so:
That is it for this tutorial! Next tutorial will be selecting by a parameter and binding. If you did this right then you should see something like this:
Alright, lets get started. Go to PhpMyAdmin and lets make a new table called 'People' with 3 columns. Here is the set up:
Next, lets add one item. Click insert, and leave the ID field blank. Enter in a first name and a last name and click go. You should see something like this when you click Browse now:
We are now on the PHP portion of this! Create a new file, and call it whatever you want.
Under the "<?php" you will want to add this and fill it in with your database info where it says change me!
Hidden Content
Once you have done that, we will go ahead and create our query. Its very simple, and it will grab all the rows within the column we are selecting from.
Hidden Content
That will execute the query, next we have to grab each row of info which can be done like so:
Hidden Content
That is it for this tutorial! Next tutorial will be selecting by a parameter and binding. If you did this right then you should see something like this: