I’m learning php and I’m having trouble connecting to a database in mysql. my code - https://pastebin.com/SV0cTbcd I’m not sure what I’m doing wrong here or how to trouble shoot this since no error is showing up, I’m only having the error being catched so in my browser ‘cant connect’ keeps showing up instead of whats in my database. My dbname is correct so I think something is wrong with the mysql:host=127.0.0.1, but I’m not sure and don’t know how to check how to fix it. I’d appreciate any help with this.
EDIT when I changed <?php 'mysql:host=localhost; ? > this line of code to localhost instead of 127.0.0.1, I’m not catching an error anymore, but my rows in my database aren’t showing and I’m not sure why. Is there any way to confirm my database is connecting correctly or am I printing the database rows incorrectly?
Based on your description, it looks like the problem occurs when you are trying to connect to your database.
To get a better idea what is going wrong, you could change the error you are catching. If you change the following lines:
I solved it. The error wasn’t showing up because it was a string I guess, but I’m not sure how to debug this since I’m just learning php. It was a typo here ;dbname:mytodo’, should have been dbname=mytodo, and after I fixed that its working. Thanks for trying to help tomvbe.