PDA

Click to See Complete Forum and Search --> : [RESOLVED] mysql database user


sridharao
Jul 16th, 2009, 12:36 PM
It might be a stupid question, but is a question nonetheless. On my desktop with wampserver on, I have been connecting to all the databases with a common username and password.
mysql_connect("localhost","root","password")
When I create database on the server hosting my site, I realize that I can't have same username for two databases. In my php files, I had used the above code to establish connection to whichever database I required. Now, I will have to alter the code specifically for each of the databases.
Is there an alternative to this? Can I use localhost and root on my server?

kfcSmitty
Jul 16th, 2009, 01:05 PM
Create a user and give them access to the databases.

Users should never be using root access to access your databases. Limiting them to the basics of what they need is best.

If you have phpMyAdmin, it has a fairly simple interface to achieve this.

SambaNeko
Jul 16th, 2009, 03:21 PM
You can usually still use "localhost" for the connection, unless your host specifies something else. And you know that mysql_connect() isn't what selects your database, right? mysql_select_db() does that. I believe you can, in fact, have the same login work for multiple databases if it has permissions to both.

As kfcSmitty said, you should never have your scripts connecting as "root," the problem being that it has full access to your database: it can read from, write to, truncate, or drop any table in the database. You want to limit access to curtail the malicious things that can be done.

sridharao
Jul 18th, 2009, 08:47 AM
:check:Thanks to both of you.
I might not get rights on localhost on the server, so I decided to have separate users of databases even though I had to type few more lines of codes.