0
4

3 回答 3

2

Shouldn't you still use localhost as $host if you're trying to connect via the application? The script is on the same server as the DB.

于 2012-08-15T03:48:50.270 回答
0

Ah, this is always the most annoying part of the process. Try this and see if it works:

$host="127.0.0.1";  // "localhost" should work, but don't count on it
$username="user"; // username you use to log into phpMyAdmin
$password="password"; // password you use to log into phpMyAdmin
$db_name="dbname"; // database you want to connect to

You'll need to have created this user/password pair and given them the appropriate permissions to access the database. Also note that the mysql PHP functions are deprecated and should not be used. PDO or mysqli are the preferred ones going forward.

于 2012-08-15T03:49:55.387 回答
0

If you are using cPanel, when you create the MySQL table, make sure you assign your user to it (trivial, I know, but Ive forgotten about it a few times myself.)

If your script is running from your remote server, just stick with localhost. Will work fine.

Last, my only suggestion until a better answer is said, try using

$host = 'localhost';
$user = 'username'; // Im pretty sure your username isn't root.
$pass = '1234';
$db = 'partnership'; 
/* Alot of hosts like to append your cPanel login to your db and username fields.
Check to see what your table is. It might actually be 'youruser_partnership'  */

$mysqli = new mysqli($host, $user , $pass, $db);
if (mysqli_connect_error()) {
    die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
}

If your host supports mysqli (most do). If not, when you do your die statement, still use die(mysql_error()); to get the exact error. It will more than likely be your username/password you created and assigned to your database

于 2012-08-15T05:02:54.440 回答