Тёмный

36: How to connect to a database in PHP | PHP tutorial | Learn PHP programming 

Dani Krossing
Подписаться 472 тыс.
Просмотров 724 тыс.
50% 1

How to connect to a database - PHP tutorial. Today we are going to learn how to connect to a database from a website using PHP. In these lessons we will learn how to access a database, and how to get data from a database.
➤ 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 to share improved and updated lesson material, and for a small fee you can access all the material. I have worked hard, and done my best to help you understand what I teach.
I hope you will find it helpful :)
Material for this lesson: / lesson-material-42361704

Опубликовано:

 

12 июл 2017

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 276   
@brandonneilsta.teresa3494
@brandonneilsta.teresa3494 3 года назад
Finally, a PHP tutorial video I can watch without cringing.
@Scuffy
@Scuffy 2 года назад
Why would you cringe? just curious.
@cancerousryan7272
@cancerousryan7272 2 года назад
@@Scuffy because he's racist
@Scuffy
@Scuffy 2 года назад
@@cancerousryan7272 makes sense
@mrtin-voe
@mrtin-voe 2 года назад
I can watch this barely without crying.
@billb6283
@billb6283 5 лет назад
Nice video. Quick and to the point. I wrote my 1st PHP programs almost 20 years, the end of 2000...before RU-vid existed. But haven't done much with PHP since. My web server is set to use version 5.3, which is unsupported, so my old programs will run. My old PHP programs need updating to run version 7. Surprise, surprise...things have changed. The old connection method no longer works. This and the next video, helped. Thanks!
@QuesoSlam
@QuesoSlam 3 года назад
I like the way you demonstrate and explain. Creating an interface for a database has been difficult for me. For some reason, there’s always something I’m missing. My code looks right, but it doesn’t work. I am looking forward to going through your other videos on this topic. Thanks!
@Klenric
@Klenric 5 лет назад
Great tutorial, well explained. How would you secure the DB handler pages from someone seeing the source. Is it based on permissions to the file on the server or by preventing access to this page on the web server configuration? Or some other way. Thanks.
@dogiap8561
@dogiap8561 2 месяца назад
tks for sharing this lesson, i was stuck with how to connect my db for my school job, love you
@aplemancao8080
@aplemancao8080 2 года назад
Applause to you sir. Thanks for sharing & teaching your programming ideas, I have learned well through your tutorials 🥰
@johanmbaabu1580
@johanmbaabu1580 10 месяцев назад
thanks man u are a legend. Young programer here from Kenya .
@Dani_Krossing
@Dani_Krossing 10 месяцев назад
I have a newer 2023 course on my channel 😊
@nazifasadia5705
@nazifasadia5705 3 года назад
Such a clear explanation man...!! Loved it very much. Thank you for making such a informative video.
@realzire
@realzire 6 лет назад
Love your tutorials! I learnt html thanks to you!
@teryphlp
@teryphlp 3 года назад
Really awesome. I am a beginner I really learned a lot . Highly recommended.
@jlambert12013
@jlambert12013 3 года назад
That was so much easier than I was expecting
@ujwalc9226
@ujwalc9226 5 лет назад
I've already downloaded the whole playlist I've come back to thank you great job guys even if u know the topic ,still watch the vedio to the end u will get new ideas to build Ur webpage.
@umrbekmatrasulov4141
@umrbekmatrasulov4141 4 года назад
can you explain why in included php files tag php was not closed
@hahehi682
@hahehi682 4 года назад
@@umrbekmatrasulov4141 to make the php file pure.
@umrbekmatrasulov4141
@umrbekmatrasulov4141 4 года назад
@@hahehi682 pure?
@umrbekmatrasulov4141
@umrbekmatrasulov4141 4 года назад
@@hahehi682 can you explain with more detail?
@CsharpQelly
@CsharpQelly 4 года назад
@@umrbekmatrasulov4141 The ?> close tag is not really necessary when PHP code is the only content of the document.
@guylemay1471
@guylemay1471 5 лет назад
My goodness... I should have watched your tutorials on the subject years ago - thank you!
@amirrezamoraveji4160
@amirrezamoraveji4160 5 лет назад
I can relate to that
@amarjeetsingh0624
@amarjeetsingh0624 3 года назад
sir i have'nt seen tutor like you , you r the great sir
@mcqueen_sportsmedia
@mcqueen_sportsmedia 4 года назад
Great video!!! It really helped me out A LOT! Thanks!
@excelapplications6969
@excelapplications6969 5 лет назад
Great explanation. Thank you!
@mikegerow4937
@mikegerow4937 5 лет назад
Great videos!!! Great explanations, easy to understand and very well taught Thank you
@umrbekmatrasulov4141
@umrbekmatrasulov4141 4 года назад
can you explain why in included php files tag php was not closed
@shayansaeed2765
@shayansaeed2765 3 года назад
@@umrbekmatrasulov4141 Cuz it was a pure php file
@zahraaliux
@zahraaliux Год назад
I've learned from you in one day what I couldn't get from college teacher in 4 months
@harlanreece2348
@harlanreece2348 Год назад
Your information is so on point and easy to understand.
@aleemahmed1863
@aleemahmed1863 4 года назад
question, how do i pass this $conn to a function so that i can use it to run an sql statement within that function?
@jasminev3436
@jasminev3436 4 года назад
Thank you so much! amazing tutorial!
@jaynostulop2476
@jaynostulop2476 3 года назад
I can now understand while looking on the screen.
@RiazKhan-uv9wx
@RiazKhan-uv9wx 5 лет назад
thank you so much . It's really good tutorials
@irenerosejohnson8346
@irenerosejohnson8346 2 года назад
Nice tutorials ... helped a lot ...crisp and clear... keep going👍👍
@RagHelen
@RagHelen 5 лет назад
Put that include in a directory above root (above www), not below, and make the variables constants.
@kithinga
@kithinga 4 года назад
you just know how to teach..thanks a lot
@sharonglendale8439
@sharonglendale8439 4 года назад
Thank you :D Great video.
@ziadbohlok7632
@ziadbohlok7632 3 года назад
beast♥♥♥ im watching u from lebanon keep it up
@EdwardHood
@EdwardHood 4 года назад
How do you initialize multiple connections to multiple databases? I have form fields that come from other physical databases.
@05renemar1
@05renemar1 6 лет назад
Lol, after the previous episode, your voice changed from energetic to a more grown man from this new episode XP
@johnberns8917
@johnberns8917 3 года назад
ReneMar Remorosa they grow up so fast
@chaddsmith3354
@chaddsmith3354 2 года назад
Thank you for the video!
@isthiswil
@isthiswil 4 года назад
Hello, could you try to make a video on user profile pages. What I mean by this is: when a user registers for the first time, it makes a new page for the user and displays information about them (avatar, username etc). If the page is about them, then they can edit information in some sort of settings section or something along those lines. Would mean a lot, as I cannot find anything else on the internet or youtube. Thanks, Will.
@niekbeijloos8355
@niekbeijloos8355 4 года назад
Very nice! Thank you !
@luiscarlosmartinez3034
@luiscarlosmartinez3034 2 года назад
Thank you! Gracias! Obrigado! 🙏🏽🔥
@stephene8315
@stephene8315 2 года назад
Hi sir! I'm a beginner in webdev. How many tables in database do I have to create for a website? Will it affect how the website response/loading?
@mainakray6452
@mainakray6452 3 года назад
awesome video , nice explanation
@manwoman4678
@manwoman4678 Год назад
Is it neccesary to declare variables for the 4 parameters? I see other videos just straight putting localhost, root, pw, dbname in the parameters.. Or is it just a good practice? Is there a difference?
@iconsworld9
@iconsworld9 2 года назад
THANK YOU VERY USEFUL< AFTER ALL THOSE YEARS< AND TIME EVERYTHING IS JUST A MATTER OF TIME.
@umarar6025
@umarar6025 4 года назад
What did you use to write down this code ? where are u writing it ? i wanna connect using PHP PDO to PostgreSQL Database but i don't know where to start
@ador989
@ador989 Год назад
this what i need, thank you
@sktrickandtreat5540
@sktrickandtreat5540 2 года назад
Great video ❤️
@pianoLee-sx9dx
@pianoLee-sx9dx 6 лет назад
This is great.. So, if you have it written in the incorrect order, it won't connect?
@brunosantos7193
@brunosantos7193 6 лет назад
Thank You very much
@mar4974
@mar4974 5 лет назад
great tutorial
@josephlivengood4508
@josephlivengood4508 5 лет назад
At 3:25 if I am using a wordpress site, can't I get this same information from the wp-config.php file?
@TimArdan
@TimArdan 6 лет назад
mmtuts, what sublime theme are you using?
@probutcher3308
@probutcher3308 4 года назад
Hello sir Why i cant include my folder It name was addtion then the php file name is db and the code doesnt read it?
@errolprince5112
@errolprince5112 2 года назад
must thank you for your video
@zahidhasan5417
@zahidhasan5417 5 лет назад
very helpful video
@yaMuntaqim
@yaMuntaqim 6 лет назад
do we really need to create the four variables on the top? I found some examples where they has not been created so I just want to have clarity on this. Well - I think this is a good practice + makes it easier to understand to others, but it's never wrong asking:)
@hohojimmy4443
@hohojimmy4443 5 лет назад
I have a question is that how did I do to link other server?just need input ip? Thank your response.
@shakawatshooan8418
@shakawatshooan8418 3 года назад
আয়ায়ায়া +র
@jazmineemiemariegueco
@jazmineemiemariegueco 5 лет назад
Hi. I just want to ask, when I am establishing a connection between database and php. It gives me error because it doesn't read the $conn. Why is that so? Please help me.
@arifrk
@arifrk 4 года назад
Hi. In this video you show connection between PHP and mysql using XAMPP, but i want to connect my php with Mysql database without using any local server (Xampp, Apache, etc). can you give me solution?
@_sbmangiepangie6982
@_sbmangiepangie6982 2 года назад
It worked!
@M1sterE321
@M1sterE321 4 года назад
What even is the type of program you're using to code the connection?
@RicardoManuelArana
@RicardoManuelArana 3 года назад
Hey, I'm still learning, but this is actually not to connect but to link a database to a site, right?. I mean, this is like the first step, declaring the database, it's not like when you log in or sign up, right?.
@hijabzainab5632
@hijabzainab5632 2 года назад
what changes will i have to make in this code if it was for sqlite instead of mysql
@lucasferreira8229
@lucasferreira8229 Год назад
Which one do companies use more at work, MYSQLI or PDO?
@amirahassan9213
@amirahassan9213 3 года назад
you r perfect thank you
@AbhimanyuNaikareWebDeveloper
@AbhimanyuNaikareWebDeveloper 5 лет назад
Hello dear. Atlast i find a very good php tutorial! Now can you please suggest a tutorial on - 1) how to design the database on complex projects.
@senju31
@senju31 5 лет назад
I am yet to find one like this.
@khairelfarish
@khairelfarish 5 лет назад
Hi, how do i know my server name because I'm installing mysql in my linux server. What to replace with the 'localhost'?
@universenerdd
@universenerdd 3 года назад
localhost refers to your computer, this is default, but i don't really know so...
@ashishgangajaliya9266
@ashishgangajaliya9266 4 года назад
I use database connection string in a class. When access it in another file it returns null. help me to solve it.
@danielwatson6529
@danielwatson6529 2 года назад
where would you put your includes folder in the Wordpress Stack?
@kevgits
@kevgits 5 лет назад
Finally, someone who speaks English...phew!
@QuesoSlam
@QuesoSlam 3 года назад
Yes! Those other guys may be good, but there are so many people I can’t understand. My ear is not tuned to their accent.
@scene-famous
@scene-famous Год назад
Exactly. The others may be teaching good stuff but I can't understand that kind of English.
@surinfarmwest6645
@surinfarmwest6645 6 лет назад
I was using your previous method:-
@sijjadawann
@sijjadawann 5 лет назад
So nice video
@kaptennick6352
@kaptennick6352 3 года назад
Amazing tutorials! It is almost TOO EASY! Ι have a question thought what theme are you using for your code?
@siddharthk4345
@siddharthk4345 2 года назад
It's sublime text editor
@ShuyanStoryTeller
@ShuyanStoryTeller 5 лет назад
It's great.
@joneseugene301
@joneseugene301 6 лет назад
Thanks .can you do a video on how to make your files downloadable using php
@policeuac
@policeuac 4 года назад
Please make a database video with PDO :)
@nogafouz2174
@nogafouz2174 2 года назад
MERCI BEAUCOUP
@Hiturion
@Hiturion 4 года назад
What does $conn variable return? Boolean (connected/connected) ?
@briansenior4910
@briansenior4910 6 лет назад
great videos, can you show us how to host a php website on hostgator that uses a database
@bortyyful8566
@bortyyful8566 5 лет назад
what application you use to create that
@itzycombi
@itzycombi 3 года назад
Hi, came accross this video after searching way how to secure password of username used in connecting to database. Our IT windows server admin has access to our server and has access to read our php folder. They able to read the user and password defined in configuration. By any chance, cost free :) do you have idea how to mask or hash the password? Hope you will answer this pls.
@gauravbhandari1184
@gauravbhandari1184 4 года назад
Helpful
@assmabenmussa4228
@assmabenmussa4228 5 лет назад
great tutorial as usual! i have a question, why did you write include_once and not the regular include? what is the difference?
@Dani_Krossing
@Dani_Krossing 5 лет назад
include_once makes sure that if we accidentically include the same file twice on the same page, then we get an error. This is to avoid having duplicate code.
@assmabenmussa4228
@assmabenmussa4228 5 лет назад
mmtuts oooh I see, thank you very much for taking the time to reply to me. You are awesome! :)
@taniyapreetsingh
@taniyapreetsingh 6 лет назад
Hi mmtuts, I really liked you videos, also your voice soo cute.. lol... it really helps me alot to learn php in easy way. I am having a simple request.. PDO login & register form (CRUD) along with facebook login (SDK) Pl its a request. Reply back
@pranabmedhi4676
@pranabmedhi4676 6 лет назад
sir,can you please make a video on creating a user profile in php?
@arielleariella3487
@arielleariella3487 4 года назад
I have already installed xampp and created a database. Now i have created a separate php form for connecting my HTML form to the database but when I try to execute it the php script is displayed by the browser instead......how can I connect my login form to the database please?
@xiehper4586
@xiehper4586 4 года назад
can i still use mysql instead? i do not have mysqli..
@ronaldjohnson4470
@ronaldjohnson4470 5 лет назад
Thank you mmtuts for the tutorial. When I tried to connect to the database I am getting the message: Warning: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] I have spent several hours trying to figure the problem. Any ideas? thanks again.
@enrikes9877
@enrikes9877 4 года назад
Note: For MAC OS Open MySQL from System Preferences > Initialize Database > Type your new password. Choose 'Use legacy password' Start the Server again. Now connect the MySQL Workbench
@michaelchikaawoke5559
@michaelchikaawoke5559 4 года назад
What about Window System
@sanketjadhav2799
@sanketjadhav2799 5 лет назад
sir i have followed exact your steps but my dbh.inc.php does not looks like yours. where am i going wrong. that text ($dbServer=....) is still in white color. please help me.
@TimeLords910
@TimeLords910 4 года назад
can you teach about how to make your own version of amfphp
@omarabdul494
@omarabdul494 6 лет назад
thanks
@aaronargottelopez3488
@aaronargottelopez3488 2 года назад
Thanks
@rabinsubedi5602
@rabinsubedi5602 3 года назад
Make video on connect dB with Singleton pattern
@MBZMaster
@MBZMaster 5 лет назад
Why not using "require" instead of "include"? If something goes wrong, "include" can expose your data, because it will continue to render page displaying content, while "require" will stop page rendering.
@codegate615
@codegate615 5 лет назад
I think that's why it's include_once rather than include
@lukaspl12
@lukaspl12 5 лет назад
include_once and include anyway will countinue to render page displaying all code to the end. In login system you dont want this kind of stuff so you should use "require" or "require_once".
@harridomana5862
@harridomana5862 5 лет назад
MBZ Master bro you don't get it do you? this is just a sample and I know you know that but the reason why he only uses include cuz his not making a website or anything important that's why he used root right? this is only a sample for people who are studying for IT to make things easier and I know that they will learn that there are other function besides include like require in the near future so just relaxed cuz there will be more episodes to see
@GT-wn4yi
@GT-wn4yi 5 лет назад
@@harridomana5862 Teaching the wrong way first is a great way to learn bad habits lmao.
@calvinsaxon5822
@calvinsaxon5822 3 года назад
Great video, don't get me wrong. My frustration is the following: every tutorial, and I mean every one, always uses "localhost" as the database. Now, how do I connect to a remote database using php? It's just frustrating that every tutorial chooses not to handle this.
@Dani_Krossing
@Dani_Krossing 3 года назад
You log into your hosting sites dashboard and get that information. If you can’t find the dashboard or the database info, ask them where it is 🙂The reason you don’t see tutorials showing you this is because every hosting site is different.
@pixzelparadize
@pixzelparadize 3 года назад
Sir , my database "loginsystem" is not visible in phpmyadmin , please help it to tackle.
@MessianicJudaism
@MessianicJudaism Год назад
So far you have said how to connect to an outside server but you didn't give an example. I understand for localhost,, but what about my service provider servers? $dbServerName = "db12.server"; // would this be correct to write it like this connect to my host provider db server? $dbUserName = "usrName"; Etc, etc. Is that how I would write it? Or do I have to put a http? Thanks for your time.
@Dani_Krossing
@Dani_Krossing Год назад
It differs depending on the hosting provider, but you usually have a link in your dashboard once you are logged into the hosting services website, that gives you the information of your server.
@matty2627
@matty2627 6 лет назад
Which Colour Scheme Did you use?
@tamchan3610
@tamchan3610 4 года назад
Question : Is the $dbPassword there is for access the database ? If so, is there any chance that client can see the password as they can get the dbh.inc.php ?
@vertimyst
@vertimyst 4 года назад
Yeah, without it your PHP code won't be able to access your database. PHP is a server-side language though, so if someone were to open the file it would be blank (or they'd see HTML code generated by the browser). I'm no security expert though so it's very possible a skilled hacker could obtain access, and I'm sure there are other things to be done to make it more secure.
@tamchan3610
@tamchan3610 4 года назад
@@vertimyst Thanks
@WalaMohammed
@WalaMohammed 2 года назад
Please I need some help… I could not understand how this thing make the information about the user when he/she “sign in “ will being appear in my admin.. I search for it in google but all I found doesn’t expelan enough.
@rahul7018
@rahul7018 2 года назад
Great
@muzamilzaman7463
@muzamilzaman7463 Год назад
I have mysql software installed instead of xamp how can i connect to it
@suitedbastard3406
@suitedbastard3406 5 лет назад
@mmtuts Is there a reason why you are using "mysqli_connect" rather than "new mysqli"?
@Dani_Krossing
@Dani_Krossing 5 лет назад
Yes. One is Procedural and the other is OOP.
@suitedbastard3406
@suitedbastard3406 5 лет назад
@@Dani_Krossing Ok, thank you! I've only learned the "new mysqli" one yet, so I got a bit confused.
@dergenius4946
@dergenius4946 3 года назад
i always have a parse error on line 8 . after 3 h of trying to fix it i couldnt do it :(
@brendanchikezie5225
@brendanchikezie5225 Год назад
How do I set the php note for it codes inside windows 10
@dragonserver4932
@dragonserver4932 4 года назад
I'm using 127.0.0.1:8090 and 3307. What I have to do?
Далее