[英]Simple mysql_connect function not working
我的XAMPP正在运行apache并且mysql正在运行,并尝试使用简单的mysql_connect
mysql_connect('localhost','root','test123');
但是mysql_error()回来了
无法连接到MySQL主机。 用户'root'@'localhost'的访问被拒绝(使用密码:是)
因此,我在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是什么? 是否有多个服务器实例?
试试这个:
$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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.