YigalB Posted July 21, 2012 Share Posted July 21, 2012 I am learning mysql using an example. According to the guidelines, I created a table and I was trying to access it with the following code: <?php define("MYSQLUSER", "php24sql"); define("MYSQLPASS", ""); define("HOSTNAME", "localhost"); define("MYSQLDB", "smithside"); $connection = @new mysqli(HOSTNAME, MYSQLUSER, MYSQLPASS, MYSQLDB); if ($connection->connect_error) { die('Connect Error: ' . $connection->connect_error); } else { echo 'Successful connection to MySQL <br />'; if ($result = $connection->query("SHOW TABLES")) { $count =$result->num_rows; echo "Tables: ($count)<br />"; while ($row = $result->fetch_array()) { echo $row[0]. '<br />'; } } } I got the following error: Connect Error: Access denied for user 'php24sql'@'localhost' (using password: NO) At first, I was sure it's the password, so I changed to "no password" using phpMyAdmin, but I still get the above error. Here is what I see at phMyAdmin: Users having access to "smithside" User Host Type Privileges Grant Action php24sql % global SELECT, INSERT, UPDATE, DELETE No Edit Privileges php24sql localhost global SELECT, INSERT, UPDATE, DELETE No Edit Privileges root linux global ALL PRIVILEGES Yes Edit Privileges root localhost global ALL PRIVILEGES Yes Edit Privileges Quote Link to comment https://forums.phpfreaks.com/topic/266057-need-help-with-first-time-mysqli-access-from-php/ Share on other sites More sharing options...
jcbones Posted July 21, 2012 Share Posted July 21, 2012 Can you log into the MySQL console? Windows: ->cmd ->cd (to your mysql directory) ex. wamp is C:/wamp/bin/mysql/mysql(version)/bin/ ->mysql -u php24sql -p; it will prompt you for a password. If you are not using one, hit enter and it will let you in, or throw an error. I hope this was clear for you. *note, if you are using wampserver, you can just choose the mysql console from the tray. Quote Link to comment https://forums.phpfreaks.com/topic/266057-need-help-with-first-time-mysqli-access-from-php/#findComment-1363351 Share on other sites More sharing options...
jazzman1 Posted July 21, 2012 Share Posted July 21, 2012 @ jcbones, the console is very hard to understand for people comming from Microsoft's world @YigalB, open up your phpmyadmin application, go to "SQL" tab (on the top), and copy/paste this code: GRANT ALL PRIVILEGES ON `db_base` . * TO 'php24sql'@'localhost'; Quote Link to comment https://forums.phpfreaks.com/topic/266057-need-help-with-first-time-mysqli-access-from-php/#findComment-1363356 Share on other sites More sharing options...
YigalB Posted July 21, 2012 Author Share Posted July 21, 2012 Can you log into the MySQL console? Windows: ->cmd ->cd (to your mysql directory) ex. wamp is C:/wamp/bin/mysql/mysql(version)/bin/ ->mysql -u php24sql -p; it will prompt you for a password. If you are not using one, hit enter and it will let you in, or throw an error. I hope this was clear for you. *note, if you are using wampserver, you can just choose the mysql console from the tray. Thanks! I am using XAMPP. I followed your guide lines and got: ERROR 1045 (28000): Access denied for user 'php24sql'@'localhost' (using password: YES) Then I re-entered the original password - and it worked! Thanks ! I am not sure what happen, because I marked "no password" and "go" at phpMyAdmin, but now it seems the need for password is still there. Quote Link to comment https://forums.phpfreaks.com/topic/266057-need-help-with-first-time-mysqli-access-from-php/#findComment-1363357 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.