0

So, basically what I am doing is a small system that allows students to take online tests and teachers can post an exam and let them know when they have it It was all good while we worked in localhost, but then one of our requests was to use PostgreSQL instead for the database, which seemed cool to us But now we are havving this issue while logging in

Database is already filled with the users and passwords, but it no longer allows us to acces the system no matter if we put a correct password/username set, or actually create a new account

This is the Connection.php file

<

?php

class Connection {
  private static $instance;
  private $connection;

  private function __construct()
  {
    $cadena = "host='localhost' port='5432' dbname='newdb' user = 'postgres' password = 'system'";
    $this->connection = pg_connect($cadena) or die ('Error');
    $this->query("SET TIME ZONE -4");
  }



  public static function getInstance(){

    if (!isset(self::$instance))
      self::$instance = new Connection();

    return self::$instance;
  }

  public function query($aQuery){
    //echo "$aQuery<br>";
    return pg_query($this->connection, $aQuery);
  }

}

?>

Error always comes up on line 10 ($this->connection = pg_connect($cadena)) Saying that the pg:connect function is undefined, and given we are not experienced with the use of PG, I was hoping you could help us

Sorry if my english fails, as it is not my first language after all

  • Was PHP compiled with [support for PostgreSQL](http://php.net/manual/en/pgsql.installation.php)? When compiling, you have to include the `--with-pgsql[=DIR]` flag. According to one of the comments, if you are using a Debian based system you can install the plugin afterwards using `sudo apt-get install php5-pgsql`; however, I have not tried this before. – c1moore Jul 16 '16 at 16:59
  • Also, remove the white spaces around the `=` operator. `pg_connect` uses white spaces to distinguish between parameters. – c1moore Jul 16 '16 at 17:28

1 Answers1

0

Try to use below line to make connection string:

$cadena = "host=localhost port=5432 dbname=newdb user=postgres password=system";

Daisy
  • 63
  • 7