我让我的XAMPP运行apache并运行mysql并尝试使用简单的mysql_connect
mysql_connect('localhost','root','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]的事情。这个$ i是什么?是否有多个服务器实例?
答案 0 :(得分:0)
试试这个:
$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;