mindapolis Posted November 13, 2015 Share Posted November 13, 2015 Hi, I'm new to PDO. Can someone tell me what this error message means? SQLSTATE[42000] [1044] Access denied for user 'mediasvcunltd'@'monolith.xymmetrix.net' to database 'mysql' Quote Link to comment https://forums.phpfreaks.com/topic/299464-error-meaning/ Share on other sites More sharing options...
benanamen Posted November 13, 2015 Share Posted November 13, 2015 (edited) It means the user/password you are connecting to the DB with does not have permission to access. Possible wrong username and/or password. Edited November 13, 2015 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/299464-error-meaning/#findComment-1526301 Share on other sites More sharing options...
mindapolis Posted November 13, 2015 Author Share Posted November 13, 2015 That's strange. I can connect to it with the old PHP code. Oh wait, is this line of code correct? $db = new PDO("mysql:host=$hostname;dbname=mysql", $username, $password); Yes, i did declare the variables beforehand. Quote Link to comment https://forums.phpfreaks.com/topic/299464-error-meaning/#findComment-1526302 Share on other sites More sharing options...
benanamen Posted November 13, 2015 Share Posted November 13, 2015 Your connecting to the wrong database. replace mysql with YOUR database name $db = new PDO("mysql:host=$hostname;dbname=mysql", $username, $password); Quote Link to comment https://forums.phpfreaks.com/topic/299464-error-meaning/#findComment-1526303 Share on other sites More sharing options...
mindapolis Posted November 13, 2015 Author Share Posted November 13, 2015 I changed the database name $db = new PDO("mysql:host=$hostname;dbname=hercules.xymmetrix.net", $username, $password); but it say SQLSTATE[42000] [1044] Access denied for user 'mediasvcunltd'@'monolith.xymmetrix.net' to database 'hercules.xymmetrix.net' Quote Link to comment https://forums.phpfreaks.com/topic/299464-error-meaning/#findComment-1526304 Share on other sites More sharing options...
benanamen Posted November 13, 2015 Share Posted November 13, 2015 (edited) Post your entire connection code. Hide your username and password Edited November 13, 2015 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/299464-error-meaning/#findComment-1526305 Share on other sites More sharing options...
mindapolis Posted November 13, 2015 Author Share Posted November 13, 2015 <?php require_once('functions.php'); $hostname = "hercules.xymmetrix.net"; $username = "..."; $password = "..."; try { $db = new PDO("mysql:host=$hostname;dbname=hercules.xymmetrix.net", $username, $password); echo 'Connected to database'; } catch(PDOException $e) { echo $e->getMessage(); } ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <form action ="contactUs.php" method="post"> <label> <input id = "fname" type="text" name="fname" size="15" placeholder="First Name" value ="<?php echo !empty($_POST['fname']) ? $_POST['fname'] : '';?>" > <?php echo !empty($error['fname']) ? $error['fname'] : '';?> <input type="text" name="lname" size="20" placeholder="Last Name"><?php echo !empty($error['lname']) ? $error['lname'] : '';?> <input type="text" name="orgName" placeholder="Organization's Name"maxlength="50"> </label><br /> <label> <!--new row --> <input id = "address" type="text" name="address" size="15" placeholder="Street Addresss" maxlength="50"> <input id = "city" type="text" name="city" placeholder="City" size="10" maxlength="25"> <select id = "state" name = "state" placeholder="State" value=""> <option value ="Please choose a state"> Please choose a state </option> <?php states($state); ?> </select> <input id = "zipcode" type="number" name="zipcode" placeholder="Zip Code" size="5" maxlength="5"> </label><br /> <label> <!--new row --> <input type="text" name="phone" placeholder="Phone Number:(including area code)" size="10" maxlength="10"> </label> <input type="text" name="fax" size="10" placeholder="Fax Number: (including area code)" maxlength="10"> </label><br /> <label> <!--new row--> <input type="text" id = "email" name="email" placeholder="Email Address" /> <input type="text" id = "confirmEmail" name="ConfirmEmail" placeholder="Confirm Email Address" /> </label><br /> <label> <!--new row --> What would you like help with? <table id="projectOptions"> <tr span=2> <td><input type="checkbox" name="SocialMedia">Social Media </td> <td><input type="checkbox" name="WebContentManagement">Web Content Management </td> </tr> <tr> <td><input type="checkbox" name="MarketingMaterials">Marketing Material Creation </td> <td><input type="checkbox" name="SEO">SEO (Search Engine Optimization) </td> </tr> <tr> <td><input type="checkbox" name="VideoEditing"> Video Editing </td> <td><input type="checkbox" name="WebDesign">Web Design </td> </tr> </table> </label> Overview about the project:<textarea rows="5" cols="10" placeholder="Overview of Project"></textarea> <br /> If you are not a robot, what year is it? <input type="text" name="year" size="4" maxlength="4"><br /> <input type="submit" name="submit" value="Contact Me!"> <input type="reset" name="reset" value="Cancel"> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/299464-error-meaning/#findComment-1526307 Share on other sites More sharing options...
benanamen Posted November 13, 2015 Share Posted November 13, 2015 There is nothing wrong with the connection code. If the same username, password and DB name works in your other code it should work in this code. Quote Link to comment https://forums.phpfreaks.com/topic/299464-error-meaning/#findComment-1526311 Share on other sites More sharing options...
mindapolis Posted November 13, 2015 Author Share Posted November 13, 2015 then why be am I getting that error on http://mediaservicesunlimited.com/contactTest.php the database name is hercules.xymmetrix.net. Would that make a difference? Quote Link to comment https://forums.phpfreaks.com/topic/299464-error-meaning/#findComment-1526312 Share on other sites More sharing options...
Jacques1 Posted November 13, 2015 Share Posted November 13, 2015 I'm fairly sure the name of your database is not hercules.xymmetrix.net. That might be the hostname, but not the actual database name. Since trial-and-error won't help in this situation, you'll have to figure out your database credentials. What does your old code say? 1 Quote Link to comment https://forums.phpfreaks.com/topic/299464-error-meaning/#findComment-1526313 Share on other sites More sharing options...
mindapolis Posted November 17, 2015 Author Share Posted November 17, 2015 I'm sorry I got confused. The hostname is hercules.xymmetrix.net and the database name is www_media_services_unlimited but I'm getting get the same error. SQLSTATE[42000] [1044] Access denied for user 'mediasvcunltd'@'monolith.xymmetrix.net' to database ' www_mediaservicesunlimited_com' $hostname = "hercules.xymmetrix.net"; $username = ""; $password = ""; try { $db = new PDO("mysql:host=$hostname;dbname= www_mediaservicesunlimited_com", $username, $password); echo 'Connected to database'; } catch(PDOException $e) { echo $e->getMessage(); } Quote Link to comment https://forums.phpfreaks.com/topic/299464-error-meaning/#findComment-1526504 Share on other sites More sharing options...
Solution mindapolis Posted November 17, 2015 Author Solution Share Posted November 17, 2015 Got it fixed ! Quote Link to comment https://forums.phpfreaks.com/topic/299464-error-meaning/#findComment-1526505 Share on other sites More sharing options...
benanamen Posted November 17, 2015 Share Posted November 17, 2015 After all this dont you think you should tell us what was wrong? Quote Link to comment https://forums.phpfreaks.com/topic/299464-error-meaning/#findComment-1526506 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.