0
I’m trying to communicate a program made in php with postgresql bd. I made a connected class, as shown below:
<?php
class conexao{
var $connect;
var $con_string = "host=localhost/TCC port=5432 dbname=TCC user=postgres password=123456";
function conexao(){
$this->connect = pg_connect($this->con_string);
}
function executarSQL($sql){
return pg_query($this->connect, $sql);
}
function prepararString($texto){
return '\''.$texto.'\'';
}
}
?>
and This is the class of index.php:
<?php
//session_start();
include ("classes/conexao.php");
$postgresql=new conexao;
if(isset($_POST['usuario'])){
$usuario=$postgresql->converte($_POST['usuario']);
$senha=$postgresql->converte($_POST['senha']);
$sql= 'select * from usuario where usuario='.$postgresql-
>prepararString($usuario).' and senha='.$postgresql->prepararString($senha);
$result = $postgresql->executarSQL($sql);
if (pg_num_rows($result) > 0){
$_SESSION['usuario']=$usuario;
header("Location: anexos/principal.php");
}else{
echo "<center><font align='center' size='5' color='RED'>O NOME DE USUÁRIO E SENHA DIGITADOS SÃO INCORRETOS.</a></font></center><br>";
}
}
else{
header("Location: login.php");
}
?>
I put all the code inside the xampp folder, htdocs, and I can see the site, however, when it comes to communicating with the bd, it contains this error:
Fatal error: Uncaught Error: Call to Undefined Function pg_connect() in C: xampp htdocs TCC Course Completion Work TCC SYSTEM src related classes.php:9 Stack trace: #0 C: xampp htdocs TCC Course Completion Work TCC SYSTEM src index.php(41): connectedness->connectedness() #1 {main} thrown in C: xampp htdocs TCC Course Completion Work TCC SYSTEM src related classes.php on line 9
Can anyone help me with this problem??? Thank you!
Check into your
php.ini
if you installed/activated the extension ofpostgresql
– Valdeir Psr
Need to install the postgres driver tried that procedure?
– rray
Hi guys, it worked out! I made the changes to the php.ini file and immediately started the communication. Thank you!
– Sbim