Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 用户“apache”@“localhost”的访问被拒绝(使用密码:否)_Php_Mysql_Linux_Apache_Centos - Fatal编程技术网

Php 用户“apache”@“localhost”的访问被拒绝(使用密码:否)

Php 用户“apache”@“localhost”的访问被拒绝(使用密码:否),php,mysql,linux,apache,centos,Php,Mysql,Linux,Apache,Centos,我在CentOS 7中安装了LAMP 在我的案例中,当我将文件放在默认目录var/www/html中时 当我访问我的页面时,我收到以下信息: 错误:PB连接和服务mysql语言:fr 错误:PB de connexion� 多恩基地酒店�法兰西:法兰西 错误SQL:从参数中选择* 拒绝使用密码访问用户“apache”@“localhost”:否 以下是我的配置文件: $action = "action"; @error_reporting (E_ALL); @setlocale(LC_TI

我在CentOS 7中安装了LAMP

在我的案例中,当我将文件放在默认目录var/www/html中时 当我访问我的页面时,我收到以下信息:

错误:PB连接和服务mysql语言:fr 错误:PB de connexion� 多恩基地酒店�法兰西:法兰西 错误SQL:从参数中选择* 拒绝使用密码访问用户“apache”@“localhost”:否

以下是我的配置文件:

$action  = "action";


@error_reporting (E_ALL);
@setlocale(LC_TIME, 'french');


$host     = "localhost";

$user     = "";
$password = ""    ;


 //---> La langue utilisée (fr, en, ar)
 global $lang ;
 $lang             = isset($_REQUEST["lang"])? $_REQUEST["lang"] : "";
 switch($lang)
 {
 case "ar"  :  $lang = "ar" ; break;
 case "en"  : $lang = "en" ; break;
 case "fr"   :  $lang = "fr" ; break;
 default        : $lang = "fr" ; //---> La langue par défaut
 } //Fin switch





 global $lang_param;

$lang_param = array
          (
            //---> principal = TRUE
             "fr" => array(
                           "host"        => "localhost"         ,
                           "db"          => "database_fr"             ,
                           "user"        => "user1"              ,
                           "password"    => ""                  ,
                           "chemin"      => "fr"                ,
                           "description" => "Langue française"  ,
                           "short"       => "Français"          ,
                         ),
                         //---> principal = FALSE
           "en" => array(
                           "host"        => "localhost"         ,
                           "db"          => "database_en"           ,
                           "user"        => "user1"              ,
                           "password"    => ""                  ,
                           "chemin"      => "en"                ,
                           "description" => "Langue anglaise"   ,
                           "short"       => "Anglais"           ,
                         )  ,


             "ar" => array(
                           "host"        => "localhost"         ,
                           "db"          => "database_ar"             ,
                           "user"        => "user1"              ,
                           "password"    => ""                  ,
                           "chemin"      => "ar"                ,
                           "description" => "Langue arabe"  ,
                           "short"       => "Arabe"          ,
                         )           


          ); //Fin $lang_param




//---> Se connecter
$r = @mysql_pconnect($lang_param[$lang]["host"], $lang_param[$lang]       ["user"], $lang_param[$lang]["password"]); 
if ($r==0) 
{
 echo "Erreur : PB de connexion au serveur mysql de la langue :    $lang<br>";
 } //Fsi

  $r = @mysql_select_db($lang_param[$lang]["db"]);
 if ($r==0) {
   echo "Erreur : PB de connexion à la base de données de la langue : $lang<br>";
  } //Fsi

我如何获得访问权限apache@localhost?

应在$user变量中定义一个帐户

尝试根帐户

$user='root'


请注意,没有密码的根帐户会使您的web服务器不安全,请尽快进行设置。您应该创建一个用户:

CREATE USER 'user'@'localhost' IDENTIFIED BY 'mypass';
并授予您尝试连接的数据库的权限:

GRANT ALL PRIVILEGES
ON database.*
TO 'user'@'%';

之后,您必须在代码中填写变量$user和$password。

这也很好,但请确保用户也能正确访问以下数据库。感谢您的回复。是的,我创建了一个具有完全权限的用户userx,问题仍然是一样的。别忘了接受答案,并投票选出对你有帮助的答案!我的根目录受到了强大的MDP保护,谢谢,但是当我能找到$user的默认定义时,它不在我的代码中???你在另一条评论中提到你添加了一个帐户,是吗?您可以在“帐户”下的phpmyadmin中查看此信息