05.
Talking to Databases in PHP
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
15 Comments
I'm not using xampp to go through these examples. Just thought I'd point out that I had to change 'host=localhost' in the PHP code to 'host=127.0.0.1' in order to get this to work. Loving the tutorials though ;)
Hey Lucio S.!
Good tip! 127.0.0.1 is probably better anyways - that's your REAL local IP address. Most systems also allow "localhost" as a sort of alias to 127.0.0.1... but as you proved, 127.0.0.1 is more portable because it *always* works :).
Cheers!
Hi,
Where to download the project?
Regards,
Ricardo
Hey Ricardo,
You can download the project code for the current tutorial on any chapter page, e.g. on the one where you asked your question: https://symfonycasts.com/screencast/php-ep3/php-talks-to-mysql
See the "Download" -> "Course Code" button in the right top corner of this page. This specific course is paid, so you need to own this course or being an active subscriber on SymfonyCasts to download it.
Cheers!
Hi,
When I use PDO module, I. am receiving below error in my web server error_log. I am trying to add this extension PDO module but still having problem.
Have you seen this problem before?
Hi again,
After searching google, I understand that
pdo_mysqlmodule is missing. I installed byyum install php-pdo_mysqland checked withphp -m, then restart httpd server. now working.Additionally, could you please help me to show output of db in nice way? I see as below.
Hey Mahmut,
Yes, exactly! Good catch :) You need to install and enable. that
pdo_msql, thanks for sharing it with others!What do you mean?
If you want a nice debug styles - you can leverage Symfony VarDumper component, use
dump()ordd()to make the debug output nicer :)Cheers!
actually, when I use var_dump(), it outputs in one line all array. In video, it is shown line per line. How can I enable it on my browser.
for json output, I am using JSONVue.
Hey @Mahmut-A!
I think I know the problem :). There is a PHP extension called "XDebug". If you have this installed, then
var_dump()will output in the fancier way that you see in the video. I bet this is what you need to match the video output you see.Cheers!
thank you so much. worked
PHP Fatal error: Uncaught PDOException: could not find driver in /Users/shubham/AirPup/index.php:2
Stack trace:
#0 /Users/shubham/AirPup/index.php(2): PDO->__construct('mysql : dbname=...', 'root', 'Titanic@123')
#1 {main}
thrown in /Users/shubham/AirPup/index.php on line 2
[Sat Jul 3 18:50:40 2021] [::1]:58302 [500]: / - Uncaught PDOException: could not find driver in /Users/shubham/AirPup/index.php:2
Stack trace:
#0 /Users/shubham/AirPup/index.php(2): PDO->__construct('mysql : dbname=...', 'root', 'Titanic@123')
#1 {main}
thrown in /Users/shubham/AirPup/index.php on line 2
I am stuck at this, I dont have server installed on my mac but why this PDO line is creating such errors I have the pdo_mysql module in my php
Hey Shubham,
Hm, please, make sure your DB credentials are correct first and you didn't make any typos in it. If everything looks good, try to restart the server, I'd recommend you to restart your laptop just in case and try again. The error really sounds like you don't have pdo_mysql module, maybe if you started the server and installed it after - the already running server does not see it, so you have to restart.
If you're still experiencing this error even after laptop restart - please, share a bit more information, what do you do to see this error? Do you run it in your terminal? What command? What OS do you use?
I hope this helps!
Cheers!
Cheers!
hey,
we didn't talked about the object-operator -> yet. Did we?? Would be nice to introduce that...
happy I found https://stackoverflow.com/questions/3037526/where-do-we-use-the-object-operator-in-php
Aha, there is also a scope operator :: hm, hm ...
Hey eltnap !
Ah, you're right! We talk about that in the NEXT chapter - https://symfonycasts.com/sc... - so I was just a minute too early! I think I wanted to get some "database query" success before we dove into some object-oriented stuff. So, while we "touch" on the object-oriented stuff in this tutorial, we have a few other proper tutorials on that topic - https://symfonycasts.com/sc...
From an object-oriented perspective, the -> operator is use to call a method on an instance of an object. The :: is used to call a static method on a class. We actually don't talk at all about static methods until episode 4 of our object oriented series - https://symfonycasts.com/sc... - in part because they "should be" rarely used (using objects typically will lead you to better code) and so I only wanted to introduce them later.
Anyways, I probably just dumped more details than you needed - but let me know if this is helpful or if you have any other questions :).
Cheers!
Thank You Ryan.
And Sorry. Five minutes after my post I was taught not to be too fast in wondering....
Stay save and happy holidays to all of the team!
"Houston: no signs of life"
Start the conversation!