Basic PHP Programming Tutorial 27: MySQL Databases Part 1
Key Takeaways
This video tutorial covers the basics of working with MySQL databases in PHP, including creating a database, adding tables, and connecting to the database using PHP scripts. The tutorial uses a simple example to demonstrate how to create a table, insert data, and browse the database.
Full Transcript
hello and welcome to the 27th php tutorial this tutorial we're going to be discussing uh working with a database uh depending on who you're hosting is setting it up is pretty much the same usually you'll just go to hosting and then like databases add a database and you can pick the database name you pick a username and a password for now our database name is epic name there is no table within it uh and then we've chosen a password so what we're gonna do is go over creating a table a database is really a collection of tables and then within the tables a table is just like a spreadsheet like an excel spreadsheet so let's make this a epic table and the number of fields we're going to have we'll just make two fields for now and you'll hit go and that'll make you get the option to set this up so the first field we're going to say is uh we'll say name and this will be the person's name and here you choose the type of data that's going to be in this case it'll be text and leave that all blank this next field is going to be age age is going to be an integer and the rest will just leave blank again and we'll come over here that's good so now we'll just say um save okay folks if you add a field here it'll add another field it's really easy to hit go but yeah if you got to this point you're like oh shoot i really want to add one more then you add more what a lot of people will do too is have a primary key which is a self-incrementing um id basically but this is just a basic tutorial i just want to show you guys how to connect and use a database so anyway we're going to go ahead and save this and we have now created the table epic table and so within this table you can see we've got an a our name and age so we can store um name and age data so if we go to browse well i guess we can't browse because there's no there's nothing in our database yet so we need to put something in it so let me insert so let's just insert some data so we'll say uh name interesting name we'll say well we already went over this harrison that's my name and then we'll do uh age we already discussed this i'm 99 so we'll hit go and now we have an inserted row so when we go to browse the database we can see this is our database table here we can see okay we've got uh name harrison age 99 so we have one entry into our database so now let's discuss how to connect to the database and actually start maybe inserting and then maybe reading from the database as well so let's hop right in into that so now back to our php script what we want to do is connect to that database so the best way to do that is let's leave the i guess we'll leave the header there and now what we want to do is specify the information to connect to it you could type it all in here like this but it's best just to store this into variables so we'll go ahead and do sql host equals what then we'll do sql user equals what and then we'll do sql pass equals um what okay oh and make sure you put your semicolons here so now we want to go ahead and define uh these parameters here so the host name is the ip address if you're using your own uh if you've got xampp or whatever on your computer and apache then this will just be a local host but otherwise you can find that server address just by right here it's this ip so you'll come back over to your script and that's what go is going to go in there in this case it's 5063 2326 seven then the username and password is whatever you defined whenever you made it in my case uh it's gonna be epic name and then it's gonna be epic pass now i know someone's going to definitely uh try to connect uh to this with these parameters whenever i'm done with this video but i will be deleting all these and this username won't exist anymore so don't waste your time anyway um continuing on that's what we're gonna fill in there and then in here with these parameters you're just gonna fill in uh this so first you've got sql underscore host then you've got sql underscore user and then finally you have sql underscore pass so now what this is going to do is we'll connect using these parameters and if it can't connect it'll just exit and say failed to connect to the database otherwise it's going to say connected so now we'll save that we'll run it and we'll pop over here or refresh and sure enough we've connected to the database now that we have you know good parameters in here now once you've connected the database the next thing you need to do is connect to the table and with that i'm going to continue uh connecting to the table in the next video as always thank you for watching thanks for your support your subscriptions and until next time
Original Description
Link to the full playlist:
http://www.youtube.com/playlist?list=PLQVvvaa0QuDcYpcjrNB43_iKqla5UeQw_
Sentdex.com
Facebook.com/sentdex
Twitter.com/sentdex
Intro to mysql databases and php
Playlist
Uploads from sentdex · sentdex · 39 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
▶
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
Python Encryption Tutorial with PyCrypto
sentdex
Python's Logging Function
sentdex
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
wxPython Programming Tutorial 4: Panels
sentdex
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
wxPython Programming Tutorial 8: Custom Button Images
sentdex
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
Basic PHP Tutorial 12: Associative Array
sentdex
Basic PHP Tutorial 14: Foreach loop
sentdex
Basic PHP Tutorial 16: Include and Require
sentdex
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
Basic PHP Tutorial 4: Variables and Comments
sentdex
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
Basic PHP Tutorial 1: Intro to PHP
sentdex
Basic PHP Tutorial 3: HTML with PHP
sentdex
Basic PHP Tutorial 9: While Loop
sentdex
Basic PHP Tutorial 10: Switch Statement
sentdex
Basic PHP Tutorial 2: Print and Echo
sentdex
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
Basic PHP Tutorial 19: Finding words in strings
sentdex
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
Basic PHP Programming Tutorial 24: String similarity
sentdex
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
Sikuli Tutorial 1: Visually programming in python!
sentdex
Sikuli Tutorial 2: Program visually in python!
sentdex
Sikuli Tutorial 3: Program visually in python!
sentdex
3D Bar Charts in Python and Matplotlib
sentdex
3D Plane wire frame Graph Chart in Python
sentdex
Raspberry Pi Part 1 Introduction
sentdex
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
Raspberry Pi Part 11: Remote Desktop
sentdex
Twitter Analysis: How to rank a user's influence
sentdex
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex
More on: Backend Performance
View skill →Related Reads
📰
📰
📰
📰
This Week In PHP Internals | August 26, 2026
Dev.to · Len Woodward
Debugging Async/Await Deadlocks in JavaScript – A Step‑by‑Step Guide
Dev.to · Deep Fix
The Matrix of STL: Surprising C++ Data Structures Every Competitive Programmer Needs
Dev.to · Timevolt
Stop Installing Libraries: 13 Native APIs That Went Baseline in 2026
Dev.to · Gos
🎓
Tutor Explanation
DeepCamp AI