0
votes

All 32Bit. Windows 2018 Server. PVSQL v10 (I can't update this)

PHP 5.3.28 (I might be able update this to 5.6.x) 7.x Would break too much

I've tried searching everywhere for an example on how to connect PHP to Pervasive DB with PDO. I've managed to connect using the following non PDO connector:

$conn = odbc_connect("demodata","","");
if(!$conn) die("Could not connect");

Looking at the examples from https://docs.actian.com/psql/psqlv13/index.html#page/odbc%2Fodbcadm.htm%23ww1213912 I found that I should be using something like:

    try {
        $conn = new PDO("odbc:Driver={Pervasive ODBC Client Interface};ServerDSN=demodata;");
        if(!$conn) die("Could not connect");
    }
    catch (PDOException $e) {
      echo $e->getMessage();
      exit;
    }

I also tried:

        $conn = new PDO("odbc:Driver={Pervasive ODBC Client Interface};ServerName=localhost;SeverDSN=demodata;");
        $conn = new PDO("odbc:Driver={Pervasive ODBC Client Interface};ServerName=localhost;SeverDSN=DEMODATA;");

When I do though. I get the error:

SQLSTATE[HY000] SQLDriverConnect: -1206 [Pervasive][ODBC Client Interface][LNA][Pervasive][ODBC Engine Interface][Data Record Manager]Non-db file or corrupted db.

But I know its not corrupted.I'm able to connect and do queries the other way. Would just really like to be able to use PDO. When I do a test from the Pervasive ODBC Client DSN Setup. I get Connection Successful.

What am I missing?

1
No sorry, I've looked at that. That is not PDO. That is the same as my connection that originally works. I'm looking to make it connect using PDO. Thank you for your time though.Shawn V
Is this all on the same machine (PHP, Pervasive, data, etc)? Is it on Windows or Linux? If it isn't on the same machine, change your ServerName to the machine name where Pervasive is running and the database is located.mirtheil
With Pervasive Client you don't do that. Thats why the original works. You can connect local. I have the Pervasive client installed properly. And can Connect not using PDO. I just can't figure out why its saying its corrupt. When connecting via PDO. I must be missing some parameter. I've updated question to show its windows.Shawn V
If you're connection string is as displayed here, you have a typo in it. You have SeverDSN but it should ServerDSN.mirtheil
Good catch, but thats just a typo. I did have to go look though, but different errors occur then. I saw I can use DSN or ServerDSN. I've tried both.Shawn V

1 Answers

0
votes

Thanks to @Mitheil for pointing me in the right direction. The server name does seem to be a must even on local machine. So the string needed is: "odbc:Driver={Pervasive ODBC Client Interface};ServerName=db;ServerDSN=demodata;"

    try {
        $conn = new PDO("odbc:Driver={Pervasive ODBC Client Interface};ServerName=db;ServerDSN=demodata;");
        if(!$conn) die("Could not connect");
    }
    catch (PDOException $e) {
      echo $e->getMessage();
      exit;
    }