Intro to Doctrine PHP - DataBase Abstraction Layer - Query Builder - Full PHP 8 Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ก.พ. 2025
  • In this lesson, we learn about Doctrine Database Abstraction Layer library. We learn how to use query builder, how to inspect database schema & so on.
    SOME OF THE WAYS YOU CAN SUPPORT THE CHANNEL
    👍 Smash the like button
    🤝 Subscribe to the channel & turn the notifications on
    💬 Post comments, any feedback is greatly appreciated
    ⭐ Become a Patreon: / programwithgio
    THANK YOU!
    🛠️ TOOLS & SERVICES I USE
    Digital Ocean Hosting - Get 100$ credit - m.do.co/c/38b9...
    Domains on Namecheap - namecheap.pxf....
    Envato Elements - 1.envato.marke...
    Adobe Photoshop & Premiere - clk.tradedoubl...
    COURSE PLAYLIST
    • Learn PHP The Right Wa...
    RESOURCES
    Source Repo - github.com/gge...
    Doctrine DBAL - www.doctrine-p...
    ** Affiliate Disclaimer: Some of the above links may be affiliate links, which may generate me a sales commission at no additional cost to you.

ความคิดเห็น • 73

  • @hannanmiah1240
    @hannanmiah1240 2 ปีที่แล้ว +2

    Thanks for the most awaited series.

    • @ProgramWithGio
      @ProgramWithGio  2 ปีที่แล้ว +1

      Thank you for your support 💙

  • @Zubbee
    @Zubbee 2 ปีที่แล้ว +1

    Learning new things even more. Thanks Gio. The refactoring is a intriguing. And the videos have become faster which is great cause I'm sure it lets you squeeze in more stuff and then we can slow it down or taking it easy so we can get all the stuff you squeezed in out. I recommended the series directly to someone today and I think he has started from the first video already. Thanks again Gio

  • @memack101
    @memack101 2 ปีที่แล้ว

    Great video as always.

  • @constantinci
    @constantinci 2 ปีที่แล้ว

    You never fail 😄, thank you.

  • @sadhakbj
    @sadhakbj 2 ปีที่แล้ว +1

    Can you make some videos on SOLID principles as well? Your content will be the best one in the entire internet.

    • @ProgramWithGio
      @ProgramWithGio  2 ปีที่แล้ว +1

      Thank you. Yes might do that in separate series

  • @abdallakaram5376
    @abdallakaram5376 2 ปีที่แล้ว

    The great Gio thanks alot ❤️

  • @hassanasadi3701
    @hassanasadi3701 2 ปีที่แล้ว

    That's amazing, thank you

  • @aerohcss
    @aerohcss 3 หลายเดือนก่อน

    I didn't find this in documentation but now when you updating something (INSERT, SET, etc) with Query Builder you probably have to add ->executeStatement() in the end of expression to actually execute it.

    • @ProgramWithGio
      @ProgramWithGio  3 หลายเดือนก่อน

      I think you can still do prepare & then execute it or just do shortcut & use executeStatement

  • @aruppaul1468
    @aruppaul1468 2 ปีที่แล้ว

    wow great gio

  • @mehdi-vl5nn
    @mehdi-vl5nn 2 ปีที่แล้ว

    so an Orm plays as data access and business layer at the same time in a Laravel app for instance?

  • @JonasHerbertson
    @JonasHerbertson 2 ปีที่แล้ว

    Great! Many thanks!

  • @GreyDeathVaccine
    @GreyDeathVaccine 2 ปีที่แล้ว

    It was good tut... sure enough 😉

  • @benderbg
    @benderbg 5 หลายเดือนก่อน

    I had an issue in 2024 at 5:00 min mark where we are passing invoice id to executeQuery and getting an error:
    Syntax error or access violation: 1064 You have a
    n error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?'
    After some investigating it turns out I was using Doctrine 4.1 where executeQuery no longer accepts array parameters. This was not the case in Doctrine 3.1 when this video was recorded. When I downgraded the version I could continue with the lesson.

    • @ProgramWithGio
      @ProgramWithGio  5 หลายเดือนก่อน

      Glad you figured it out

    • @aerohcss
      @aerohcss 3 หลายเดือนก่อน

      If I have a habit to read comments before watching videos I will save a lot of time lol

  • @cryptoknight7256
    @cryptoknight7256 2 ปีที่แล้ว

    Thanks a lot for that video!! .. And so on! lol

  • @BrowserManager
    @BrowserManager ปีที่แล้ว

    Hello, thank you for all these videos. Please tell me how autoload Dotenv\Dotenv. I can do it 'composer require symfony/dotenv' ?

    • @ProgramWithGio
      @ProgramWithGio  ปีที่แล้ว

      We covered that in second section, search the playlist, you will find it

  • @truthteachers
    @truthteachers ปีที่แล้ว +2

    For info: at timestamp 9:50, the type argument "\Doctrine\DBAL\Connection::PARAM_INT_ARRAY" has been deprecated and we need to use "\Doctrine\DBAL\ArrayParameterType::INTEGER".

    • @ProgramWithGio
      @ProgramWithGio  ปีที่แล้ว

      Yup, thank you for the note. We use older version in this recording but later videos we have up to date version.

  • @jackrourke9237
    @jackrourke9237 2 ปีที่แล้ว +3

    As always absolutely Love your content and way to teaching ♥ ♥ ♥ ♥ ♥ Can you tell me which package you use to get array key and values on same level to each other like on 3:33? Thank you once again ♥

    • @ProgramWithGio
      @ProgramWithGio  2 ปีที่แล้ว

      Thank you. It's a setting in my IDE under Code Style (PhpStorm).

    • @jackrourke9237
      @jackrourke9237 2 ปีที่แล้ว

      @@ProgramWithGio what extra setting parameter you use, can you tell, I also want that one 😊

    • @ProgramWithGio
      @ProgramWithGio  2 ปีที่แล้ว +2

      Code Style -> PHP -> Wrapping and Braces -> Align consecutive assignments
      Code Style -> PHP -> Wrapping and Braces -> Align constants
      Code Style -> PHP -> Wrapping and Braces -> Array Initializer (checked all 4)
      I think that's all, there might be couple more but it should be all under Wrapping and Braces section so play around with those settings.

    • @jackrourke9237
      @jackrourke9237 2 ปีที่แล้ว +1

      Appreciated! Thank you so much 😊 ♥ ♥ ♥ ♥ ♥

  • @expresscoding3525
    @expresscoding3525 ปีที่แล้ว

    Hello sir, at 9:50, I see [\Doctrine\DBAL\Connection::PARAM_INT_ARRAY] this part is deprecated, what to do?

    • @ProgramWithGio
      @ProgramWithGio  ปีที่แล้ว

      Use \Doctrine\DBAL\ArrayParameterType::INTEGER

  • @pauliusjankauskas8028
    @pauliusjankauskas8028 2 ปีที่แล้ว +1

    Thanks for nice tutorial! Just one off topic question: how did you align "connection params"? Is it any default phpstorm shortcut or need to setup phpstorm to do so?

    • @ProgramWithGio
      @ProgramWithGio  2 ปีที่แล้ว +1

      ctrl + alt + l if it doesnt work then you can adjust the alignment from the phpstorm settings for PHP

  • @dileepnadukuru4493
    @dileepnadukuru4493 2 ปีที่แล้ว

    nice tutorial

  • @DigitaSkills101
    @DigitaSkills101 2 ปีที่แล้ว

    Which exception does the \Doctrine\DBAL\DriverManager::getConnection()
    throws

    • @ProgramWithGio
      @ProgramWithGio  2 ปีที่แล้ว

      You can inspect th get connection method and see. I don't remember off the top of my head

  • @sefyankehail7801
    @sefyankehail7801 2 ปีที่แล้ว

    Hello Gio, I hope you're having a good day!
    I have a question right here : 09:26
    *executeQuery()* second parameter is an array of arrays right ? because it throws an error when I take off the brackets of $ids ( related to the vendor doctrine DBAL classes )

    • @ProgramWithGio
      @ProgramWithGio  2 ปีที่แล้ว +1

      Hello. In this case yes because we are using where IN().

    • @sefyankehail7801
      @sefyankehail7801 2 ปีที่แล้ว +1

      @@ProgramWithGio Got it, thank you!

  • @BrowserManager
    @BrowserManager ปีที่แล้ว

    How to create table with doctrine dbal dynamically ?

    • @ProgramWithGio
      @ProgramWithGio  ปีที่แล้ว

      You would typically use migrations, what do you mean by dynamically & what would be the use case?

  • @omaryahia
    @omaryahia ปีที่แล้ว

    I can't be a perfectionist
    with some topics like doctrine
    I don't think I need to go into details
    so
    I make a trade off
    I get some value by watching and taking general notes
    I miss a lot of value by not doing hands-on codes
    but I accept this risk/loss
    now, I don't need to slow down
    I can continue in the playlist as I am
    the costly decision of getting in-depth + asking questions + hands-on
    will be saved for topics I feel more relatable to my career in the short term
    just an approach I am using
    to manage the gains of my study streak following a curriculum/roadmap
    I hope I do well

    • @ProgramWithGio
      @ProgramWithGio  ปีที่แล้ว +1

      Thats fine, you might like the active record pattern ORM like Eloquent from Laravel

  • @DigitaSkills101
    @DigitaSkills101 2 ปีที่แล้ว

    Which sql driver is better to use.

    • @ProgramWithGio
      @ProgramWithGio  2 ปีที่แล้ว

      Whichever you like. I use mysql

    • @DigitaSkills101
      @DigitaSkills101 2 ปีที่แล้ว

      @@ProgramWithGio well the doctrine does not support mysql does it have any reason for that

    • @ProgramWithGio
      @ProgramWithGio  2 ปีที่แล้ว

      It does, we use mysql in this lesson. Check the documentation or the video again (3:21), it uses pdo_mysql. Doctrine supports PDO driver so whatever drivers PDO supports can be used with doctrine.

  • @truthteachers
    @truthteachers ปีที่แล้ว

    Its odd, in the documentation i only get "listTables()" and not "listTableNames()"'. When i look at the definition for ""listTables()"' i able to find "listTableNames". I may be wrong, as I see the documentation is very summary level. Is there anywhere we could get a list of methods for DBAL?

    • @ProgramWithGio
      @ProgramWithGio  ปีที่แล้ว

      listTableNames is available on the schema manager, maybe documentation is missing it but you should be able to open up AbstractSchemaManager and see both listTables & listTableNames there

    • @truthteachers
      @truthteachers ปีที่แล้ว

      @@ProgramWithGio Thank you for the reply. Only worrying thing is that we may not know all methods to make best use of the library/extension.

    • @ProgramWithGio
      @ProgramWithGio  ปีที่แล้ว

      @@truthteachers you don't need to know. When you have a need for a specific method then you start searching for it. I do agree that Doctrine could use a better documentation. I've had to dig into the source many times

  • @mimoh2000
    @mimoh2000 2 ปีที่แล้ว

    Hi Gio, please 2 quick questions.
    1. "driver" => 'pdo_mysql' ?? $_ENV['DB_DRIVER']. Without inverting this statement, I get doctrine does not support mysql
    driver that we had been using despite having pdo_mysql driver installed. Am using Fedora 36.
    2. $stmt = $conn->prepare('SELECT * FROM invoices WHERE id = ?');
    This line gives the error message below.
    An exception occurred while executing a query: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; heck the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1.
    Still trying to figure out the reason and solution. Any assistance will be highly appreciated.

    • @mimoh2000
      @mimoh2000 2 ปีที่แล้ว

      Hi, was able to resolve the 2nd part of the question. Binding the position or named parameter and calling the executeQuery() without parameter resolved the issue.
      Using named parameter:
      $stmt = $conn->prepare('SELECT * FROM invoices WHERE id = :id');
      $stmt->bindValue('id', 100);
      $result = $stmt->executeQuery();
      using position parameter:
      $stmt = $conn->prepare('SELECT * FROM invoices WHERE id = ?');
      $stmt->bindValue(1, 100);
      $result = $stmt->executeQuery();
      The sql error has to dp with mysql keywords or reserved words. But am still unable to figure it out as the id
      isn't a keyword or reserved word. Will keep digging.

    • @ProgramWithGio
      @ProgramWithGio  2 ปีที่แล้ว

      Hey, glad you figured it out. The query looks correct, you do need to bind the values though which you did seems like, if you are still getting an error send me a DM on twitter & send me the screenshot of your actual code and I can help troubleshoot.
      About your first question, pdo_mysql is the correct driver for pdo mysql. You can also send me screenshot of your code on Twitter & I can take a look.

    • @themaridv2000
      @themaridv2000 ปีที่แล้ว

      ​@@ProgramWithGioif I use pdo_mysql, the rest of conections stop working because we have been using just mysql as the DB_DRUVER. I don't know what to do, should i create a new db service and create another db conection that uses pdo_mysql?

    • @benderbg
      @benderbg 5 หลายเดือนก่อน

      @mimoh2000 if you are still curious why you had problem with sql statement it was because of Doctrine 4.x version that no longer supports array parameters in executeQuery method. The work around is to use Doctrine 3.x that Gio used when he recoded this video. Moving to Doctrine 4.x requires different code like the one you suggested a year ago.

  • @po3881
    @po3881 ปีที่แล้ว

    In these later videos I find the moving blue background and animations distracting from the content. Just trying to help by mentioning.

  • @Netz0
    @Netz0 ปีที่แล้ว +1

    Don't use ORM's, just learn SQL, you will thank me later once your application suffers from badly joined queries as it keeps growing.

    • @ProgramWithGio
      @ProgramWithGio  ปีที่แล้ว +3

      I've been using ORMs for a long time along with raw SQL without any problems. I do agree that knowing SQL is essential without it you are just waiting for problems to happen, but if you know SQL and know how ORM works you will be able to build efficient queries

  • @ollakalla0
    @ollakalla0 2 ปีที่แล้ว

    Thank you very much for this video, If you can share with us the main class for \App\Enums\InvoiceStatus::tryFrom() that you are calling on th-cam.com/video/bfTIVQvS5JI/w-d-xo.html. I was having something like this before but your functions are very elegant and readable

    • @ProgramWithGio
      @ProgramWithGio  2 ปีที่แล้ว +1

      There is a link to the repo in the description that contains the code. tryFrom is part of the enums feature, you check the lesson about enums where we discuss that.

    • @ollakalla0
      @ollakalla0 2 ปีที่แล้ว +1

      @@ProgramWithGio Thanks a alot