PHP-and-MySQL/C3/MySQL-Part-1/English-timed
From Script | Spoken-Tutorial
Revision as of 20:45, 16 February 2015 by Sandhya.np14 (Talk | contribs)
Time | Narration |
00:01 | Hi everyone! |
00:03 | This is a pure My SQL php tutorial. |
00:06 | I will teach you the basics of connecting, retrieving data, handling errors and modifying data. |
00:12 | So, that will cover some SQL code and some SQL queries. |
00:17 | Ok! Lets start. |
00:19 | Here I am going to show the directory structure of "mysql" |
00:23 | and we will create a couple of files here. |
00:29 | I will create the first file and call it "connect.php". |
00:33 | I will come here, click on the folder called "mysql" and Save this as "connect.php", |
00:39 | Now here we will create a separate file and include with every page that we use. |
00:45 | This is a lot easier to connect to your database, |
00:48 | What we will do is type our "include" function and specify this file. |
00:53 | I will create another file which is my main "mysql" file |
00:57 | with a code that I will show you all. |
00:59 | Ok, so I have got my mysql dot php open. |
01:03 | This is php codes and we need the php tags and the same will connect to php. |
01:10 | I will explain this "include" function in a minute. |
01:16 | First, I will teach you how to connect to the database. |
01:20 | If you don't know where you have it stored on your web server, then I suggest you check out an application called phpmyadmin. |
01:28 | It is a database interface php written program or in other words a script. |
01:35 | Here we will look at the inside of my database, my service. |
01:41 | Rather my server, My SQL server. It gives our table information, our database information and information about my server etc etc. |
01:55 | Although, we don't need to know about it, this is a good start to a program, if you are just starting to use a php mysql or just mysql in general. |
02:06 | It is a good way to start interfacing with your database, instead of using the command line to do things. |
02:13 | Using command line could be difficult for the first timers. |
02:18 | Ok, so what we see here are, our databases. |
02:23 | I have got one called "phpacademy" and I have got one called "phplogin" which I mentioned in another tutorial that I have created. |
02:31 | The others are just a standard. |
02:34 | They are just for holding data. |
02:36 | Don't delete them. |
02:38 | All you need to do is create new databases. |
02:41 | To do this, you have got a simple box here. |
02:45 | We are just going to create databases. |
02:47 | I will work within my php academy database for now. |
02:51 | It is a lot easier. |
02:53 | So its creating a database now. |
02:55 | It is simple. |
02:56 | You type in the name and click on "Create". |
02:58 | My php has already been created here. |
03:01 | So I will use this one. |
03:02 | Click on it and you can see that there are several tables inside. |
03:08 | This is denoted by the symbol here when using phpmyadmin. |
03:15 | This is guestbook from my guestbook tutorial. |
03:21 | Now I will create a new table on this database for the specifics of this tutorial and I shall call it "people". |
03:30 | The number of fields is quite important. |
03:33 | You can't leave this blank. |
03:35 | The number of fields on your table is for storing each column of data. |
03:42 | For example, the first one usually when you are dealing with records, you can have an ID which is a numerical value. |
03:51 | So it is a number that is going to increment each time. |
03:56 | It will allow you to reference your records being stored individually by the unique number. |
04:02 | And usually set this to the primary key. |
04:06 | If you are not familiar with the databases, you need to start looking out for terms like primary key. |
04:14 | I will not be dealing with secondary keys because its quite flexible way to do this anyway with mysql database. |
04:22 | Just read up on databases in general, if you have Microsoft access or any other database . |
04:29 | I suggest you to learn about groups of database. |
04:34 | Ok, so the number of fields depends on how much data you want to store and what data you want to store. |
04:39 | Usually when I am creating fields, I will bring out an usual blank document. |
04:44 | And I will start by typing out the fields that I want. |
04:47 | The first one is always going be ID. |
04:50 | This is a self incrementing value every time I create a new record. |
04:55 | So it will be 1 for the first record, 2,3,4 and the data will be stored after this. |
05:00 | It is a very useful field. |
05:02 | Since my table is called "people", I will store some data about people. |
05:08 | So I will first type in the firstname and then I will type in the lastname and then the age and the gender. |
05:17 | We can leave it there for now, to keep it simple. |
05:20 | So here we can see that we have got 5 fields. |
05:23 | I shall go back here and type in 5 and click "Go". |
05:28 | It will also be great to see a pop up here in a minute. |
05:31 | No you won't because we haven't created our field names yet. |
05:35 | Ok! We have a standard here. |
05:38 | There are a lot of options for these. |
05:40 | But, a field is a fieldname. |
05:42 | So the first one is going to be "ID". |
05:45 | The type is the data type, that you want to store this field in. |
05:49 | Anything that goes into it must be added here to this datatype. |
05:54 | "varchar" which stands for variable characters is quite common. It is a very useful one and it requires a length. |
06:00 | We can have 25 characters long here. |
06:03 | 50 characters long. |
06:02 | Or 100 characters long. |
06:04 | Or 1 character long. |
06:07 | Actually we are just storing the type and the length of the data stored. |
06:14 | It helps in storing, for example your firstname. |
06:17 | Lets say our fieldname here is "firstname" and I have a "varchar". |
06:24 | There is no point in typing in 500 characters because we will be using unnecessary amount of data. |
06:32 | A typical firstname will be no more than 25 characters. |
06:36 | Even if it is, it will not be more than 30 or 35 characters. |
06:41 | But for now I will store my "firstname" as 20 to 25 characters and I will put 20 here. |
06:48 | Our "ID" will be an integer because it is a number. |
06:53 | It will be self incrementing. |
06:55 | This will be 1,2,3,4 |
06:57 | The amount of records we use. |
07:00 | And we have some other options here. |
07:03 | That is here is primary key. |
07:05 | We are going to select it and at extra, we can see that we got "auto underscore increment". |
07:11 | This is an auto increment. |
07:13 | It will give this particular function. |
07:16 | Whenever you enter a new record, this will also automatically go up. |
07:21 | So here we have "firstname". |
07:23 | We have "lastname" and again I will set this as 30. |
07:27 | And what else do we have??? |
07:29 | We have "age" and obviously this is an integer and we have "gender". |
07:34 | Ok. |
07:35 | Now here instead of "age", I will say say "Date of birth". |
07:40 | So this is Date of Birth. |
07:43 | I will set this as date. |
07:45 | Here I am trying to find a date datatype and I will see how this works. |
07:51 | So our length for date doesn't have to be set here. |
07:54 | We have a standard format for this. So we don't have to worry about that. |
07:58 | Now I will set the "gender" as "varchar" of character 1. |
08:05 | Now we can store "M" for male and "F" for female. |
08:12 | Ok. If we go across here, we can see that there are a lots of options. |
08:16 | You can comment this yourself. |
08:19 | You can remind yourself what this field does. |
08:22 | But usually name your fieldname appropriately so you know what data you are saving. |
08:28 | Ok. Here I will click on "Save" and you can see that "people" has appeared here. |
08:35 | This will ask you a query here. |
08:38 | Now when I was talking about command line earlier, this is what you have to type to create that. |
08:46 | However, we have used a graphic user interface to save ours. |
08:50 | We can see down here, we have our fields, our types and our collation attributes, null data for example. |
08:59 | The default value that is stored as.... say for example if you had a field saying "Has the user registered?" |
09:07 | Or anything of your choice. You could use the default here too. |
09:11 | For example if I wanted to store everyone, I have registered here as male by default or female by default, I could type "M" or "F" here. |
09:21 | And we have auto increment here and also some other data that we don't need to know about in this tutorial. |
09:28 | Ok, here we have created our table and if you go in part II of this, I will show you how to insert some data and also how to retrieve this data from your database using php. |
09:40 | Join me in part 2. This is Evan Varkey dubbing for the Spoken Tutorial Project. (Script contributed by Juanita Jayakar). |
Contributors and Content Editors
Minal, PoojaMoolya, Pratik kamble, Sakinashaikh, Sandhya.np14, Sneha