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

Поділитися
Вставка
  • Опубліковано 11 вер 2024
  • 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.

КОМЕНТАРІ • 70

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

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

    Thanks for the most awaited series.

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

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

    You never fail 😄, thank you.

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

    Great video as always.

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

  • @omaryahia
    @omaryahia 8 місяців тому

    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  8 місяців тому +1

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

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

    The great Gio thanks alot ❤️

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

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

    That's amazing, thank you

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

    Great! Many thanks!

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

    wow great gio

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

    It was good tut... sure enough 😉

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

    nice tutorial

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

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

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

  • @user-gv8xg5bh1e
    @user-gv8xg5bh1e 7 місяців тому

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

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

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

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

    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 Рік тому

      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  Рік тому

      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 10 місяців тому

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

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

  • @expresscoding3525
    @expresscoding3525 11 місяців тому

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

    • @ProgramWithGio
      @ProgramWithGio  11 місяців тому

      Use \Doctrine\DBAL\ArrayParameterType::INTEGER

  • @mehdi-vl5nn
    @mehdi-vl5nn Рік тому

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

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

    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 )

  • @user-gv8xg5bh1e
    @user-gv8xg5bh1e 7 місяців тому

    How to create table with doctrine dbal dynamically ?

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

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

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

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

  • @po3881
    @po3881 11 місяців тому

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

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

  • @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 ua-cam.com/video/bfTIVQvS5JI/v-deo.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