-1

I am connecting PHP to Pervasive SQL and the connection keep resetting

This connection is on Windows Server 2012 using PHP7 on Apache 2.4. I have already created a DNS connection and the test can connect to the database successfully.

<?php
  $conn=odbc_connect("brps","","");
   if(!$conn) die("Could not connect");
?>
  • What version of Pervasive are you using? What's the exact error? – mirtheil Jan 09 '19 at 17:04
  • PSQL version 11 – Kwasi Owusu Jan 09 '19 at 17:06
  • You might want to edit your question to include the exact error as well as the version of Pervasive. – mirtheil Jan 09 '19 at 17:52
  • it gives no error. The page cannot load. My application connects to both MySQL and Pervasive. When I comment out the pervasive connection, the page loads alright. But when I add the pervasive connection the page reset, times out or fail to load with no errors – Kwasi Owusu Jan 09 '19 at 17:55
  • If it's not connecting, it's got to give an error. What does your page give is you have just this in it: `` – mirtheil Jan 09 '19 at 18:27
  • page attempts to load and the returns can not find page or the site cannot be reached. I felt something like a firewall is blocking it. I allowed firewall access but still – Kwasi Owusu Jan 10 '19 at 01:35

1 Answers1

0

The following code works for me in an x64 environment using PHP 7.31 with the ODBC extension enabled in the PHP.INI. I'm also using the v11.30 x64 Client connecting to a remote PSQL v11 server.

<?php
  $conn=odbc_connect("brpp","","");
   if(!$conn) die("Could not connect");
$result = odbc_tables($conn);

echo '<div id="top">..</div><table border="1" cellpadding="5"><tr>';

$tblRow = 1;
while (odbc_fetch_row($result)){
  if(odbc_result($result,"TABLE_TYPE")=="TABLE"){
    $tableName = odbc_result($result,"TABLE_NAME");
    echo '<tr><td>' . $tblRow . '</td><td><a href="#' . $tableName . '">' . $tableName . '</a></td></tr>';
    $tblRow++;
  }  
}
echo '</table><hr>';

$result = odbc_tables($conn);

while (odbc_fetch_row($result)){
  if(odbc_result($result,"TABLE_TYPE")=="TABLE"){
    $tableName = odbc_result($result,"TABLE_NAME");

    echo '<div id="' . $tableName . '"> *** ' . $tableName . ' *** <a href="#top">top</a></div>';

    $cols = odbc_exec($conn, "SELECT * FROM $tableName WHERE 1=2");
    $ncols = odbc_num_fields($cols);

    for ($n=1; $n<=$ncols; $n++) {
      $field_name = odbc_field_name($cols, $n);
      echo $field_name . "<br>";
    }    
    echo '<hr>';
  }
}
?>

If the DSN doesn't exist, I get an error:

    Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in C:\Wnmp\html\phpodbc.php on line 2
Could not connect

I was getting a System error 998 after installing the PSQL x64 client. A reboot of the machine fixed that error.

mirtheil
  • 8,952
  • 1
  • 30
  • 29