[英]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.