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.
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
That's awesome, thank you 💙
Thanks for the most awaited series.
Thank you for your support 💙
Can you make some videos on SOLID principles as well? Your content will be the best one in the entire internet.
Thank you. Yes might do that in separate series
You never fail 😄, thank you.
😁. Thank you
Great video as always.
Thanks you
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".
Yup, thank you for the note. We use older version in this recording but later videos we have up to date version.
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
Thats fine, you might like the active record pattern ORM like Eloquent from Laravel
The great Gio thanks alot ❤️
Thank you 🙌
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 ♥
Thank you. It's a setting in my IDE under Code Style (PhpStorm).
@@ProgramWithGio what extra setting parameter you use, can you tell, I also want that one 😊
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.
Appreciated! Thank you so much 😊 ♥ ♥ ♥ ♥ ♥
That's amazing, thank you
You're welcome 👍
Great! Many thanks!
You're welcome 🙌
wow great gio
Thank you
It was good tut... sure enough 😉
Thanks 😁
nice tutorial
Thank you
Thanks a lot for that video!! .. And so on! lol
You're welcome, & so on :D
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?
ctrl + alt + l if it doesnt work then you can adjust the alignment from the phpstorm settings for PHP
Hello, thank you for all these videos. Please tell me how autoload Dotenv\Dotenv. I can do it 'composer require symfony/dotenv' ?
We covered that in second section, search the playlist, you will find it
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.
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.
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.
@@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?
@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.
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.
Glad you figured it out
Hello sir, at 9:50, I see [\Doctrine\DBAL\Connection::PARAM_INT_ARRAY] this part is deprecated, what to do?
Use \Doctrine\DBAL\ArrayParameterType::INTEGER
so an Orm plays as data access and business layer at the same time in a Laravel app for instance?
Yes pretty much
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 )
Hello. In this case yes because we are using where IN().
@@ProgramWithGio Got it, thank you!
How to create table with doctrine dbal dynamically ?
You would typically use migrations, what do you mean by dynamically & what would be the use case?
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?
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
@@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.
@@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
Which exception does the \Doctrine\DBAL\DriverManager::getConnection()
throws
You can inspect th get connection method and see. I don't remember off the top of my head
In these later videos I find the moving blue background and animations distracting from the content. Just trying to help by mentioning.
Thanks for the feedback
Which sql driver is better to use.
Whichever you like. I use mysql
@@ProgramWithGio well the doctrine does not support mysql does it have any reason for that
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.
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.
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
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
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.
@@ProgramWithGio Thanks a alot