Next lesson playing in 5 seconds

Cancel
  • Overview
  • Transcript

1.2 What You Need

You'll need an environment that includes PHP, Apache, and a MySQL database. I use XAMPP to get up and running quickly. We'll also create the database and table that our application will use.

1.2 What You Need

Before we dive right in and start talking about working with databases and PHP, let's first of all, go over what you will need to follow along in this course. And I can only assume that you have at least some of this stuff, because this isn't necessarily a course for brand new PHP beginners. I assume that you have experienced with PHP. It doesn't necessarily need be a lot of experience. But I assume you know the basics of the language which leads me to believe that you have something at least installed on your computer that you can work with PHP. Now, you might have some of the other things like a web server and database server, and if not well, then I have a very good solution for you. Now you can of course install all of those things separately. That would be PHP, a web server, and then a database serve. And then you can configure them however, that can be a headache, and it's a lot easier to just download and install a package that's going to manage all of that for you, so I recommend using XAMPP. X-A-M-P-P, you can see that it stands for Apache + Maria DB + PHP + Perl. Now Maria DB is not MySQL. It is a very good clone of MySQL. And that's not really a problem, because when it comes to working with relational databases, which is what MySQL is, what Maria DB is Microsoft SQL, and host of other SQL oriented databases. All of the concepts are the same, there might be different features that separate one type of database from another, but for the most part, the concepts are the same. So when it comes to this course, we are technically going to be working with Maria DB, or at least I am going to be on the screen. However, everything is going to translate just fine to MySQL. Now there are versions of XAMPP for Windows, for Linux and Mac OS. So feel free to download that for your operating system. And then get that up and running. And the really nice thing that I like about XAMPP and there's other tools like XAMPP, but this gives you the ability to turn on these services, and then whenever you're done with them, you can turn them off. So if you're not fortunate enough to have a virtual environment for your development purposes, this is perfect so that you don't have services running all the time. Now, as you can see, my version of XAMPP is just a little dated. It was compiled June 5 of 2019, but that's okay because. Well, none of these technologies have really changed all that much since then. However, I do want to get Apache up and running. I also want to get my SQL up and running as well. So I will start those services. And let's very briefly go over the concept of a database table. Now a table is just something that is going to store data. Database is a container of tables. So yes, we store data in a database. But more technically we store data inside of a database table. And we can create as many tables as we need in order to meet the needs of our application. So the application that we are going to write is just a simple address book. We will have a first name and last name. Then an email address. So a database table is really divided into two dimensions, we have columns, and then we have rows. The columns define the type of data that we are going to be working within and storing within our table. And then the rows are the actual records themselves. So for our database, we would have, first of all, a column that will allow us to identify an individual record. This is very important, because when it comes down to the data inside of a database, in our case, we would have a first name and a last name, and then let's just say an email address. Now, email addresses are unique. Yes, but let's say that we may or may not have an email address. So we can't really rely upon the email field. In order to retrieve an individual record, we can't really rely upon the first name and last name, because first names and last names are not unique. We might have two people called john doe. Or we might have somebody called John Smith, in which case, if we tried to find people just by their first name or their last name, We're going to get multiple results. So instead we have an identity. This is a special column that typically contains a unique number that we can then use to reference an individual row. So we could say, okay, database, give me the user with an ID or give me the person with an idea of one that would be. John Doe here, give me the person with an id three. That would be John Smith. That's the purpose there. So we are going to build a database table that looks a lot like this. We're going to have four columns and we're going to use that to store people. So let's click on the admin button for our MySQL database. This is going to pull up phpMyAdmin. This is an open source project. That is, well the project itself is very old. In fact it is over 20 years old, but that doesn't mean that we shouldn't use it, because it is updated regularly. So new features are added to it. It's just that this is a project that has been around for a very long time. It is very useful and it's given to us or we just might as well use it here. So we're going to create a new table, or a new database. We're going to call it, address_book. The convention for a MySQL database, and really anything inside of MySQL is if you have multiple words to separate them with an underscore. So the entire name is lowercase Words are spaced with an underscore. And then we will create. And then we want to create our table and we're just gonna call that people. We can start off with a certain number of rows, but 4, or columns rather, but 4 is going to be. Perfect in our case. So the first that we want is an ID. We want this to be an integer, but we can choose other types of values if we want. The main thing is that Id has to be unique, and if we pick integer can make sure that is unique, because we can tell the database to automatically increment that value, so we don't have to worry about that at all. Now, I clicked on this AI, or A_I, that stands for auto increment, and this popped up at an index. We're not going to really go into indexes, but when you have a table that has a lot of data building into indexes, so that you can find information a little quicker, and really find the information that you need a little quicker. Is very useful and that's why you would want to use an index, but we won't get into that. The next thing that we want is the first name, and that is not an integer. So you can see at the top that there are four types of values. There's Int, Varchar, Text and Date. These are the most common types that we use inside of a MySQL database. There are a tonne of other data types, so you're not limited to just those if you need a tiny Int or small Int or if you need something with precision like a decimal, then those options are there. But in our case, we just need the VARCHAR here. This can be a string of zero to 65,000 characters. So it can contain a lot, we just need 50, and that's gonna be fine. Let's also have the last name. And we will essentially do the same thing so that, that is a VARCHAR that is 50 in length. And just, because we're picking 50 doesn't mean that we have to fill up all 50 characters. That's just the maximum amount that we can store here. If we need to, we can come back, and change that 50 is going to be fine. And then finally we'll have an email. And once again that's going to be a VARCHAR, let's give it a length of 50. I've never seen an email address longer than 50, but you never know. But remember that we may or may not have an address, we might want to add a person, and then add their address at a later time. So we might not always have Information for the email and the database can fit that need for us with this know. If we check this for our email field that means that we can insert a row that contains the first name and last name, but doesn't contain an email. If we uncheck, no, that means that we have to supply some kind of value for email. So we're gonna leave that as no, and then we will scroll on down, click on, save. And we have our database table. And this is just giving us a readout of the columns. And as since we don't have any data inside of this table, we don't see that data, but that's okay. Because in the next lesson, we are going to write the code that will add a person to our table.

Back to the top