17 | Create Database Tables in MySQL PHP Tutorial | 2023 | Learn PHP Full Course for Beginners

  Рет қаралды 50,562

Dani Krossing

Dani Krossing

Күн бұрын

In this PHP tutorial I will talk about how to create a MySQL database table, so we can insert data into our newly created database! 🙂 This will be a lon lesson, and I will have chapters bellow the video for easy navigation. 😉
I will cover MySQL tables, including data types, primary keys, foreign keys, and table relationships. 🙂 So there is quite a bit to learn in this video.
➤ TIMESTAMPS
00:00:00 - Introduction to tables
00:04:02 - SQL data types
00:15:42 - SQL SIGNED & UNSIGNED
00:17:20 - Creating our first table
00:26:48 - SQL PRIMARY KEY
00:29:58 - Creating our second table
00:32:28 - SQL FOREIGN KEY
00:35:56 - SQL ON DELETE
➤ GET ACCESS TO MY LESSON MATERIAL HERE!
First of all, thank you for all the support you have given me!
I am really glad to have such an awesome community on my channel. It motivates me to continue creating and uploading content! So thank you!
I am now using Patreon and KZbin Memberships to share improved and updated lesson material, and for a small fee you can access all the material either from my memberships or Patreon, depending on your preference. I have worked hard, and done my best to help you understand what I teach.
I hope you will find it helpful :)
Memberships: / @dani_krossing
Patreon: / mmtuts

