Jump to content

Learning PHP mySQL


impresario

Recommended Posts

When I say I'm a noobie, I'm not kidding!

 

I'm using a hosting service (Bluehost) that offers PHP 5.4.30 and mySQL 5.5.37 and am trying to work through a beginners tutorial. Using the service's PHPMyAdmin tool, I have no trouble creating a database and table that I can manipulate using this tool. My problem is with my very first php command:

 

$db = new mysqli(localhost, 'me', 'pw', 'RR');

 

'me' and 'pw' are my Bluehost signon credentials that were also required to get into the PHPMyAdmin tool. 'RR' is the actual name of the database I'd created. I'm not sure if these are what mySQL is looking for. I also tried 'root' and a null password as done in the tutorial, but that didn't help. The message I get is:

 

Connect failed: Access denied for user 'me'@'localhost' to database 'RR'

 

I'd love to get somewhat proficient on PHP/mySQL. Please help.

Link to comment
Share on other sites

i moved your thread to the php coding help forum section, since the problem is in getting your php code to connect to the database server.

 

your web host has a FAQ section that explains what you must use for the database username and database name in your php code - https://my.bluehost.com/hosting/help/318

 

it prepends your hosting account's username and to the database username and database name you picked.

 

also, localhost needs to be quoted in the php code, 'localhost', so that it is not treated as a defined constant first.

 

lastly, for learning and development, you should do this on a local pc/laptop as you will waste a bunch of time constantly FTP'ing/uploading code and data to a live server (and needing to conform that the FTP/upload worked in its entirety) just to see the result of each change.

Link to comment
Share on other sites

$db = new mysqli(localhost, 'me', 'pw', 'RR');

 

'me' and 'pw' are my Bluehost signon credentials that were also required to get into the PHPMyAdmin tool. 'RR' is the actual name of the database I'd created. I'm not sure if these are what mySQL is looking for.

 

Your database should have a different username/password than your credentials for accessing your web host interface. Are you SURE those are the credentials for accessing PHPMyAdmin? For my host, once I access the administration panel for my Databases, there are buttons to launch PHPMyAdmin. When I click those buttons it launches PHPMyAdmin automatically without an additional login. That's not because the username/password for those is the same as I used to get the the admin panel, it is because the credentials are being sent behind the scenes. Check your administration area for your databases and you should see information about the user or users for the database. The password may not be something you can "see". But, you should be able to "edit" the user and change the password.

Link to comment
Share on other sites

I'm gonna guess that your provider gave you a uid/pswd to access the administration function of your site - cPanel perhaps?  That gives you access to the phpadmin tool where you create dbs and tables in your dbs.  Each db that you create has to have a userid and pswd created for it since in the long run not all users are going to have access to all your tables in all your dbs (in most situations).  Be sure that you have done that before trying to connect.  You may have missed that step when creating the db.  I use just one set so that all of my connections use the same ones and I only have to create one standard module to do the connecting in any of my scripts.

 

PS - Keep that uid/pswd that logs you into cpanel/phpadmin extremely private.  It should not be used anywhere else (meaning don't use the same creds again for a db or an email account)..  Period.  It is the single most important of data you have that controls your entire site.

Edited by ginerjm
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.