No video

Connect To A Database Using MySQLi and OOP PHP | Object Oriented PHP Tutorial | PHP Tutorial

  Рет қаралды 160,404

Dani Krossing

Dani Krossing

Күн бұрын

Connect To A Database Using MySQLi and Object Oriented PHP | OOP PHP Tutorial | Learn OOP PHP. In this PHP tutorial you will learn how to connect to a database using object oriented PHP programming. We will also display data from the database on our website using a MVC pattern.
Article on PDO vs MySQLi: code.tutsplus....
➤ 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: / oop-php-lessons-26928726

Пікірлер: 165
@Agtgf
@Agtgf 7 жыл бұрын
Man, your lessons are exciting! I'm from Ukraine, but l understand your videos better, than videos in native tongue from other authors!
@Dani_Krossing
@Dani_Krossing 7 жыл бұрын
Геннадий Акулов Thank you :)
@SergeyFominVL
@SergeyFominVL 7 жыл бұрын
I am from Russia and can agree with Gennadi.
@LucasPedroniG
@LucasPedroniG 7 жыл бұрын
I'm from Brazil, and I can agree with you guys :D
@JustAlexV
@JustAlexV 7 жыл бұрын
Agree with you all and I'm from Moldova)
@mateuszb4387
@mateuszb4387 7 жыл бұрын
I'm from Poland. I won't argue with any of you, guys :-)
@dmlamarre1
@dmlamarre1 7 жыл бұрын
Much the same as Nitin Gupta below, I followed your entire Procedural PHP course and was very impressed. What would it take to get you to complete this OOP MVC PHP course? I don't have much to give, but if a 1000 people following these videos donated $10... well, that's $10,000. Just saying.
@nitingupta1650
@nitingupta1650 7 жыл бұрын
hey i am waiting for you to add more videos about oops php. i followed your whole series about php. now i want to learn oops php. if not your videos then please suggest me a good channel or book or some links?
@flawlessproudmoore3765
@flawlessproudmoore3765 4 жыл бұрын
very nice and clean, although lack the controller part but its much easier to understand simplified code like this. Thank you, keep up the good work!
@cedrictwillie1892
@cedrictwillie1892 7 жыл бұрын
I really like your PHP tutorials. I've watched several of your videos. The only complaint I have is that you use mysqli and not PDO method for database connections. I use PDO because of its versatility and wish you could use it as well to help me and others follow your tutorials more easily. Thanks anyway for the help you've been to me! Great job...
@JustinTheVlogger
@JustinTheVlogger 3 жыл бұрын
Thanks for this info bro, now I can connect and fetch my data from my database using OOP, because all I know is procedural programming.
@celsomasotti_mat
@celsomasotti_mat 5 ай бұрын
Thank you for the excellent tutorial.
@dudonz
@dudonz 3 жыл бұрын
Thanks Dani, you helped me finally connect to my database via PHP and retreive some data. :) Here's a like. It's the least I can do.
@devnullex
@devnullex 4 жыл бұрын
Thank you very much. Your videos are very, very helpful. Along with your great tutorials, I'm trying to fulfill my dream of becoming a programmer.
@gib-gab
@gib-gab Жыл бұрын
The first video that I've watched that actually helped me understand oop ;) thank you so much
@augustbloom_
@augustbloom_ 3 жыл бұрын
I have to say, your videos helped me tremendously. Please do a video on how you can fetch stored data according to user ID using OOP. greatly appreciate it
@LucasPedroniG
@LucasPedroniG 7 жыл бұрын
Such a great teacher! I hope to watch more videos from you! I watched all videos at once!
@nasiruddin2638
@nasiruddin2638 6 жыл бұрын
I am enjoying your tutorial series a lot. You explain so well.
@adriancelis9691
@adriancelis9691 5 жыл бұрын
Thanks very much! This was exactly what i was looking for. Great tutorial.
@batyr71
@batyr71 7 жыл бұрын
please make a blog or some news website example using oop and mvc whit routing etc. your way of explanation is very clear. thank you!
@ZectorWood
@ZectorWood 4 жыл бұрын
Hello, man. I'm from Brazil and I love your videos. You're so good. Congrats, teacher.
@abrasaxtago9478
@abrasaxtago9478 7 жыл бұрын
Thank you so much for this tutorial. Hoping for the continuation of this series.
@flaviouscorreia536
@flaviouscorreia536 4 жыл бұрын
Really useful now i find programming interesting thanks :)
@rifatbeigh1131
@rifatbeigh1131 4 жыл бұрын
You are an amazing teacher... love the way you make it so simple to understand
@TheKiloOhm
@TheKiloOhm 6 жыл бұрын
Great video! However one thing is not clear to me: why not assign the values to the private variables straight away and not in the "connect" function? Thanks!
@rajendrajoyce
@rajendrajoyce 6 жыл бұрын
it's really helpfull to me. could u make complete tutorial on oophp with mysqli(E-commers level)
@rw7799
@rw7799 5 жыл бұрын
nice. why do use classes instead of functions to query the db? i struggle with the seperation logic. thx,
@Akosiyawin
@Akosiyawin 4 жыл бұрын
Hello 👋 I'm used to using PDO on database handling, I just wanted to know what is better to use, mysqli or PDO? Thx.
@navjotsingh2251
@navjotsingh2251 4 жыл бұрын
They are both good, obviously if your using my SQL it's better to use the dedicated mysqli handler, but PDO will work just as fine.
@kieran1990able
@kieran1990able 7 жыл бұрын
Very precise and clearly explained. I subbed you.
@SimPwear84
@SimPwear84 7 жыл бұрын
Best lessons on the web! You got a gift to explain complex things easily. I watched and finished your PHP series and it has helped me a lot. Keep it up bro, you rock.
@Dani_Krossing
@Dani_Krossing 7 жыл бұрын
Thank you :) I'm glad you found the lessons useful
@stormybear4986
@stormybear4986 4 жыл бұрын
The sound of your voice always makes me very happy. I love your videos!
@nicollegaddi2032
@nicollegaddi2032 5 жыл бұрын
thanks for your lessons its so easy to follow specially your html css tutorials
@LaughterOnWater
@LaughterOnWater 5 жыл бұрын
These are great tutorials! Thank you so much for providing these. Regarding timeframe 11:07 ... Not sure, but I think PHP 7.1 may require initializing $data somewhere after line 5 with something like "data = array();" _So function would look like:_ protected function getAllUsers() { *$data = array();* $sql = "SELECT * FROM user"; $result = $this->connect()->query($sql); $numRows = $result->num_rows; if ($numRows > 0) { while($row = $result->fetch_assoc()) { $data[] = $row; } return $data; } } At least that's the only way I could get it to work on Ubuntu 18.04 with PHP 7.2.15. I was getting this error: "PHP Fatal error: Uncaught Error: [] operator not supported for strings in ... includes/user.inc.php:14 ... I hope this helps someone!
@tortingseloc1810
@tortingseloc1810 4 жыл бұрын
Yeah it help me to fix the errors, thanks!
@homuncu1i
@homuncu1i 7 жыл бұрын
This video helped me a lot. Thank you man!..... I'll share you until the end of times!
@TITAN-sv5eg
@TITAN-sv5eg Жыл бұрын
thanks that's so helpful
@jandefajardo7136
@jandefajardo7136 5 жыл бұрын
Hi, do you have a tutorial for PHP OOP CRUD? thank you. I liked your videos
@slagunes4705
@slagunes4705 7 жыл бұрын
dude you are sent from heaven, for sure. thanks for your amazing work.
@ziyadkader6767
@ziyadkader6767 7 жыл бұрын
One of the best tutorials i ever seen , thank you very much for this interesting video !
@bosshunters500
@bosshunters500 7 жыл бұрын
concise and understandable!
@HeineSkateboarding
@HeineSkateboarding 7 жыл бұрын
I was wondering if you could integrate this into your login-system video :) I would love to see how OOP could be used that way.
@Dani_Krossing
@Dani_Krossing 7 жыл бұрын
I have planned to do so in the future ;)
@jelmerdekker
@jelmerdekker 7 жыл бұрын
Is this still on your list? I really look forward to that video!
@hamzaarshad9690
@hamzaarshad9690 5 жыл бұрын
My code didn't work when I included all the files "dbh.inc.php" "user.inc.php" and "viewuser.inc.php" in the same order as shown in the tutorial in my "index" file. However when I included "view" file in my "index" file and "user" file in "viewuser" file and "dbh" file in "user" file my code worked accurately. I also tried different arrangement of files in my "index" file but none of them worked. Solution required "How to include all the files in the Index file so that I can get the desired result." thanks
@hakankurhan2411
@hakankurhan2411 7 жыл бұрын
your tutorials are amazing, please keep working on them as possible as you can :D
@sumeyradavran4738
@sumeyradavran4738 6 жыл бұрын
could you make videos about how to make a design for files, classes, folders? How should we divide codes into files?
@dangputerz
@dangputerz 5 жыл бұрын
the server CPU and memory overhead of PDO is much more then MySQLi ... and if you are not worried about migrating to a different database server down the road... MySQLi is much better. This is not what most people say... but it is a fact.
@shankaranand199091
@shankaranand199091 3 жыл бұрын
Sir I am creating a register and login system using php object oriented approach however I've already created it in procedural style. What I am confusing at is is it necessary to use $conn = new mysqli() inside a connect() function ? can't we use it write is outside that connect function by creating constants instead of variables and then extend the Dbh class and use the $conn directly with prepared statement ?
@ThatoJChere
@ThatoJChere 4 жыл бұрын
What determines the choice of which type of connection to use between Mysqli and PDO ?
@danidan2235
@danidan2235 2 жыл бұрын
In which folder is the database stored? Is it in the same folder where you store your php files, or do you create a subfolder like when you do to put CSS, JS or images for example, or is it somewhere else?
@Dani_Krossing
@Dani_Krossing 2 жыл бұрын
I’m not sure I understand the question. In the video I show that I save the dbh file inside a ‘includes’ folder. If you mean the database we create inside phpmyadmin, then it gets stored somewhere inside our XAMPP installation, and is not something you need to worry about. 🙂
@obu69
@obu69 7 жыл бұрын
Hey man amazing tutorials on php on youtube by far. Keep it up. Can u kindly do a tutorial on an oop login system? That will be awesome.Thanks
@raf598
@raf598 7 жыл бұрын
Hi, Where the rest of the tutorial ,are you done?. Very useful....thanks man.
@StockSprint-byVRS
@StockSprint-byVRS 7 жыл бұрын
Very Nice work beautiful flow of concepts...amazing It helped me A LLoT :)
@surinfarmwest6645
@surinfarmwest6645 7 жыл бұрын
This has just answered a big question! Thank you very much Daniel :-)
@antoniofuller2331
@antoniofuller2331 3 жыл бұрын
Is it possible to use OOP to make a login system?
@swapnilshinde2489
@swapnilshinde2489 7 жыл бұрын
Very nice explanation....Thanks man
@pianoLee-sx9dx
@pianoLee-sx9dx 6 жыл бұрын
I really like your teaching style! Can you make a register and login system plus email activation for php oop?
@flickerspot
@flickerspot 3 жыл бұрын
Good. Tutorial..i have a doubt inline number 14:58 .. we have included database connection. Doest it really required. As the third file extends from the dbh would be possible to fetch db connection.?
@mydata3807
@mydata3807 6 жыл бұрын
Sir please create CRUD application with OPP and Ajax concept please
@joshuamusalia2075
@joshuamusalia2075 Жыл бұрын
How do i output only one column? not in the function code but in HTML. Fore example: I want one html field to output name, second to output id. i get all the rows in one field if i use the above method.
@jevgenijsmarcenkovs265
@jevgenijsmarcenkovs265 4 жыл бұрын
Hi, Your lessons are really helpful. Thank you for your work! Maybe anybody can clarify a little thing to me. I have done everything the same as in video, but when I try to check result - each element from DB returns 2 times. Where can be a mistake? Thank you in advance.
@PardeepKumar-tc3ws
@PardeepKumar-tc3ws 6 жыл бұрын
Hi, great stuff, I have a question, if I want create a separate file for SQL credential how the variables are collected by db connect class
@nonchalant8473
@nonchalant8473 6 жыл бұрын
Great tutorial thanks. What packages are you using for php?
@real.anigan
@real.anigan 5 жыл бұрын
hey mmtuts. I'm confused. Why did you create another class called ViewUser.inc.php if you can put the function that you've create to the class of user? is it because of MVC?
@architector7199
@architector7199 5 жыл бұрын
thanks for ur knowledge
@emmanagan9231
@emmanagan9231 7 жыл бұрын
Good day sir Nice tutorial . . Can i put my connection to database in __construct method or not ?? just wondering so it will be automatically connected :D ??
@souravdutt7
@souravdutt7 5 жыл бұрын
Amazing video 💯👍🙏
@patrickgabriel6196
@patrickgabriel6196 7 жыл бұрын
I thought you did a great job teaching OOP. Can you let me know what editor you use for PHP?
@jhanreygonzales1510
@jhanreygonzales1510 6 жыл бұрын
He's using Sublime Text
@reassume4826
@reassume4826 5 жыл бұрын
Ah! procedural was much easier to write the connection! Is there any harm in using procedural way to write connection and write all other in OOP?
@MrLexisbill
@MrLexisbill 4 жыл бұрын
Can you check if the database did connected with this code ?? if ($this->conn->connect_error) { die("Connection error" .$this->conn->connect_error); } echo "Connected Succesfully"; return $this->conn; ???
@devadas7439
@devadas7439 4 жыл бұрын
thanks
@jansiska7527
@jansiska7527 4 жыл бұрын
Could "viewUser" be a method within "User" class instead of object "viewUser" that extends "User" class?
@abdulfattahyusor1158
@abdulfattahyusor1158 7 жыл бұрын
Hello sir do u have a video on how to create food product inventory with database?
@neil5137
@neil5137 6 жыл бұрын
so so so so good!!!!
@chipsterchops
@chipsterchops 6 жыл бұрын
Was wondering why use the properties in the dbh class if there is nothing set in this example. Can use enter the properties directly when creating the $conn object. But I'm guessing you want to explain it in an OOP fashion where later some values can be put in the connect function.
@Dani_Krossing
@Dani_Krossing 6 жыл бұрын
It's a good habit to keep sensitive info private. If I were to include the database info directly in the $conn, then the info would be protected and not private. Since we only want to make it possible to access this info in the Dbh class.
@hey-simba
@hey-simba 3 жыл бұрын
hey does this vedio belong to any playlist or its just a random vedio?
@hebaalhwedy354
@hebaalhwedy354 6 жыл бұрын
i want a video for how can i insert items in data base in oop php ? plz
@j_hj_j
@j_hj_j 7 жыл бұрын
You are amazing!
@jggamingYT
@jggamingYT 7 жыл бұрын
Nice video! Are you going to continue with this series? Maybe you can make a long video where we can see the advantage of OOP PHP well. You have given the example of a login system in the last episodes. We know how to make a login system from the normal PHP tutorial series. But maybe you can make a video about it in OOP PHP. And point out the way you need to do it in OOP PHP and the advantage more than the login system itself.
@Dani_Krossing
@Dani_Krossing 7 жыл бұрын
Hi there, yes I will continue this series once I get the time for it. A login system in OOP is the plan for the next episode :)
@j_hj_j
@j_hj_j 7 жыл бұрын
please! Thank you so much!
@jared4670
@jared4670 7 жыл бұрын
looking forward to this!
@TienNguyen-lm5yi
@TienNguyen-lm5yi 7 жыл бұрын
Nice tutorial. Could you focused more on OOP PHP rather than html/CSS? Also do you take donation?
@Dani_Krossing
@Dani_Krossing 7 жыл бұрын
I have plans on developing further on OOP PHP once I'm settled in properly after moving :) I gratefully accept donations on my website www.mmtuts.net
@MrMarcoAlvarado
@MrMarcoAlvarado 4 жыл бұрын
Why don't you use a constructor within the dhb class?
@pm599hd
@pm599hd 7 жыл бұрын
very good tutorial mate. though one thing isn't very clear to me. Why create a new class ViewUser which extends the User class, and why not using the same User class for both methods getAllUsers() and showAllUsers()? thanks!
@Dani_Krossing
@Dani_Krossing 7 жыл бұрын
We are separating the two classes because we want to have one class which handles all database queries, and another class that shows the data on the website. It is perfectly possible to do it the way you are suggesting, but because we are following the OOP MVC design pattern, we are separating the functionalities.
@pm599hd
@pm599hd 7 жыл бұрын
oh right! we're following the MVC pattern, thanks!
@ernestsakala417
@ernestsakala417 4 жыл бұрын
Hey can you please help I am get an error call to a member function fetch() in the while loop
@angke5677
@angke5677 7 жыл бұрын
pls make tuts for PDO..
@johanstam3602
@johanstam3602 6 жыл бұрын
Wondering where you get all your content to make these video tutorials? What is your source?
@Dani_Krossing
@Dani_Krossing 6 жыл бұрын
Back from when I was studying my bachelor in web development, and some paid online courses :)
@mindustrial
@mindustrial 4 жыл бұрын
I have problem that with the code in the video tutorial, my results do display but each line is displayed twice. So I have 4 results, while my database only has 2 in it.
@thyrsus07
@thyrsus07 5 жыл бұрын
I'm sorry if this is a stupid question but, can you really run it without error without "?>" in the end of a
@Dani_Krossing
@Dani_Krossing 5 жыл бұрын
Yes as long as there is only PHP :)
@alev5762
@alev5762 5 жыл бұрын
In newer versions of PHP, yes
@obu69
@obu69 7 жыл бұрын
sup man....awesome tutorials. But are you done? Where the rest of the tutorial @ lol.
@diamondtroller1253
@diamondtroller1253 5 жыл бұрын
Why these older lessons aren't in oop php playlist?
@endone3661
@endone3661 3 жыл бұрын
so the "." keyword stands for "+" because I am confused I always use java.
@westfield90
@westfield90 6 жыл бұрын
I apologize for being such a newbie but I understand that this connection file is kept in a includes folder. Now i have a file called login.php and register.php which need that connection information. I put at the top of these files the include reference to this connection information file. However when i now try to use this connection information in both of these files i get a undefined variable for $conn. What am I missing?
@Dani_Krossing
@Dani_Krossing 6 жыл бұрын
That seems odd since the $conn should be accesible inside the login and register files. Try checking that you spell everything correctly and included the file path in the correct way.
@ArrayBuffer
@ArrayBuffer 7 жыл бұрын
nice tutorial
@bernardbalansag8551
@bernardbalansag8551 5 жыл бұрын
Thank you sir.. this helps me a lot as a student.
@jonast9726
@jonast9726 5 жыл бұрын
Can someone give me some tips on how to insert data using this method? I've been toying around with it for some time, but I haven't had any luck so far
@chandanjoshi9493
@chandanjoshi9493 4 жыл бұрын
Can we display mysqli error in inherit class insert? lf yes how
@user-rv1tn2bm6r
@user-rv1tn2bm6r 7 жыл бұрын
nice
@pianoLee-sx9dx
@pianoLee-sx9dx 6 жыл бұрын
how do you update records? Is it something liked... $sql = UPDATE from user WHERE id = 1? I like to update my emailactivation to 1...
@nkiangmatiahjunior6451
@nkiangmatiahjunior6451 5 жыл бұрын
UPDATE user SET--------- THEN YOU USE THE WHERE statement
@janrichard3831
@janrichard3831 7 жыл бұрын
i fucking love you. thank you so much u just saved my ass xD
@viper5758
@viper5758 4 жыл бұрын
could you add error message on your connection ?
@djkadakamc1889
@djkadakamc1889 2 жыл бұрын
You don't close the connection? How it works if you want to manage transactions?
@Dani_Krossing
@Dani_Krossing 2 жыл бұрын
According to PHP.net it closes the connecting automatically. Which is why I leave it out in my tutorials.
@rajdhanki8740
@rajdhanki8740 6 жыл бұрын
Waiting for oop mvc mysqli project??
@glotech21
@glotech21 4 жыл бұрын
Please can you fix this error Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ')' which raises on $conn = new mysqli($this->servername, this->username, $this->password, $this->dbname);
@Uni1299
@Uni1299 4 жыл бұрын
this->username ==> $this->username
@lokmann16
@lokmann16 5 жыл бұрын
Plz make a video login system in oops
@avengersreturns3348
@avengersreturns3348 6 жыл бұрын
How to make logout session for all files
@idol2010
@idol2010 4 жыл бұрын
playlist link please...!!
@777horus
@777horus 5 жыл бұрын
The order of your include files doesn't matter as long you call its methods and properties afterwards.
@Dani_Krossing
@Dani_Krossing 5 жыл бұрын
Last time I checked the order does matter when you include them in your header, otherwise the class files can't refer to one another.
@777horus
@777horus 5 жыл бұрын
@@Dani_Krossing Oh yes, you are right l overlooked that one class extends the other. So I think in javascript the order doesn't matter but in PHP it does. However I'm not sure about javascript too. The simplest way is to try it out. Perhaps you know how Javascript reacts if one do not care about the order of included javascript classes.
@cloudeweb
@cloudeweb 4 жыл бұрын
Hello, great tutorial! I have a question: how can I access to single fields? something like this: foreach($datas as $data) { $username = $data["username "]; $password= $data["password"]; } I'd like echo only Username o Password here: $leads->showAllLeads(); thanks!
@kearfy
@kearfy 6 жыл бұрын
how about: $database->query(SELECT * FROM users); ?
@Dani_Krossing
@Dani_Krossing 6 жыл бұрын
That is also a possible way to query :) However it is using PDO and not MySQLi like mentioned in the video title. In a later episode I go over PDO connections as well since PDO and MySQLi both have pros and cons ;)
@codingneko
@codingneko 2 жыл бұрын
Please use naming conventions. don't use getAllUsers, use getUsers, that way you can add an optional "limit" parameter so you don't overwhelm your database retriving 9 million users at once, name your users variable "users" because it contains User instances (not really because you didn't use class mapping, but it should), that way you know what the variable contains. If you name it "datas", fuck knows what's in that variable, plus you could have another variable with the same generic ass name later in your code.
Doing This Instead Of Studying.. 😳
00:12
Jojo Sim
Рет қаралды 33 МЛН
Вы чего бл….🤣🤣🙏🏽🙏🏽🙏🏽
00:18
Lehanga 🤣 #comedy #funny
00:31
Micky Makeover
Рет қаралды 28 МЛН
Should You Learn Object Oriented PHP?
13:48
Dani Krossing
Рет қаралды 10 М.
you need to learn SQL RIGHT NOW!! (SQL Tutorial for Beginners)
24:25
NetworkChuck
Рет қаралды 1,5 МЛН
Object Oriented PHP
26:37
Derek Banas
Рет қаралды 322 М.
Doing This Instead Of Studying.. 😳
00:12
Jojo Sim
Рет қаралды 33 МЛН