Пікірлер: 71
@Dani_Krossing
@Dani_Krossing Жыл бұрын
Hi everyone! Sorry about the long break 🙂 For people who check my community posts, you'll know that I have had to take care of Frida (my dog), who had been extremely sick for the past few weeks. Unfortunately she didn't make it, so I needed some time to deal with all that... But I'm back again now. 🙂
@samnako
@samnako Жыл бұрын
Sorry bro for the loss
@yousifky
@yousifky Жыл бұрын
😢
@gensys244
@gensys244 Жыл бұрын
😢Sorry to hear this all the best
@johnellempuerto3659
@johnellempuerto3659 Жыл бұрын
:(
@GerritforBazeja
@GerritforBazeja Жыл бұрын
Sorry to hear. Can imagine you needed some time to it.
@ingelegenial
@ingelegenial 3 ай бұрын
You are underrated, Daniel. Thank you for everything.
@Killer-ke6ff
@Killer-ke6ff 8 күн бұрын
Man you're a savior I have a web development course and you are saving me time and I actually understand you well Thanks for your efforts
@theSassySquatch
@theSassySquatch 9 күн бұрын
Dani, you are awesome! You are a great teacher! Thank you for your videos!
@decall
@decall Ай бұрын
I am so sorry to hear about your dog. We recently lost a cat and almost also our dog (but he went well fortunately). I love your lessons... Learned a lot of it...
@davescorneroftheworld1147
@davescorneroftheworld1147 Жыл бұрын
Very sorry for your loss. I am not a dog lover but I have lost a few cats in my 73 years so I understand your pain. THANK YOU FOR ALL YOU DO ON THIS TOPIC. I have learned so much from you.
@SamBoxEthiopia
@SamBoxEthiopia Ай бұрын
Learning php at 73??? You're my Hero.
@davescorneroftheworld1147
@davescorneroftheworld1147 Ай бұрын
@@SamBoxEthiopia Thank you SanBox Ethiopis, I am NOT a Hero! I started out with electricity “talking to me”. Just into high school (in about 1966 or so) I decided I was to lazy to go across the room to turn my TV on and off. I made a WIRED remote control that would turn the TV on and off along with changing the volume. In 1966 NOBODY had ever heard of remote control on TV’s. After high school I went to an electronics school. In 1971 I was a certified electronics technician in the state of Missouri. I only did that for about three years of so. Then I went to work as a welder, with many welding jobs throughout my life. In about 1978 or 79 I started working at of the Pacific Northwest biggest saw mills. In 1983 I touched my FIRST computer. Make sure you get the date right. That was BEFORE Bill Gates was a household name. I have been addicted to them DAMN things every since. I welded in several jobs until about 2003 or so. Then I became a videographer, not long after that I got several jobs as a professional videographer. I retired in 2013 (or so I thought) I still have three to seven video shoots per year, I also help out friends out welding all the time. Soooo, now WHY NOT learn PHP. I am doing pretty well but I will probably never make any money with PHP. After all who wants to hire a 73 year old man. Besides that, I DO NOT WANT A FULL TIME JOB. So here I am setting in front of my two 27” monitors with a gaming system that is very very powerful. NO, I am not a gamer. But like I said I am addicted to computers. So I am not a hero by any means. Just someone that NEVER figured out what to do with my life. (:
@UHDking
@UHDking Жыл бұрын
Thanks for the freshest mySQL tut from the god of programming tuts(the best one was New Boston but he does not make any tuts anymore for a long time and this is a fresh vs his 2013). Love your tuts Dani and thanks for your time. You are the best on KZbin.
@akashgola2153
@akashgola2153 2 ай бұрын
Sorry to hear about Frida. Hopefully ur over it now. The video was amazing as always. Also what i am liking the most is the logics or practicality inside ur videos. Great Work Keep going🔥
@samnako
@samnako Жыл бұрын
I'm glad this video is out now when i am trying to design a new website and I will definitely pick one or two knowledge to add to what I'm doing right now. Thank you Daniel
@ArgieHista
@ArgieHista Жыл бұрын
Here I am again... Watching your videos and learning for something that no one can taught me easily but You... Thank you for sharing your knowledge.. Godblessed 🙏
@jackiedavis5574
@jackiedavis5574 4 ай бұрын
You are just the best!! Amazing delivery, simple logical explanation - you have freed me from my exasperation with my websites! Been looking for way to learn to do logins and comments on my site. (I hate those non-verbal, canned music, no explanation videos) but you are phenomenal! Forget binging tv shows, I am binging your tutorials!! Thank you so much! - and I am so sorry about your pup :(
@benjicanones1454
@benjicanones1454 11 ай бұрын
Superb!
@x6c3
@x6c3 10 ай бұрын
very help for a beginner ❤
@renatusrichard
@renatusrichard 2 ай бұрын
Thank you so much sir, have enjoyed the lesson
@jd2722
@jd2722 2 ай бұрын
This is awesome, thank you!
@dusandrazevic
@dusandrazevic Жыл бұрын
Thanks for the video
@sungodd63
@sungodd63 5 ай бұрын
Very nice video. I was so into it
@bilalbeny4172
@bilalbeny4172 4 ай бұрын
thank you my brother 😍😍
@armandoWebDev
@armandoWebDev 6 күн бұрын
Daniel, correct me if I'm wrong, but I read that VARCHAR has tha capability to take a VARIABLE amount of memory, so if we define (30) characters this doesn't mean that will reserve that space in memory, it is just the maximum amount of memory/characters can take in one spot but if you store let's say, 10 characters in a VARCHAR(30) will just consume 10 characters space in memory. Hope my idea is clear. Thank you for your course.!
@sundayemmanuel4789
@sundayemmanuel4789 6 ай бұрын
Thank you
@fotonext7441
@fotonext7441 9 ай бұрын
FOREIGN KEY REFERENCES must be PRIMARY KEY in the parent table, or can it be any column?
@user-ug9gr3ne1s
@user-ug9gr3ne1s 3 ай бұрын
Maybe we have several IDs in the users table. On what basis does the database value users_id?
@omarghabawi1913
@omarghabawi1913 7 күн бұрын
Hi, I followed your instruction and encountered an error. The database did not accept CURRENT_TIME; instead, it accepted CURRENT_TIMESTAMP. Is there a different syntax to resolve this error? I am also using phpMyAdmin like you. Thank you!
@yousifky
@yousifky Жыл бұрын
❤🎉
@noelradhakrishnan4423
@noelradhakrishnan4423 7 ай бұрын
I have a doubt though, shouldn't we refer the username from the users table as a foreign key to the comments table?
@pain7359
@pain7359 4 ай бұрын
What if, I want to make a note pad project, do i need to make a database for it?
@IEmirovic
@IEmirovic 10 ай бұрын
Thanks Dani. I have a question. Do we need "username" column inside comments table? We can reach "username" column inside users table with "join" querys. Because we defined foreign key. Thanks again.
@Dani_Krossing
@Dani_Krossing 10 ай бұрын
You are correct, you would be better off doing a inner join SQL statement. 🙂
@ASmallGreenBean
@ASmallGreenBean 10 ай бұрын
​@@Dani_Krossing Thanks! I had the same question. But to clarify a bit more, we don't need to add the "username" column in the "comments" table, right? We can just reference it to the "users" table through the foreign key "users_id", correct? Is there any reason to actually have this kind of "redundant" information in a database table? (On that matter, do you have any video about the key principles of structuring your SQL database? - With your teaching skills, I might finally be able to grasp that... 😅) Oh, and thank you so much for all this useful information and the perfectly structured course!!
@TOMAKAIROS
@TOMAKAIROS 9 ай бұрын
im getting this error.... #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CURRENT_TIME, PRIMARY KEY (id) )' at line 6 is my version too new??? or is it too old? how do i check the version?
@Dani_Krossing
@Dani_Krossing 9 ай бұрын
What is the full SQL that you tried to submit?
@TOMAKAIROS
@TOMAKAIROS 9 ай бұрын
@@Dani_Krossing I’m not sure what you mean by that but I did everything that’s in the video. It seems it only works if I do CURRENT_TIMESTAMP instead of CURRENT_TIME. Is there a difference?
@hortensiamusic6670
@hortensiamusic6670 3 ай бұрын
​@@Dani_Krossing I have the same problem: CREATE TABLE users ( id INT(11) NOT NULL AUTO_INCREMENT, username VARCHAR(30) NOT NULL, pwd VARCHAR(200) NOT NULL, email VARCHAR(100) NOT NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIME, PRIMARY KEY(id) );
@user-ge1sq3nx1z
@user-ge1sq3nx1z 2 ай бұрын
We have the username in both the users table and the comments table? Is that ok? Seems to defeat the point of the relational db.
@hellofromiqbal
@hellofromiqbal 2 ай бұрын
Including the `username` column in the `comments` table alongside the `users_id` foreign key column depends on your specific requirements and design considerations. Having the `username` column in the `comments` table can be beneficial in scenarios where you frequently need to display comments along with the username without having to join the `users` table every time. This denormalization can improve query performance, especially in cases where you're frequently retrieving comments and displaying them with usernames, as it eliminates the need for a join operation. However, if you're concerned about data redundancy or prefer a more normalized database design, you can omit the `username` column from the `comments` table and rely solely on the `users_id` foreign key to associate comments with users. In this case, when you need to display a comment along with the username, you would perform a join operation between the `comments` and `users` tables to retrieve the username. In summary, whether to include the `username` column in the `comments` table depends on factors such as performance considerations, data redundancy, and your specific application requirements. Both approaches are valid and have trade-offs that you should consider based on your particular use case. At least this is what I got from chatGPT lol.
@MohammedAlziko
@MohammedAlziko 5 ай бұрын
😘😘😘
@houssainhafed4180
@houssainhafed4180 Жыл бұрын
pls create Laravel course
@techgamer734
@techgamer734 9 күн бұрын
I am getting error that Foreign key constraint is incorrectly formed
@Dineshsharma-ec6ys
@Dineshsharma-ec6ys Жыл бұрын
Why php is dying language? And why people are running after javascript frameworks?
@samnako
@samnako Жыл бұрын
But Daniel, how do i join your patreon's? I live in Lagos, NIGERIA and I need to do so to support your works.
@Dani_Krossing
@Dani_Krossing Жыл бұрын
If you would like to join, there is a link for either my Patreon, or my KZbin memberships, in the bottom of the description. 🙂
@MoosicLayf
@MoosicLayf 3 ай бұрын
My professor always use the timestamp on creating a timestamp, how ddoes that makes a difference if i use datetime?
@typo368
@typo368 9 ай бұрын
Mine is throwing errors at the "DATETIME" statements in both tables, i deleted both of them and is good?
@TOMAKAIROS
@TOMAKAIROS 9 ай бұрын
im getting the same error.... did you find the solution? this is my error #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CURRENT_TIME, PRIMARY KEY (id) )' at line 6
@fathimaifla9215
@fathimaifla9215 Жыл бұрын
Pls upload a video for front end connected to back end use insert delete upload select update every things in one video . I'm a software engineer student . Your videos are very useful for me
@Dani_Krossing
@Dani_Krossing Жыл бұрын
Once I'm done with this MySQL part of the course, the plan is to teach that. 🙂 I do have a older PHP course that shows it too, if you need it now.
@fathimaifla9215
@fathimaifla9215 Жыл бұрын
Please do python language also
@fathimaifla9215
@fathimaifla9215 Жыл бұрын
​@@Dani_Krossing I need complete video of web-based application design with your explanation. I think it's useful for student
@RelateAndElevate
@RelateAndElevate 10 ай бұрын
Do you have paid courses in Udemy?
@ShootYourBricks
@ShootYourBricks Жыл бұрын
What happens when the auto increment reaches the max allowed number?
@Dani_Krossing
@Dani_Krossing Жыл бұрын
Your data will “overflow” and create errors. But unless you plan on creating a website that uses billions of rows in one table, that won’t happen. IF you plan on having more rows than a INT has storage for, then just use BIGINT instead for the id 🙂 Or if you plan on creating a HUGE commercial site like Facebook, which literally stores billions of messages a day, I can imagine they use custom databases with multiple databases specifically for messages only hehe.
@ShootYourBricks
@ShootYourBricks Жыл бұрын
@@Dani_Krossing interesting. Yeah I don't plan on ever having 4 billion users on a website lol
@davescorneroftheworld1147
@davescorneroftheworld1147 Жыл бұрын
At 29:08 of this video when you created the TABLE, just above you we see two tables. "New" and "users", where did the "New" table come from?
@Dani_Krossing
@Dani_Krossing Жыл бұрын
That’s not a table 🙂 that’s a button you can click to create a new table
@davescorneroftheworld1147
@davescorneroftheworld1147 Жыл бұрын
@@Dani_Krossing OK. Thank you very much for your time.
@bilalbeny4172
@bilalbeny4172 3 ай бұрын
I just have one note, by default when we define a column as a primary key, its is impossible to be null and must be unique, in other words: PRIMARY KEY = NOT NULL + UNIQUE, so we can not use NOT NULL constraint with a column when it's a primary key.
@Trunk_Tech
@Trunk_Tech 8 ай бұрын
Why did we not use the field "ID" (PRIMARY KEY) in the Comments table as the FOREIGN KEY in references rather than creating user_id Field to act as a FOREIGN KEY ??
@Dani_Krossing
@Dani_Krossing 8 ай бұрын
Because the ID has to be unique to that particular entry, and not based on other tables. Otherwise a bunch of issues can happen. Primary Keys should not be Foreign Keys.
@heinzerbrew
@heinzerbrew 3 ай бұрын
What's the point of having an id when you already have a unique username?
@Dani_Krossing
@Dani_Krossing 3 ай бұрын
The ID is for the table row, which is different. There HAS to be a unique id for all rows of data, which isn’t up to the user to decide. Having the ID be a number, also makes it easier to list them all out if needed.
@henryuchenna7785
@henryuchenna7785 5 ай бұрын
Am getting user_id error.
How to Connect HTML Form with MySQL Database using PHP
7:09
Technical Babaji
Рет қаралды 2,3 МЛН
狼来了的故事你们听过吗?#天使 #小丑 #超人不会飞
00:42
超人不会飞
Рет қаралды 58 МЛН
CAN YOU HELP ME? (ROAD TO 100 MLN!) #shorts
00:26
PANDA BOI
Рет қаралды 36 МЛН
6 SQL Joins you MUST know! (Animated + Practice)
9:47
Anton Putra
Рет қаралды 87 М.
Learn SQL Basics in Just 15 Minutes!
16:57
Kenji Explains
Рет қаралды 99 М.
MySQL: AUTO_INCREMENT is awesome
3:55
Bro Code
Рет қаралды 48 М.
狼来了的故事你们听过吗?#天使 #小丑 #超人不会飞
00:42
超人不会飞
Рет қаралды 58 МЛН