Тёмный
No video :(

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

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

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

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

 

13 авг 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 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!
@celsomasotti_mat
@celsomasotti_mat 5 месяцев назад
Thank you for the excellent tutorial.
@cedrictwillie1892
@cedrictwillie1892 6 лет назад
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...
@gib-gab
@gib-gab Год назад
The first video that I've watched that actually helped me understand oop ;) thank you so much
@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.
@LucasPedroniG
@LucasPedroniG 7 лет назад
Such a great teacher! I hope to watch more videos from you! I watched all videos at once!
@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.
@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.
@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
@nasiruddin2638
@nasiruddin2638 5 лет назад
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.
@kieran1990able
@kieran1990able 7 лет назад
Very precise and clearly explained. I subbed you.
@ZectorWood
@ZectorWood 4 года назад
Hello, man. I'm from Brazil and I love your videos. You're so good. Congrats, teacher.
@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
@flaviouscorreia536
@flaviouscorreia536 4 года назад
Really useful now i find programming interesting thanks :)
@abrasaxtago9478
@abrasaxtago9478 7 лет назад
Thank you so much for this tutorial. Hoping for the continuation of this series.
@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!
@TITAN-sv5eg
@TITAN-sv5eg Год назад
thanks that's so helpful
@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.
@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!
@rifatbeigh1131
@rifatbeigh1131 4 года назад
You are an amazing teacher... love the way you make it so simple to understand
@rw7799
@rw7799 5 лет назад
nice. why do use classes instead of functions to query the db? i struggle with the seperation logic. thx,
@homuncu1i
@homuncu1i 7 лет назад
This video helped me a lot. Thank you man!..... I'll share you until the end of times!
@nicollegaddi2032
@nicollegaddi2032 5 лет назад
thanks for your lessons its so easy to follow specially your html css tutorials
@ziyadkader6767
@ziyadkader6767 7 лет назад
One of the best tutorials i ever seen , thank you very much for this interesting video !
@stormybear4986
@stormybear4986 4 года назад
The sound of your voice always makes me very happy. I love your videos!
@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!
@rajendrajoyce
@rajendrajoyce 6 лет назад
it's really helpfull to me. could u make complete tutorial on oophp with mysqli(E-commers level)
@bosshunters500
@bosshunters500 7 лет назад
concise and understandable!
@hakankurhan2411
@hakankurhan2411 7 лет назад
your tutorials are amazing, please keep working on them as possible as you can :D
@jandefajardo7136
@jandefajardo7136 5 лет назад
Hi, do you have a tutorial for PHP OOP CRUD? thank you. I liked your videos
@souravdutt7
@souravdutt7 5 лет назад
Amazing video 💯👍🙏
@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 ?
@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
@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.
@slagunes4705
@slagunes4705 7 лет назад
dude you are sent from heaven, for sure. thanks for your amazing work.
@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!
@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
@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.
@StockSprint-byVRS
@StockSprint-byVRS 7 лет назад
Very Nice work beautiful flow of concepts...amazing It helped me A LLoT :)
@swapnilshinde2489
@swapnilshinde2489 7 лет назад
Very nice explanation....Thanks man
@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?
@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. 🙂
@architector7199
@architector7199 5 лет назад
thanks for ur knowledge
@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?
@devadas7439
@devadas7439 4 года назад
thanks
@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
@sumeyradavran4738
@sumeyradavran4738 6 лет назад
could you make videos about how to make a design for files, classes, folders? How should we divide codes into files?
@raf598
@raf598 7 лет назад
Hi, Where the rest of the tutorial ,are you done?. Very useful....thanks man.
@neil5137
@neil5137 6 лет назад
so so so so good!!!!
@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; ???
@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.
@ThatoJChere
@ThatoJChere 4 года назад
What determines the choice of which type of connection to use between Mysqli and PDO ?
@j_hj_j
@j_hj_j 7 лет назад
You are amazing!
@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?
@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.
@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
@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?
@jansiska7527
@jansiska7527 4 года назад
Could "viewUser" be a method within "User" class instead of object "viewUser" that extends "User" class?
@hebaalhwedy354
@hebaalhwedy354 6 лет назад
i want a video for how can i insert items in data base in oop php ? plz
@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 ??
@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!
@nonchalant8473
@nonchalant8473 6 лет назад
Great tutorial thanks. What packages are you using for php?
@abdulfattahyusor1158
@abdulfattahyusor1158 7 лет назад
Hello sir do u have a video on how to create food product inventory with database?
@patrickgabriel6196
@patrickgabriel6196 6 лет назад
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
@ArrayBuffer
@ArrayBuffer 7 лет назад
nice tutorial
@ernestsakala417
@ernestsakala417 4 года назад
Hey can you please help I am get an error call to a member function fetch() in the while loop
@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.
@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!
@angke5677
@angke5677 7 лет назад
pls make tuts for PDO..
@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
@hey-simba
@hey-simba 3 года назад
hey does this vedio belong to any playlist or its just a random vedio?
@obu69
@obu69 7 лет назад
sup man....awesome tutorials. But are you done? Where the rest of the tutorial @ lol.
@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.
@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
@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
@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 :)
@user-rv1tn2bm6r
@user-rv1tn2bm6r 7 лет назад
nice
@MrMarcoAlvarado
@MrMarcoAlvarado 4 года назад
Why don't you use a constructor within the dhb class?
@endone3661
@endone3661 3 года назад
so the "." keyword stands for "+" because I am confused I always use java.
@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
@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
@bernardbalansag8551
@bernardbalansag8551 5 лет назад
Thank you sir.. this helps me a lot as a student.
@diamondtroller1253
@diamondtroller1253 5 лет назад
Why these older lessons aren't in oop php playlist?
@lokmann16
@lokmann16 5 лет назад
Plz make a video login system in oops
@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!
@janrichard3831
@janrichard3831 7 лет назад
i fucking love you. thank you so much u just saved my ass xD
@idol2010
@idol2010 4 года назад
playlist link please...!!
@ninjatribble7961
@ninjatribble7961 5 лет назад
Great tutorial series, learnt loads so far. I'm getting an error message at the end of this one. Not sure where I've gone wrong. Gone through it several times. Any thoughts anyone? "Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\OOP_12\includes\viewuser.inc.php on line 7"
@matheusalencar6708
@matheusalencar6708 4 года назад
Make sure you have some data in the table. If not, the method getAllUsers won't have any return and so you'll get that error.
@NiltonOliv
@NiltonOliv Год назад
@@matheusalencar6708 Where to use a key with ELSE echo "No record found!";
@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.
@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 ;)
@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.
@rajdhanki8740
@rajdhanki8740 6 лет назад
Waiting for oop mvc mysqli project??
@armandocoralesbogayanjr2516
@armandocoralesbogayanjr2516 7 лет назад
nc tutorial :D
@Dani_Krossing
@Dani_Krossing 7 лет назад
Thank you :)
Далее
Should You Learn Object Oriented PHP?
13:48
Просмотров 10 тыс.
What does MySQLi vs PDO Teach You about Development?
13:19
Ajax Live Data Search with jQuery PHP MySQL
10:20
Просмотров 94 тыс.
PHP OOP -  Beginners Crash Course
24:05
Просмотров 159 тыс.