我正在运行我的XAMPP,apache和mysql都在运行,并尝试创建一个简单的mysql_connect
Mysql_connect(‘本地主机’,‘根’,'test123');
但是mysql_error()返回的结果是
无法连接到MySQL主机。拒绝用户'root'@'localhost‘的访问(使用密码: YES)
因此,我在myphpadmin中打开了config.inc.php,并验证了凭据是否正确。
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'config';
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'test123';
$cfg['Servers'][$i]['connect_type'] = 'socket';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = true;
/* Select mysqli if your server has it */
$cfg['Servers'][$i]['extension'] = 'mysql';我唯一不确定的是$cfg‘’Servers‘这件事。这是什么$i?是否有多个服务器实例?
发布于 2012-02-21 09:49:07
试试这个:
$hostname_koneksi = "localhost";
$database_koneksi = "your_database";
$username_koneksi = "your_username";
$password_koneksi = "your_password";
$koneksi = mysql_pconnect($hostname_koneksi, $username_koneksi, $password_koneksi) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_koneksi) or die("Can't open the database!");编辑:您可以在一个文件上创建此脚本,并对要使用此连接的文件使用include函数。
这是我自己在config.inc.php上的设置
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
/* Select mysql if your server does not have mysqli */
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['AllowNoPassword'] = true;https://stackoverflow.com/questions/9370987
复制相似问题