【问题标题】:Simple mysql_connect function not working简单的 mysql_connect 函数不起作用
【发布时间】:2012-02-21 01:42:32
【问题描述】:

我的 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?是否有多个服务器实例?

【问题讨论】:

标签: php mysql


【解决方案1】:

试试这个:

$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;

【讨论】:

猜你喜欢
  • 2012-09-24
  • 1970-01-01
  • 2012-12-05
  • 1970-01-01
  • 2013-03-23
  • 1970-01-01
  • 1970-01-01
  • 2015-08-16
  • 2015-06-21
相关资源
最近更新 更多