PHP SQL syntax (postgresql)

  php, postgresql

I am learning PHP and I am writing a simple program which calls my database but I am getting the following error and not sure how to resolve it: pg_query(): Query failed: ERROR: syntax error at or near ","nLINE 1: ...ontactTitle, Address, City, Country FROM customers LIMIT ?,? in C:Apache24htdocstestdata.php on line 17.

Which it’s referring to the following code:

<?php
include('connect.php');
$pgsql = pg_connect("host=$hostname dbname=$database user=$username password=$password") or die('Could not connect: ' . pg_last_error());
$pagenum = $_GET['pagenum'];
$pagesize = $_GET['pagesize'];
$start = $pagenum * $pagesize;
$query = "SELECT SQL_CALC_FOUND_ROWS CompanyName, ContactName, ContactTitle, Address, City, Country FROM customers LIMIT ?,?";
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
$result->bind_param('ii', $start, $pagesize);
$result->execute();
$result->bind_result($CompanyName, $ContactName, $ContactTitle, $Address, $City, $Country);
while ($result->fetch())
    {
    $customers[] = array(
        'CompanyName' => $CompanyName,
        'ContactName' => $ContactName,
        'ContactTitle' => $ContactTitle,
        'Address' => $Address,
        'City' => $City,
        'Country' => $Country
    );
    }
$result = $pgsql->prepare("SELECT FOUND_ROWS()");
$result->execute();
$result->bind_result($total_rows);
$result->fetch();
$data[] = array(
    'TotalRows' => $total_rows,
    'Rows' => $customers
);
echo json_encode($data);
$result->close();
$pgsql->close();
?>

Source: Ask PHP

LEAVE A COMMENT