am having little problem with SELECT statement in my PHP and MYSQL tutorial…when I connect to my database and I want to use PHP try-catch to SELECT the database content with the code below butI always get a PDOException error message that say “no database selected”
Thanks for getting back to me…This is the code am trying to run but each time I run the script I get the error message that says “no datebase selected”.
Not sure if it is a typo when placed on the forum, or if it really is a typo in your code, but I see a few small things (though I’m not sure if they are the cause yet)
You have
$pdo = new PDO('mysql:host=localhost;dbame =*****', user*****', 'pass*****');
Which I believe should be
$pdo = new PDO('mysql:host=localhost;dbame=*****', 'user*****', 'pass*****');
I removed an extra space after dbname (dobut this makes a difference), but it might
Added a ’ quote in front of user*****’
Also as a future FYI, if you place your code inside [ php ] and [/ php ] (without the extra spacing in between the , it will format it for you on the forum.
Only because we both steadfastly worked through a list of typos - and then I cheated by searching on the error message
@aosworks; When faced with problems like this read it, re-read it and if it still does not work type it out again, get used to doing that because it is part of the nature of the business.
We read things and re-read them but our brains tend to interpret what it thinks should be there, its an occupational hazard we have to bear. Using a good IDE which recognises PHP syntax will help a bit, but not in all cases.