i had created and connected datatables to postgresql.
this is my connection code. may i have two connection called pg_query, and how i can make a right code? i try for 2 days and still stuck
<?php
$conn = "host=localhost port=5432 dbname=test user=postgres password=password";
$connection = pg_connect($conn);
if (!$connection) {
print("failed");
exit;
}
else print("Connection Success");
?>
this is my datatables code
<?php
include_once("connection.php");
$params = $columns = $totalRecords = $data = array();
$params = $_REQUEST;
$columns = array(
0 =>'id',
1 =>'employee_name',
2 => 'employee_salary',
3 => 'employee_age'
);
$where = $sqlTot = $sqlRec = "";
$sql = "SELECT * FROM employee ORDER BY employee_name";
$sqlTot .= $sql;
$sqlRec .= $sql;
$sqlRec .= "ORDER BY employee_name";
$queryTot = pg_query($conn, $sqlTot)or die("database error:");
$totalRecords = pg_num_rows($queryTot);
$queryRecords = pg_query($conn, $sqlRec) or die("error to fetch employees data");
while( $row = pg_fetch_row($queryRecords) ) {
$data[] = $row;
}
$json_data = array(
"draw" => 1,
"recordsTotal" => intval( $totalRecords ),
"recordsFiltered" => intval($totalRecords),
"data" => $data
);
echo json_encode($json_data);
print_r ($json_data);
?>