简体   繁体   English

简单的mysql_connect函数不起作用

[英]Simple mysql_connect function not working

I have my XAMPP running up apache and mysql are running and try to a simple mysql_connect 我的XAMPP正在运行apache并且mysql正在运行,并尝试使用简单的mysql_connect

mysql_connect('localhost', 'root', 'test123'); mysql_connect('localhost','root','test123');

but the mysql_error() comes back with 但是mysql_error()回来了

Failed to connect to MySQL host. 无法连接到MySQL主机。 Access denied for user 'root'@'localhost' (using password: YES) 用户'root'@'localhost'的访问被拒绝(使用密码:是)

So, I open up config.inc.php inside myphpadmin and verified the credentials are correct. 因此,我在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';

The only thing I am not sure is the $cfg['Servers'][$i] thing. 我唯一不确定的是$ cfg ['Servers'] [$ i]东西。 What's this $i? 这$ i是什么? Are there multiple instances of Servers? 是否有多个服务器实例?

try this one: 试试这个:

$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!");

Edit: you create this script on a file, and use include function to the file that you want to use this connection.. 编辑:您在文件上创建此脚本,然后对要使用此连接的文件使用include功能。

this is my own setting on config.inc.php 这是我在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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM