Это видео недоступно.
Сожалеем об этом.

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

Поделиться
HTML-код
  • Опубликовано: 12 июл 2017
  • 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

Комментарии • 276

  • @dogiap8561
    @dogiap8561 4 месяца назад +2

    tks for sharing this lesson, i was stuck with how to connect my db for my school job, love you

  • @brandonneilsta.teresa3494
    @brandonneilsta.teresa3494 3 года назад +55

    Finally, a PHP tutorial video I can watch without cringing.

    • @Scuffy
      @Scuffy 2 года назад +3

      Why would you cringe? just curious.

    • @cancerousryan7272
      @cancerousryan7272 2 года назад +3

      @@Scuffy because he's racist

    • @Scuffy
      @Scuffy 2 года назад +1

      @@cancerousryan7272 makes sense

    • @mrtin-voe
      @mrtin-voe 2 года назад +3

      I can watch this barely without crying.

  • @johanmbaabu1580
    @johanmbaabu1580 Год назад +2

    thanks man u are a legend. Young programer here from Kenya .

    • @Dani_Krossing
      @Dani_Krossing  Год назад

      I have a newer 2023 course on my channel 😊

  • @ujwalc9226
    @ujwalc9226 5 лет назад +31

    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 года назад +1

      @@hahehi682 pure?

    • @umrbekmatrasulov4141
      @umrbekmatrasulov4141 4 года назад +1

      @@hahehi682 can you explain with more detail?

    • @CsharpQelly
      @CsharpQelly 4 года назад +3

      @@umrbekmatrasulov4141 The ?> close tag is not really necessary when PHP code is the only content of the document.

  • @billb6283
    @billb6283 5 лет назад +2

    Nice video. Quick and to the point. I wrote my 1st PHP programs almost 20 years, the end of 2000...before RUclips 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 года назад +7

    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!

  • @jaynostulop2476
    @jaynostulop2476 3 года назад +6

    I can now understand while looking on the screen.

  • @zahraaliux
    @zahraaliux 2 года назад +1

    I've learned from you in one day what I couldn't get from college teacher in 4 months

  • @jlambert12013
    @jlambert12013 3 года назад +4

    That was so much easier than I was expecting

  • @teryphlp
    @teryphlp 3 года назад +1

    Really awesome. I am a beginner I really learned a lot . Highly recommended.

  • @kevgits
    @kevgits 5 лет назад +63

    Finally, someone who speaks English...phew!

    • @QuesoSlam
      @QuesoSlam 3 года назад +1

      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.

  • @Klenric
    @Klenric 6 лет назад +25

    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.

  • @aplemancao8080
    @aplemancao8080 2 года назад +2

    Applause to you sir. Thanks for sharing & teaching your programming ideas, I have learned well through your tutorials 🥰

  • @guylemay1471
    @guylemay1471 5 лет назад +4

    My goodness... I should have watched your tutorials on the subject years ago - thank you!

  • @amarjeetsingh0624
    @amarjeetsingh0624 3 года назад

    sir i have'nt seen tutor like you , you r the great sir

  • @05renemar1
    @05renemar1 7 лет назад +9

    Lol, after the previous episode, your voice changed from energetic to a more grown man from this new episode XP

    • @johnberns8917
      @johnberns8917 3 года назад +1

      ReneMar Remorosa they grow up so fast

  • @harlanreece2348
    @harlanreece2348 Год назад

    Your information is so on point and easy to understand.

  • @mikegerow4937
    @mikegerow4937 6 лет назад +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

  • @nazifasadia5705
    @nazifasadia5705 3 года назад +1

    Such a clear explanation man...!! Loved it very much. Thank you for making such a informative video.

  • @RagHelen
    @RagHelen 5 лет назад +1

    Put that include in a directory above root (above www), not below, and make the variables constants.

  • @chaddsmith3354
    @chaddsmith3354 3 года назад

    Thank you for the video!

  • @ador989
    @ador989 Год назад

    this what i need, thank you

  • @iconsworld9
    @iconsworld9 2 года назад

    THANK YOU VERY USEFUL< AFTER ALL THOSE YEARS< AND TIME EVERYTHING IS JUST A MATTER OF TIME.

  • @irenerosejohnson8346
    @irenerosejohnson8346 2 года назад

    Nice tutorials ... helped a lot ...crisp and clear... keep going👍👍

  • @errolprince5112
    @errolprince5112 2 года назад

    must thank you for your video

  • @kithinga
    @kithinga 4 года назад

    you just know how to teach..thanks a lot

  • @mcqueen_sportsmedia
    @mcqueen_sportsmedia 5 лет назад

    Great video!!! It really helped me out A LOT! Thanks!

  • @MBZMaster
    @MBZMaster 6 лет назад +9

    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 6 лет назад +2

      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 лет назад +4

      @@harridomana5862 Teaching the wrong way first is a great way to learn bad habits lmao.

  • @realzire
    @realzire 7 лет назад +4

    Love your tutorials! I learnt html thanks to you!

  • @excelapplications6969
    @excelapplications6969 5 лет назад +1

    Great explanation. Thank you!

  • @luiscarlosmartinez3034
    @luiscarlosmartinez3034 2 года назад

    Thank you!
    Gracias!
    Obrigado! 🙏🏽🔥

  • @isthiswil
    @isthiswil 4 года назад +1

    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.

  • @ziadbohlok7632
    @ziadbohlok7632 3 года назад

    beast♥♥♥ im watching u from lebanon keep it up

  • @khairelfarish
    @khairelfarish 5 лет назад +11

    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 года назад +1

      localhost refers to your computer, this is default, but i don't really know so...

  • @sktrickandtreat5540
    @sktrickandtreat5540 3 года назад

    Great video ❤️

  • @calvinsaxon5822
    @calvinsaxon5822 3 года назад +2

    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 года назад +1

      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.

  • @hohojimmy4443
    @hohojimmy4443 5 лет назад +7

    I have a question is that how did I do to link other server?just need input ip? Thank your response.

  • @umarar6025
    @umarar6025 4 года назад +1

    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

  • @mainakray6452
    @mainakray6452 4 года назад

    awesome video , nice explanation

  • @jasminev3436
    @jasminev3436 4 года назад

    Thank you so much! amazing tutorial!

  • @RiazKhan-uv9wx
    @RiazKhan-uv9wx 6 лет назад

    thank you so much . It's really good tutorials

  • @niekbeijloos8355
    @niekbeijloos8355 4 года назад

    Very nice! Thank you !

  • @nogafouz2174
    @nogafouz2174 2 года назад

    MERCI BEAUCOUP

  • @lucasferreira8229
    @lucasferreira8229 Год назад

    Which one do companies use more at work, MYSQLI or PDO?

  • @pianoLee-sx9dx
    @pianoLee-sx9dx 6 лет назад

    This is great.. So, if you have it written in the incorrect order, it won't connect?

  • @_sbmangiepangie6982
    @_sbmangiepangie6982 3 года назад

    It worked!

  • @rabinsubedi5602
    @rabinsubedi5602 3 года назад

    Make video on connect dB with Singleton pattern

  • @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.

  • @sharonglendale8439
    @sharonglendale8439 4 года назад

    Thank you :D Great video.

  • @zahidhasan5417
    @zahidhasan5417 5 лет назад

    very helpful video

  • @aleemahmed1863
    @aleemahmed1863 4 года назад +2

    question, how do i pass this $conn to a function so that i can use it to run an sql statement within that function?

  • @surinfarmwest6645
    @surinfarmwest6645 7 лет назад +2

    I was using your previous method:-

  • @jazmineemiemariegueco
    @jazmineemiemariegueco 5 лет назад +1

    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.

  • @amirahassan9213
    @amirahassan9213 3 года назад

    you r perfect thank you

  • @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?

  • @gauravbhandari1184
    @gauravbhandari1184 4 года назад

    Helpful

  • @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:)

  • @danielwatson6529
    @danielwatson6529 2 года назад

    where would you put your includes folder in the Wordpress Stack?

  • @brunosantos7193
    @brunosantos7193 6 лет назад

    Thank You very much

  • @aaronargottelopez3488
    @aaronargottelopez3488 2 года назад

    Thanks

  • @pranabmedhi4676
    @pranabmedhi4676 7 лет назад +1

    sir,can you please make a video on creating a user profile in php?

  • @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?

  • @kaptennick6352
    @kaptennick6352 3 года назад

    Amazing tutorials! It is almost TOO EASY! Ι have a question thought what theme are you using for your code?

  • @EdwardHood
    @EdwardHood 5 лет назад

    How do you initialize multiple connections to multiple databases? I have form fields that come from other physical databases.

  • @joneseugene301
    @joneseugene301 7 лет назад

    Thanks .can you do a video on how to make your files downloadable using php

  • @mar4974
    @mar4974 5 лет назад

    great tutorial

  • @M1sterE321
    @M1sterE321 4 года назад

    What even is the type of program you're using to code the connection?

  • @probutcher3308
    @probutcher3308 4 года назад +1

    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?

  • @policeuac
    @policeuac 4 года назад

    Please make a database video with PDO :)

  • @taniyapreetsingh
    @taniyapreetsingh 6 лет назад +1

    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

  • @hijabzainab5632
    @hijabzainab5632 3 года назад

    what changes will i have to make in this code if it was for sqlite instead of mysql

  • @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?.

  • @SuldaanMedia
    @SuldaanMedia 4 года назад

    Hello mmtuts can you please help me validate my PHP contact form before saving to database ?

  • @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?

  • @assmabenmussa4228
    @assmabenmussa4228 6 лет назад +1

    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  6 лет назад +4

      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 6 лет назад

      mmtuts oooh I see, thank you very much for taking the time to reply to me. You are awesome! :)

  • @briansenior4910
    @briansenior4910 7 лет назад

    great videos, can you show us how to host a php website on hostgator that uses a database

  • @sijjadawann
    @sijjadawann 6 лет назад

    So nice video

  • @eb4416
    @eb4416 4 года назад

    In this example you used include_once @7:29 and not just include. Is it necessary? I thought you would use include_once for example in a loop, where you need something to be included once, while the loop continues to do stuff.

    • @annukulthakran2834
      @annukulthakran2834 4 года назад

      Suppose if we have included a file two times in our code the it will show an error and we don't want that. So by using include_once it will not show any error even when we included a file more than one time.

  • @gregorycooper8116
    @gregorycooper8116 3 года назад

    For whatever reason my index.php file does not recognize my dbh.inc.php file. my index.php and my includes folder are in the same directory but its not registering it. Any suggestions?

  • @ronaldjohnson4470
    @ronaldjohnson4470 5 лет назад +3

    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 года назад +1

      What about Window System

  • @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.

  • @Hiturion
    @Hiturion 4 года назад

    What does $conn variable return? Boolean (connected/connected) ?

  • @MessianicJudaism
    @MessianicJudaism 2 года назад

    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  2 года назад

      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.

  • @hiran9485
    @hiran9485 3 года назад

    Vell don vasu vell don ✌🏻

  • @arifrk
    @arifrk 5 лет назад

    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?

  • @AmeerHamza-cy6km
    @AmeerHamza-cy6km 4 года назад +1

    Parse error: syntax error, unexpected '$host' (T_VARIABLE) in C:\xampp\htdocs\NewTestRegistration\connectDB.php on line 4

  • @majdibrahem5586
    @majdibrahem5586 3 года назад

    massive bro

  • @TimeLords910
    @TimeLords910 4 года назад

    can you teach about how to make your own version of amfphp

  • @peppigue
    @peppigue 3 года назад

    Some videos, like this one, have choppy playback of sound on my chromecast 1st gen. Very frustrating. I bet it's about the video format.

  • @gillydadude1541
    @gillydadude1541 2 года назад

    This code syntax doesn't work in IDE Atom it's almost like you have to hard code the connection script for IDE Atom to know what variable your calling. sgls in this scenario don't work either :( what's another ide i can go with for my next assignment.

    • @Dani_Krossing
      @Dani_Krossing  2 года назад

      Your text editor has nothing to do with your code not working. It’s just a tool. 🙂 I can guarantee you that the error is happening because you set your website up incorrectly, or you made a typo.

  • @itzycombi
    @itzycombi 4 года назад

    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.

  • @sanketjadhav2799
    @sanketjadhav2799 6 лет назад

    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.

  • @ShuyanStoryTeller
    @ShuyanStoryTeller 6 лет назад

    It's great.

  • @subhajitpaul4005
    @subhajitpaul4005 6 лет назад +1

    where do i find the servername of my website? from the c-panel?

    • @deepakgupta2872
      @deepakgupta2872 6 лет назад

      search in the file config.find out the wp-config.php after that view the data you will find out the servername
      bt bydefault server name is '
      localhost'

  • @rahul7018
    @rahul7018 2 года назад

    Great

  • @senju31
    @senju31 5 лет назад

    What books did you read in order to figure all of this out?

  • @muzamilzaman7463
    @muzamilzaman7463 Год назад

    I have mysql software installed instead of xamp how can i connect to it

  • @dergenius4946
    @dergenius4946 4 года назад +1

    i always have a parse error on line 8 . after 3 h of trying to fix it i couldnt do it :(

  • @tarsemmaini06
    @tarsemmaini06 3 года назад

    Sorry, but i followed the same steps but it didn't show in my localhost as a loginsysytem, i don't know where i am lacking, can you please tell what could be wrong?

  • @brendanchikezie5225
    @brendanchikezie5225 Год назад

    How do I set the php note for it codes inside windows 10