17: Query A Database Using OOP PHP | Prepared Statements Using PDO | Object Oriented PHP Tutorial

Поділитися
Вставка
  • Опубліковано 18 вер 2024
  • In this OOP PHP tutorial, I will show you how to query a database using OOP PHP. We will be going over selecting, inserting, and updating database content using PDO and prepared statements. Prepared statements are important as part of a more secure database connection.
    ➤ 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

КОМЕНТАРІ • 174

  • @gabrielfono844
    @gabrielfono844 2 роки тому +6

    after teaching myself coding full time , I recently got hired as software engineer in seattle waghinston.
    I remember started tutorials with your html and css.
    now , they require me to learn php oop, design pattern in two weeks before getting started.
    everything makes sense for me since I really understand OOP in javascript.
    this is why it is so crucial to know one language well.
    thanks Dani krossing.

  • @lawrencemichael5571
    @lawrencemichael5571 4 роки тому +10

    20 minutes of brilliance.
    Some guys are lucky to sit in class in real life with this man as their professor.

  • @MMH94MMH
    @MMH94MMH 2 роки тому +19

    Its 2022 and this series still very helpful, Thank you so much Daniel this OOP-Series helped me a lot, a appreciate your effort.

  • @andresalvarez7303
    @andresalvarez7303 Рік тому +2

    I think the most valuable thing about your tutorials is that you say what you're doing but also WHY you're doing something. It's that information that helps bridge gaps in learning and has helped me have a lot of answered questions about the code. I always find myself asking WHY immediately after learning how to do something. Thanks for making every video feel like more than just a set of rigorous instructions without reason behind them.🙌

  • @mh5854
    @mh5854 4 роки тому +39

    I got full marks in college in a web programming class. thanks.

  • @xyzxyz2734
    @xyzxyz2734 4 роки тому +2

    My professor linked most of your videos - so great job! He is quite picky, when it comes to exact education/explanations. So thats like a TÜV-Approved for your content. And you did your job great! Nice help for my fisrt php project. Thank you so much.

  • @NicolasLagiosOfficial
    @NicolasLagiosOfficial Рік тому +1

    Thank you Dani, you helped me a lot. I had to watch your series first in order to understand OOP PHP in order to start learning Laravel. Thank you very much 😄

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

    Very nice, thank you! I extended this this by combining it with an earlier tut you made with the calculator. But instead of calculating I let a user type their first name, last name and dob and when they submit it, it creates a user inside the table. Not really that special but your tuts made that possible, once again thanks a lot!

  • @chyjohn6502
    @chyjohn6502 Рік тому

    Thanks a lot Dani for these really helpful videos. I just want to say something about 12:55-13:35, I might be wrong, I don't know, you obviously know more than a lot of us, but I think FETCH works just fine with or without prepared statements, you just have to use WHILE LOOP to spit out multiple records, whereas FETCHALL fetches everything at once removing the need to use the WHILE LOOP.

  • @sivap8984
    @sivap8984 4 роки тому +29

    Can you make the tutorial for laravel framework in php?

  • @salalalalalala11
    @salalalalalala11 3 роки тому +1

    I am very picky about the channels I subscribe to and my good sir, you are one of them.

  • @stopit405
    @stopit405 3 роки тому

    Dani, I was frustrated with this subject. I was trying to make sense of the clases and the examples provided by the professor. After spending 35 minutes watching your videos i fanally got it. Thank you man.

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

    There are two channels which are my favorite . That are mmtuts and all type tutorials. Well Done brother.

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

    I like the way you explain even no programming knowledge don't lost the topic.

  • @VitalijMik
    @VitalijMik 4 роки тому +5

    Thanks for the tutorial but please bare in mind that this code is just for the Tutorial Purpose, this is not industry standard, you should not extend from the database connection, rather injecting the connection into your class over constructor, usually youre using a dependecy container such as PHP-DI for this. Also you should not prepare the statement everytime you call getUsersStmt, prepare it once in constructor or something and then just call execute with the new parameters. And also do not use PHPMyADmin on live system since it has too many security issues while noone is dating it up.
    But anyways thanks for this tutorial which helps the PHP Language a lot

  • @edgar1906
    @edgar1906 4 роки тому +4

    Heyyy I love these tutorials!
    You should do a full-stack course with angular or react for front-end using php for the back-end. That would be the perfect combination! :D

    • @pbznt
      @pbznt 2 роки тому +1

      Vanilla JS and custom css is way better than any front-end framework and libraries. Just like we are doing now. We don't use Laravel. We use pure PHP. Always go for the pure alternative, if you're not in a context of work where you are limited time to accumplish a task. ;)

  • @ma.reynalinjoypahayahay3302
    @ma.reynalinjoypahayahay3302 2 роки тому

    Thank you for creating this video! I finally solve my 4 hours error in php

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

    Må indrømme at dine videoer hjælpe meget når man er igang med at tage en Webudvikler uddannelse :)

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

      Dani would be like
      Wow good to see someone my kind
      Rest of audience: what does this mean

  • @Born2DoubleUp
    @Born2DoubleUp 2 роки тому

    I'm here! 😎 Great video, just posting a comment to show some support! Keep up the good work. 🤙

  • @adedayoomotoso9340
    @adedayoomotoso9340 Рік тому

    You are the best, simple and unique.

  • @okaforchinyerematthew1937
    @okaforchinyerematthew1937 2 роки тому

    Hello Dani Thanks a lot for this awesome tutorial, your teaching style is one in a million. Dani for some reason i don't know i try using while loop to convert the data return from database into array it failed, but i changed it to foreach loop and it worked, then i come upon stackoverflow there was an answer that you cannot use while loop with fetchAll() function in PDO rather foreach loop is right. But in your example you use while loop and it worked for you.

    • @Dani_Krossing
      @Dani_Krossing  2 роки тому +3

      I can explain that. 🙂
      In my example I am fetching the database results one at a time using "fetch", and not using "fetchAll".
      This means that I can use a while loop since I am only fetching one at a time.
      What you are trying to do however, is to grab ALL the data at once using "fetchAll", not one at a time, and insert into an array. Therefore a while loop would only run once and not do anything, since you get ALL the data the first time. That's why a "foreach" loop is working, since you are creating a multidimentional array that way.
      However just to mention it, it is also still possible to create an array with the results like you are trying to do, but with a "while" loop instead of "foreach". You just need to create an empty array before the "while" loop, and then inside the while loop just insert the data into the empty array during each run. 😊

    • @jvoynar5826
      @jvoynar5826 Рік тому

      I had a similar problem. I changed the '' to "", and it displayed all items in that column. Otherwise it only displayed the first. Using mariaDB on macOS terminal to interact w/ my database/table. Anyway, thank you Dani !

  • @pawecyrklaf4729
    @pawecyrklaf4729 4 роки тому +7

    Hi :)
    Why did you use extends instead of injecting the Dbh instance into the constructor of the Test class?

    • @pseudounknow5559
      @pseudounknow5559 3 роки тому +1

      Znalazlesz odpowiedz czy nie ? Bo ja nie rozumiem

    • @pawecyrklaf4729
      @pawecyrklaf4729 3 роки тому

      @@pseudounknow5559 Nie, ale dla mnie to ewidentny błąd, bo jego klasa Test w żaden sposób nie rozszerza możliwości klasy Dbh, a od tego jest extends, jedynie używa z niej połączenia. W tym wypadku powinien wstrzyknąć Dbh do klasy Test. Od 8 lat pracuję jako php dev i nigdy nie spotkałem się z tym, aby klasę od DB rozszerzać po to, żeby używać z niej połączenia.

    • @arshiatolou1958
      @arshiatolou1958 2 роки тому

      What's that? i don't get it?

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

    Thanks for this video,, we are learning web development in school.. This helps me a lot... More power

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

    thank you very much teacher, i like your style of teaching

  • @aguswidi9316
    @aguswidi9316 7 місяців тому

    Mr. Daniel, I have learned a lot from you especially oop php. Could you make another video teaching oop php with mvc, database, and using transaction, commit, rollback feature. Thank's

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

    People are so lazy: There should be way more like as these tutorials are excellent. Many Thanks

  • @princeedward9160
    @princeedward9160 3 роки тому +1

    hi Dani ive got a question of the prepared statements why didnt we bind parameters like we do with precedural php and then execute $stmt later? of do we bind if they are coming from the form?

    • @chyjohn6502
      @chyjohn6502 Рік тому +1

      I assume you might have found an answer to this and I'm not very good with PHP theories, but then I'll still try to answer you and then hope my answer makes any sense. Inserting the values directly as an array inside execute() is very valid according to PHP docs and it makes things easier when using the class across multiple projects. Whenever you instantiate an Object and pass 'where clause' and 'the value array' as the parameters, no matter the project, no matter the quantity of the 'where parameters / where values', your code will still run correctly without having to go back to the class file to start editing / worrying about the number of 'bindParams' you are supposed to have.

  • @JamesAutoDude
    @JamesAutoDude 2 роки тому

    Freaking best tutorial I've ever seen with awesome explanations

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

    You really have a knack for teaching. Thank you for these amazing videos, truly appreciate it.

  • @gonzaloalbornoz3220
    @gonzaloalbornoz3220 3 роки тому

    Thank you very much, greetings from Argentina

  • @Camaro-it8ht
    @Camaro-it8ht 4 роки тому +6

    I'm stuck... Fatal error: Uncaught Error: Call to a member function fetch() on bool in /var/www/html/classes/test.class.php:8 Stack trace: #0 /var/www/html/index.php(16): Test->getUsers() #1 {main} thrown in /var/www/html/classes/test.class.php on line 8

    • @arturskovrigo3915
      @arturskovrigo3915 4 роки тому +2

      This most probably means that the query is returning false, but I have not found the reason why is this happening

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

      Did you get the bug? I got the exact same and I'm stuck. Can't find a way through

    • @mikoko2192
      @mikoko2192 3 роки тому +1

      Ensure you check everything concerning the database check your SQL statement if it is working properly and also your database connection code check for spelling errors...I found out mine was a spelling error at setting up the dsn I spelt (dbName=' . $this->dbName;) instead of (dbname=' . $this->dbName;)

  • @poetha5100
    @poetha5100 3 роки тому

    before i don't understand now i can understand easly bro
    Thank a lot Super over talk bor

  • @AbJadzera
    @AbJadzera 3 роки тому

    Absolute LEGEND!!! Much love and respect!

  • @vytautaskuklys3829
    @vytautaskuklys3829 3 роки тому +1

    Awesome video! How to handle exceptions though?

  • @hayatzee8830
    @hayatzee8830 Рік тому

    Thank you Dani!

  • @omerkarebek8809
    @omerkarebek8809 2 роки тому

    Thanks, Dani. You made my day!

  • @Greenitcom
    @Greenitcom 3 роки тому

    thank you i understand is oop php

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

    cant wait til the next episode!
    Thanks for being an awesome teacher!

  • @osmanalp4110
    @osmanalp4110 2 роки тому

    Thank you very much 😀

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

    Just love the way you teach sir!, i find your videos very taughtful, but can you make more videos on topics like ReactJs, AngularJs, etc, where you can explain every concept of those language topic by topic.

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

    too much lovve from MOROCCO !!! thank u soooooooo much

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

    you saved my life man

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

    So ok... Then it is going to be new hat every episode. Nice:)

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

    being a high school student in computer science (last year), i learned a lot from your videos.
    In school we have only seen procedural programming (OOP will come in college) and i decided i wanted to learn OOP because I am currently doing an internship for school with a big project and procedural PHP isn't working all that well on a big scale.
    The point of this comment being that although i learned a lot from your videos, i would like more in depth tutorials, i mean these are good but just the basics. For example namespaces were only covered briefly. But what i really mean with in depth is for example ajax with OOP, ...
    Don't get me wrong I LOVE your tutorials and i don't want to criticize but i am in need of of the most in depth tutorials, if you guys know any feel free to let me know

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

    I'm curious about the query() method you call on $this->connect()->query(), is this a built in method or did you write it in the class you're extending. I didn't see it in the last video. Also curious about fetch(). Are they built in for pdo?

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

      coming to the query part, you have to pass in the query you have written. And for fetch()....it's like you have to define the attribute first(which is done in the parent class in this video) and then use fetch method in order to fetch the data. Hope I helped you!
      Happy to help.
      Pratik Navlani

    • @samduss4193
      @samduss4193 2 роки тому

      @@pratiknavlani1188 $this ->connect()->query() ??? does it mean that the object return from $this-connect() as a method called query ?!

    • @arshiatolou1958
      @arshiatolou1958 2 роки тому

      Those are built in oop generally, he didn't create any methods as 'query' , or 'fetch' in the class.

  • @Star-zf8su
    @Star-zf8su 4 роки тому

    Thanks very much 😊😀....I was eagerly waiting for the lesson..... I hope I'll get another lesson very much soon.....😁😁

  • @nathanielohiare5717
    @nathanielohiare5717 2 роки тому

    Hey thanks for your tutorials, because of you am able to understand traits better.
    Please do you have a playlist on UA-cam for your PHP tutorials, I checked your channel but couldn't find any PHP related playlist

    • @Dani_Krossing
      @Dani_Krossing  2 роки тому

      I have a playlist on my UA-cam page :) It's in the section where I have all my courses

  • @rashid.m-li
    @rashid.m-li 4 роки тому

    Waiting for the next Episode...Thank You ;) Class

  • @mahsapourshahmari8458
    @mahsapourshahmari8458 2 роки тому

    that is what I call a mega tutorial. would you mind making one for handling JSON and inserting it into the database in oop way, please?

  • @ademottoman962
    @ademottoman962 4 роки тому +3

    hi can you live stream some times because that would be awsome :)

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

      ua-cam.com/video/9uzJn8g4mlM/v-deo.html

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

      @@bouabadahamid nta w mahrez ta3k hhhhh nas tat3alem w nta ab9a m3a mahrez

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

    Perfect!! I was waiting for the next episode, when Will this course finish?

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

    Please a make a video on '5 star rating and review system, comment and reply' . Thanks

  • @Jam....
    @Jam.... 4 роки тому

    Subscribed, excellent tutorials.

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

    Hi, First Thanks alot for your Tutos. They are very helpful.
    General Question, as you talk about prepared statements:
    In this examples you didnt use the *bind_param?
    This is for purpose, as you assume not getting external Data? or does the execute([]) take this procedure?
    Thank you or someone else who will explain me :)

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

      Ok got it, its PDO Handling

  • @carllawrencecacho9455
    @carllawrencecacho9455 2 роки тому

    I wish that I saw your tutorials sooner :(

  • @randyhopkins9895
    @randyhopkins9895 2 роки тому +1

    Howdy Dani, trying to move more to OOP, it seem the class-autoload does not function in my setup. Is there something that needs to be changed in maybe the php.ini file? It is kind of weird because your PDO OOP login systems works fine. Just asking for a little help here and Thank you!

  • @monsurrahmanriaz5157
    @monsurrahmanriaz5157 3 роки тому +1

    I got this error, " Fatal error: Uncaught Error: Call to a member function fetch() on bool in C:\xampp\htdocs\OOP_PHP\db_connection\Danial\classes\test.php:11 Stack trace: #0 C:\xampp\htdocs\OOP_PHP\db_connection\Danial\index.php(8): Test->getUsers() #1 {main} thrown in C:\xampp\htdocs\OOP_PHP\db_connection\Danial\classes\test.php on line 11 ." can you tell me why?

  • @pbznt
    @pbznt 2 роки тому

    Dani, thank you for those videos. I'll soon subscribe to your patreon to discover the hidden content 😎 Meanwhile, could you tell me how is it that, for example, at 1:25, you extends a class that is in another file, and the file is not included in the document, nor the autoloader? Should not we include the autoloader in every file that requires references to other documents?Thanks!

    • @pbznt
      @pbznt 2 роки тому

      I simply don't understand how the spl_autoload_register function from autoloader is called.

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

    tnx brother ....

  • @tovis_bratsburg
    @tovis_bratsburg 3 роки тому

    Is it more or less the same with using Stored Procedures and Views?

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

    Awesome Thank you!

  • @AhmadZaki95
    @AhmadZaki95 2 роки тому

    when i trying to run test.class.php i getting an error class Dbh not found why and i make autoloader page

  • @poetha5100
    @poetha5100 3 роки тому

    I was subscrib && watch your a lot of videos but don't understand
    any php || any php mysql i already understand over voice an English language 😃😄😁😆😅😂🤣

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

    Hey mmuts nice tutorial! But when are you going to make a router tut? looking forward to that

  • @菅家俊太-i5j
    @菅家俊太-i5j 4 роки тому

    thank you for good video everytime,
    and I would like to ask why you can extends Dbh class without requiring dbh.class.php??

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

      there is includes\class-autoload.inc.php file solves it =)

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

    Thank you!

  • @stephenkruger37
    @stephenkruger37 Рік тому

    Would you be able to do a class AddUser{} where you have data input from your HTML input fields and then posting it to your table and then display info in table on front end?

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

    Hello Daniel, can you explain the differences between real escape string and prepared statements?

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

      www.eversql.com/5-common-mistakes-php-developers-make-when-writing-sql/
      :)

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

    Thanks thanks thanks!!!

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

    Thanks.

  • @emirano
    @emirano Рік тому

    Hi, great tutorial and I really loved it but am having an issue with the fact that you stated that you get the property of class by using the 'this' keyword but with the 'stmt' property you actually called it like a variable that is '$stmt'. So am kinda confused. Thanks alot for the tutorial

  • @hadesinferno813
    @hadesinferno813 4 роки тому +3

    no data was displayed after fetching, i don't know why

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

      Same problem, any solution?

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

      try $pdo = new PDO("mysql:host=$this->host;dbname=$this->dbname", $this->login, $this->pwd

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

      @@mopserdak I had a problem with Fatal error using fetch() to return boolean, and after I changed $pdo into your version, it worked for me. I still have no idea why making a $dsn variable and using it didn't work. Thank you.

    • @michalpazitka3182
      @michalpazitka3182 3 роки тому

      @Hades inferno did you find what is wrong??i have the same, everything is right as he wrote it and not working, thank you

    • @michalpazitka3182
      @michalpazitka3182 3 роки тому

      @@mopserdak still not working for me

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

    I have one question to the setUsersStmt, if I want to have the firstname optional how can I add NULL to the DB

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

      Access your database, go to your table -> structure -> action -> edit firstname and check null. SO firstname can be null.

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

    Thanz broo

  • @vsmclassifiedads4046
    @vsmclassifiedads4046 3 роки тому +1

    i got this error
    Fatal error: Uncaught Error: Call to a member function fetch() on boolean in C:\xampp\htdocs\education\mvc_model\classes\test.class.php:7 Stack trace: #0 C:\xampp\htdocs\education\mvc_model\index.php(95): Test->getUsers() #1 {main} thrown in C:\xampp\htdocs\education\mvc_model\classes\test.class.php on line 7

  • @Benjitob
    @Benjitob Рік тому

    Hey Daniel, i am a little bit confused about prepared statments.
    First i learned to make prepared statements in msyqli, and in that way i should bind the parameters, but you dosent do it in your toturial, but is it still safe to do it in your way?

    • @Dani_Krossing
      @Dani_Krossing  Рік тому

      This tutorial just shows how to do basic queries, so no this isn't secure since it isn't done using prepared statements. You should ALWAYS use prepared statements, and I just never got far enough with making this course to the point where I show how to do it. 🙂
      But if you wanna use prepared statements, then it is done like this inside the method instead:
      // HERE WE START THE METHOD
      protected function getUser($userId)
      {
      // HERE WE CREATE THE QUERY
      $stmt = $this->connect()->prepare('SELECT * FROM users WHERE users_id = ?;');
      // HERE WE ASSIGN THE PLACEHOLDERS AND EXECUTE THEM
      if (!$stmt->execute(array($userId))) {
      $stmt = null;
      header("location: index.php?error=stmtfailed");
      exit();
      }
      // HERE WE GRAB THE RETURNED DATA
      $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
      // HERE WE CHECK IF DATA WAS ACTUALLY RETURNED
      if (count($data) == 0) {
      $stmt = null;
      header("location: index.php?posts=none");
      exit();
      }
      // IF WE HAD DATA, THEN WE RETURN IT
      return $data;
      }

    • @Benjitob
      @Benjitob Рік тому

      Hey Dani
      Many thanks for you answer
      So in pdo, You assign the pladeholders in the execute function?
      So if i do like you wrote, my query is safe?

    • @Dani_Krossing
      @Dani_Krossing  Рік тому

      I mean there are many security measurements in PHP, such as assigning user roles to prevent any accidental "bad queries", hashing, secure connections, sanitizing data, etc... But yes, using prepared statements is how you should submit data to a database, or get data from a database.

    • @Benjitob
      @Benjitob Рік тому

      @@Dani_KrossingSorry about all my questions, but i saw a touturial about prepared statement on youtube.
      and in that tutorial they made it like this $conn->prepare("INSERT INTO MyGuests (email) VALUES (:Mail)")
      $stmt->bindParam(":Mail", $input);
      $input = $userId
      $stmt->execute();
      i think that the ":" is a type of placeholders.
      Do you think this way also works, and is secure?
      Many thanks for you big help, and thank you for heping a danish guy how wants to program

  • @Rafael-es5dp
    @Rafael-es5dp 4 роки тому

    How are we gonna use LIKE in that kind of format of prepared statement? around 12:00 of the video stmt

  • @subratmca
    @subratmca 3 роки тому

    How to return a success or failure message with prepare statement?
    also how to check for existing data and return a message if already data present in DB?

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

    Hi! can you give example on how to populate a table? using the methods in this video. thanks

  • @Zoen12345
    @Zoen12345 3 роки тому

    insaine!!

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

    Sorry, when I try to get the rows from the database the query fails, but I have done everything as you explained.
    Here is my code:
    public function getUser(){
    $sql = "SELECT * FROM users";
    $stmt = $this->connect()->query($sql);
    if (!$stmt)
    echo "error";
    else{
    while($row = $stmt->fetch()){
    echo $row['username'];
    }
    }
    }
    Can you please help me, I'm becoming crazy!

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

      You are missing an opening bracket at the if statement.

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

      @@Dani_Krossing nothing changes, on the web I found that is possible to not put the brakets with only one instruction under the if statement

  • @ten8217
    @ten8217 3 роки тому

    you are amazing.

  • @sohaibrahman6240
    @sohaibrahman6240 3 роки тому

    Please Please! Create a tutorial on Laravel Framework in PHP.

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

    Hi Daniel, i am not familiar with PDO. i remember u use mysql to handle database in php.
    Is there any reasons that u don't use mysql here?

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

      Hi there, I think you mean MySQLi and not MySQL :) most people have the assumption that PDO connections are better than MySQLi, so therefore I decided to go with PDO :) you can just go ahead and use MySQLi if you wanna go with that instead.

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

      @@Dani_Krossing thanks dude. =D

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

    Sir, Gud Evening.!. I am trying to insert answer to my database answer which consists of q_no (AUTO _INCREMENT), qno(VARCHAR) and answer(VARCHAR) . Data is coming from radio button and i want answer of question 1 should insert into qno(varchar) 1 and so on.. but i am unable to perform that ..can u help me out if u have free time ?

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

    Please tell me how you bring your body in front of the video? I also use OBS studio, but I don't know how to to do it. I can place my video in a corner but that is complete square.
    How you trim all other background except your body?

  • @scottm8701
    @scottm8701 3 роки тому

    what about closing the connection, commit, rollback?

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

    Shouldn’t we close the connection? How it works then? Thank you

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

    Wrong is
    while($row=$smtp->fetch()
    True is
    Do it $users=$stmt->fetchAll();

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

    Nice :)

  • @nipunsachinda
    @nipunsachinda 3 роки тому

    Fatal error: Uncaught Error: Call to a member function execute() on bool in C:\Xampp new\htdocs\L16\classes\test.class.php:18 Stack trace: #0 C:\Xampp new\htdocs\L16\index.php(21): Test->getUserStmt('nipun', 'sachinda') #1 {main} thrown in C:\Xampp new\htdocs\L16\classes\test.class.php on line 18
    why come this error

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

    HELP I keep getting the error: connect()->query($sql);
    while ($row = $stmt->fetch()){
    echo $row['firstname'];
    }
    }
    }
    ?>
    Fatal error: Uncaught Error: Class 'Email' not found in C:\Users\

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

      Well it's hard to tell what's wrong when you only pasted one small part of your code. But judging by the error message, it seems you have created a new object that's an instance of class "Email" while not having created the class itself. Like this:
      - $your_new_object = new Email();

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

    Hey, thank you so much for this great tutorial. Watched all oop videos and everything was great but in this lecture i got an error,
    public function getUsersStmt($name, $ph) {
    $sql = "SELECT * FROM tableName WHERE name = ? AND mobile = ?";
    $stmt = $this->connect()->prepare($sql);
    $stmt->execute([$name, $ph]);
    $res = $stmt->fetchAll();
    foreach ($res as $key) {
    echo $key['name'];
    echo $key['mobile'];
    }
    }
    but this piece of code return nothing. It's return an empty page with no errors. Please help

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

      change it to foreach ($res = $key)

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

    Please use PSR12

  • @stephenkruger37
    @stephenkruger37 Рік тому

    How would you code a table to show your output data?

    • @Dani_Krossing
      @Dani_Krossing  Рік тому +1

      You just create a HTML table and then create a PHP foreach loop, that loops a with the data in it. 🙂

    • @stephenkruger37
      @stephenkruger37 Рік тому

      @@Dani_Krossing Was able to create one thank you

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

    how can I get lastInsertedId using PDO ?

  • @ShubhamMishra-uw9yi
    @ShubhamMishra-uw9yi 4 роки тому

    Hello sir. Can i get material used in this lesson

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

    How many episodes are you planning?

  • @mrwinnin1306
    @mrwinnin1306 2 роки тому

    how to do delete and update method please help me i am stuck

  • @VTULab
    @VTULab Рік тому

    Please 🥺 do you have course on udemy?