dstwfcz1377 2015-07-19 08:49
浏览 63
已采纳

致命! 用户postgres的身份验证失败,操作系统倍数,无效

This is my first time with Apache, php and postgresql. This is what I did:

  • I installed postgresql, wapp y pgadmin3,
  • I copied the file with my project in apache/htdocs,
  • open the index and try to enter in the user account of my web, but it said:

"Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[08006] [7] FATAL: the authentication failed for the user «'postgres'»' in C:\Bitnami\wappstack-5.5.27-0\apache2\htdocs\PROJECT\formss\class\connection.php:31 Stack trace: #0 C:\Bitnami\wappstack-5.5.27-0\apache2\htdocs\PROJECT\forms\class\connection.php(31): PDO->__construct('pgsql:host=127....', ''postgres'', ''12345'') #1 C:\Bitnami\wappstack-5.5.27-0\apache2\htdocs\PROJECT\forms\actions\user_login.php(6): connection->__construct() #2 {main} thrown in C:\Bitnami\wappstack-5.5.27-0\apache2\htdocs\PROJECT\forms\class\conection.php on line 31"

The pass that I set for the user postgress was 12345 in every step. Pgadmin3 let me change everything inside the db.

I already tried all these in Ubuntu but without a stack, it said the same. I checked the config of postgresql and see that for all the users say md5 like a lot of people suggest in other questions about this (yes, I searched and tried many solutions but they did not work for me).

The REAL problem is that with the exact same file, the project works in my office, with windows 7, now, with a clean installation of W7 and Ubuntu 14.04, don't want anything.

This is the connection code:

 <?php
    class connection {
        private $database;
        private $host;
        private $port;
        private $user;
        private $pass;
        public $db;
        public function __construct(){
            $this->user='postgres';
            $this->pass='12345';
            $this->host='localhost';
            $this->database='project';
            $this->port=5432;
            $this->db=new PDO("pgsql:host=".$this->host.
                ";port=".$this->port.
                ";dbname=".$this->database
                ,"'".$this->user."'"
                ,"'".$this->pass."'");
            $this->db->exec("SET CHARACTER SET utf8");
            return $this->db;
        }
        public function __clone(){
            trigger_error('The clone is not allowed', E_USER_ERROR);
        }
    }
?>
  • 写回答

1条回答 默认 最新

  • dongzhuifeng1843 2015-07-19 10:12
    关注

    As per the comment discussion, the code that creates the database connection seems to be problematic:

            $this->db=new PDO("pgsql:host=".$this->host.
                ";port=".$this->port.
                ";dbname=".$this->database
                ,"'".$this->user."'"
                ,"'".$this->pass."'");
    

    It is very unusual to wrap the username and password in quote marks, I have never see this before. We discovered in the comments that removing the quotes got the connection working again.

    You may wish to discuss with a colleague why the database server in the office works with this unusual approach. It is possible that user accounts are disabled in some fashion, perhaps because it is a LAN-only database, and all connections are permitted.

    It is also worth approaching the author of this code, in case they have some knowledge about the system that you do not. I would expect this unusual code to have been commented, so discussing it may be the next best thing.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建