datatables with php, jquery and postgresql

0

Good day, I have been working without any problem with datatables, php and mysql, but when trying to use the plugin with Postgresql it has not worked, I do not know if it requires any additional configuration. in advance I appreciate any help or recommendation.

If someone has a link showing examples of datatables and postgres, I would be very grateful.

    
asked by omjimenez29 08.02.2018 в 23:59
source

1 answer

0

Recently I had the same problem but luckily for both I could solve it, then I leave everything I have done to work with databases in postgres;

Personally I use WAMP server and manage the connection with PDO and its methods;

The first thing is to open the file php.ini and within the file find the line “extension=php_pdo_pgsql.dll” which will have a semicolon in front (;) , this is removed and the wamp is restarted. This to use PDO with postgres

To make the connection you can take the following code as an example;

file: dbconfig_postgres.php

<?php

$host='127.0.0.1';
$db = 'mi_base_datos';
$username = 'postgres';
$password = '1706';

?>

file: conexion_postgres.php

<?php
require_once 'dbconfig_postgres.php';
    $dsn = "pgsql:host=$host;port=5432;dbname=$db;user=$username;password=$password";

try{
    $base_postgres = new PDO($dsn);
    $base_postgres->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    //echo "Conexion correcta PostGres";

}catch (PDOException $e){
    echo "BD fuera de servicio";
}
?>

already configured the connection is only to make queries, I leave you an example;

    include('conexion_postgres.php');
    $registros=$base_postgres->prepare('Select id,nombre,correo  From "mi_esquema"."mi_tabla"');                

    $registros->execute(array());
    //Por si quieres saber cuantos registros arrojo la consulta
    $registros = $registros_niscap->rowCount();

    $registros = $registros->fetchAll( PDO::FETCH_OBJ );

Assuming that you know how to use PDO, the rest is accessed through an indexed array or with a foreach.

Anyway, any question I can continue editing the answer to add what you need.

    
answered by 09.02.2018 в 00:32