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

Поділитися
Вставка
  • Опубліковано 9 лис 2024

КОМЕНТАРІ • 165

  • @Agtgf
    @Agtgf 7 років тому +29

    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 років тому +2

      Геннадий Акулов Thank you :)

    • @SergeyFominVL
      @SergeyFominVL 7 років тому +2

      I am from Russia and can agree with Gennadi.

    • @LucasPedroniG
      @LucasPedroniG 7 років тому +1

      I'm from Brazil, and I can agree with you guys :D

    • @JustAlexV
      @JustAlexV 7 років тому +2

      Agree with you all and I'm from Moldova)

    • @mateuszb4387
      @mateuszb4387 7 років тому +3

      I'm from Poland. I won't argue with any of you, guys :-)

  • @dmlamarre1
    @dmlamarre1 7 років тому +8

    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.

  • @flawlessproudmoore3765
    @flawlessproudmoore3765 5 років тому +1

    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 років тому +1

    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.

  • @nitingupta1650
    @nitingupta1650 7 років тому +27

    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?

  • @dudonz
    @dudonz 4 роки тому

    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.

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

  • @celsomasotti_mat
    @celsomasotti_mat 8 місяців тому +1

    Thank you for the excellent tutorial.

  • @gib-gab
    @gib-gab Рік тому

    The first video that I've watched that actually helped me understand oop ;) thank you so much

  • @LucasPedroniG
    @LucasPedroniG 7 років тому +1

    Such a great teacher! I hope to watch more videos from you! I watched all videos at once!

  • @devnullex
    @devnullex 5 років тому

    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.

  • @ZectorWood
    @ZectorWood 4 роки тому

    Hello, man. I'm from Brazil and I love your videos. You're so good. Congrats, teacher.

  • @SimPwear84
    @SimPwear84 7 років тому +8

    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 років тому +1

      Thank you :) I'm glad you found the lessons useful

  • @flaviouscorreia536
    @flaviouscorreia536 4 роки тому

    Really useful now i find programming interesting thanks :)

  • @nasiruddin2638
    @nasiruddin2638 6 років тому +1

    I am enjoying your tutorial series a lot. You explain so well.

  • @stormybear4986
    @stormybear4986 4 роки тому +1

    The sound of your voice always makes me very happy. I love your videos!

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

  • @adriancelis9691
    @adriancelis9691 5 років тому +1

    Thanks very much! This was exactly what i was looking for. Great tutorial.

  • @abrasaxtago9478
    @abrasaxtago9478 7 років тому

    Thank you so much for this tutorial. Hoping for the continuation of this series.

  • @homuncu1i
    @homuncu1i 7 років тому

    This video helped me a lot. Thank you man!..... I'll share you until the end of times!

  • @rifatbeigh1131
    @rifatbeigh1131 4 роки тому

    You are an amazing teacher... love the way you make it so simple to understand

  • @TITAN-sv5eg
    @TITAN-sv5eg Рік тому

    thanks that's so helpful

  • @kieran1990able
    @kieran1990able 7 років тому +4

    Very precise and clearly explained. I subbed you.

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

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

  • @Akosiyawin
    @Akosiyawin 5 років тому +1

    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.

  • @rw7799
    @rw7799 5 років тому +1

    nice. why do use classes instead of functions to query the db? i struggle with the seperation logic. thx,

  • @bosshunters500
    @bosshunters500 7 років тому

    concise and understandable!

  • @hakankurhan2411
    @hakankurhan2411 7 років тому

    your tutorials are amazing, please keep working on them as possible as you can :D

  • @slagunes4705
    @slagunes4705 7 років тому +1

    dude you are sent from heaven, for sure. thanks for your amazing work.

  • @TheKiloOhm
    @TheKiloOhm 6 років тому +1

    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!

  • @souravdutt7
    @souravdutt7 5 років тому

    Amazing video 💯👍🙏

  • @surinfarmwest6645
    @surinfarmwest6645 7 років тому

    This has just answered a big question! Thank you very much Daniel :-)

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

  • @rajendrajoyce
    @rajendrajoyce 6 років тому +1

    it's really helpfull to me. could u make complete tutorial on oophp with mysqli(E-commers level)

  • @architector7199
    @architector7199 5 років тому

    thanks for ur knowledge

  • @swapnilshinde2489
    @swapnilshinde2489 7 років тому

    Very nice explanation....Thanks man

  • @StockSprint-byVRS
    @StockSprint-byVRS 7 років тому

    Very Nice work beautiful flow of concepts...amazing It helped me A LLoT :)

  • @jandefajardo7136
    @jandefajardo7136 5 років тому +1

    Hi, do you have a tutorial for PHP OOP CRUD? thank you. I liked your videos

  • @devadas7439
    @devadas7439 4 роки тому

    thanks

  • @raf598
    @raf598 7 років тому

    Hi, Where the rest of the tutorial ,are you done?. Very useful....thanks man.

  • @j_hj_j
    @j_hj_j 7 років тому

    You are amazing!

  • @nonchalant8473
    @nonchalant8473 6 років тому

    Great tutorial thanks. What packages are you using for php?

  • @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 років тому +4

      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!

  • @HeineSkateboarding
    @HeineSkateboarding 7 років тому +2

    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 років тому +6

      I have planned to do so in the future ;)

    • @jelmerdekker
      @jelmerdekker 7 років тому +1

      Is this still on your list? I really look forward to that video!

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

  • @neil5137
    @neil5137 7 років тому

    so so so so good!!!!

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

  • @sumeyradavran4738
    @sumeyradavran4738 7 років тому

    could you make videos about how to make a design for files, classes, folders? How should we divide codes into files?

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

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

  • @patrickgabriel6196
    @patrickgabriel6196 7 років тому

    I thought you did a great job teaching OOP. Can you let me know what editor you use for PHP?

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

  • @ArrayBuffer
    @ArrayBuffer 7 років тому

    nice tutorial

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

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

  • @ThatoJChere
    @ThatoJChere 4 роки тому

    What determines the choice of which type of connection to use between Mysqli and PDO ?

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

  • @mydata3807
    @mydata3807 7 років тому +2

    Sir please create CRUD application with OPP and Ajax concept please

  • @angke5677
    @angke5677 7 років тому +1

    pls make tuts for PDO..

  • @shankaranand199091
    @shankaranand199091 4 роки тому

    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 ?

  • @abdulfattahyusor1158
    @abdulfattahyusor1158 7 років тому

    Hello sir do u have a video on how to create food product inventory with database?

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

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

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

  • @obu69
    @obu69 7 років тому

    sup man....awesome tutorials. But are you done? Where the rest of the tutorial @ lol.

  • @hey-simba
    @hey-simba 3 роки тому

    hey does this vedio belong to any playlist or its just a random vedio?

  • @hamzaarshad9690
    @hamzaarshad9690 5 років тому +1

    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

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

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

  • @bernardbalansag8551
    @bernardbalansag8551 5 років тому

    Thank you sir.. this helps me a lot as a student.

  • @jansiska7527
    @jansiska7527 4 роки тому

    Could "viewUser" be a method within "User" class instead of object "viewUser" that extends "User" class?

  • @АртемВолков-ю5ь
    @АртемВолков-ю5ь 7 років тому +1

    nice

  • @hebaalhwedy354
    @hebaalhwedy354 6 років тому +1

    i want a video for how can i insert items in data base in oop php ? plz

  • @diamondtroller1253
    @diamondtroller1253 5 років тому

    Why these older lessons aren't in oop php playlist?

  • @lokmann16
    @lokmann16 5 років тому

    Plz make a video login system in oops

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

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

  • @MrMarcoAlvarado
    @MrMarcoAlvarado 4 роки тому

    Why don't you use a constructor within the dhb class?

  • @armandocoralesbogayanjr2516
    @armandocoralesbogayanjr2516 7 років тому

    nc tutorial :D

  • @rajdhanki8740
    @rajdhanki8740 6 років тому

    Waiting for oop mvc mysqli project??

  • @janrichard3831
    @janrichard3831 7 років тому

    i fucking love you. thank you so much u just saved my ass xD

  • @777horus
    @777horus 6 років тому

    The order of your include files doesn't matter as long you call its methods and properties afterwards.

    • @Dani_Krossing
      @Dani_Krossing  6 років тому

      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 6 років тому

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

  • @idol2010
    @idol2010 4 роки тому

    playlist link please...!!

  • @avengersreturns3348
    @avengersreturns3348 7 років тому

    How to make logout session for all files

  • @ernestsakala417
    @ernestsakala417 4 роки тому

    Hey can you please help I am get an error call to a member function fetch() in the while loop

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

  • @chandanjoshi9493
    @chandanjoshi9493 4 роки тому

    Can we display mysqli error in inherit class insert?
    lf yes how

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

  • @mindustrial
    @mindustrial 5 років тому

    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.

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

  • @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!";

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

  • @cloudeweb
    @cloudeweb 5 років тому

    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!

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

  • @nilsgarland6302
    @nilsgarland6302 7 років тому

    Slim course?

    • @Dani_Krossing
      @Dani_Krossing  7 років тому +3

      No there will be more episodes. I'm currently moving and don't have my office for recording before the weekend.

    • @nilsgarland6302
      @nilsgarland6302 7 років тому

      Gotcha, keep it up!

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