-1
I’m having a problem connecting to the database, more specific to register a value
I tried to make the connection here
class Dbconnection{
private $conn;
function __construct(){
$this->conn = pg_connect("host='localhost' port='5432' dbname='desafio_softexpert' user='postgres' password='****'") or die("cannot connect to DB");
}
public function get_conn(){
return $this->conn;
}
}
and here wanted the variable Conn receive the return of the connection, but an error
include("./DB/DBConnection.php");
$DBConnection = new DBConnection();
$conn = $DBConnection->get_conn();
function insert_in_DB($query){
$result = pg_query ($conn, $query);
if (!$result)
echo "query did not execute";
$rs = pg_fetch_assoc($result);
if (!$rs)
echo "0 records";
you just forgot to put public in the construction Function even.. <? php class Dbconnection { private $Conn; public Function __Construct() { ... , if you do so it will work normal. in error says that the variable is Undefined or is without definition
– Luciano Alves