Pervasive SQL

  • Thread starter Thread starter Anonymous
  • Start date Start date
A

Anonymous

Guest
67217-1643c98702b825fbff57a7a139f70c7b.jpgHi all,

I'm using the following connection string to connect to the "P000Lap" Pervasive database from within MS Access
(See screenshot)

tdfLinked.Connect = "ODBC;DSN=P000Lap;DBQ=P000Lap"

However I would like to connect to it from PhP.

At the moment I'm connecting to a MySQL database from PhP but would also like to connect to the above.

$mysqli = mysqli_connect($databaseHost, $databaseUsername, $databasePassword, $databaseName);

How do I change the connection string for this.

If for whatever reason it is not possible, then how do I connect to the "PSQL" database in the screenshot - which is an Access db

Thanks a lot
 
Among other this is the code I tested just now but not working:

Code:
<?php

$connect=odbc_connect("Driver={Pervasive ODBC Interface};ServerName=localhost;ServerDSN=P000Lap;","", "", SQL_CUR_USE_ODBC); 

//$connect=odbc_connect("Driver={Pervasive ODBC Engine Interface};ServerName=localhost;ServerDSN=P000Lap;","", "", SQL_CUR_USE_ODBC); 

$res = mysqli_fetch_array(mysqli_query($connect, "SELECT * FROM HRDepartments"));
	$Descript = Trim($res['Description']);
	echo $Descript;
?>

I also included a screenshot of the Pervasive Drivers installed. I'm running Win7 64
Screenshot_x.jpg
 
To connect to a Pervasive database from PHP, you can use the ODBC extension. Here's an example of how you can modify your PHP connection string:

```php
$dsn = 'Driver={Pervasive ODBC Client Interface};ServerName=localhost;DBQ=P000Lap';
$user = 'your_username';
$password = 'your_password';

$connection = odbc_connect($dsn, $user, $password);

if ($connection) {
// Connection successful
// You can perform queries on the Pervasive database using this connection
// For example: $result = odbc_exec($connection, "SELECT * FROM your_table");
} else {
// Connection failed
echo 'ODBC Connection Error: ' . odbc_errormsg();
}
```

Make sure you have the Pervasive ODBC Client Interface driver installed on your PHP server. Adjust the `ServerName` parameter to the appropriate server name or IP address where your Pervasive database is hosted.

Regarding the "PSQL" database in the screenshot, it appears to be a Microsoft Access database. To connect to an Access database from PHP, you can use the PDO extension with the appropriate ODBC driver. Here's an example:

```php
$dsn = 'odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\path\to\your\database.accdb';
$user = '';
$password = '';

try {
$connection = new PDO($dsn, $user, $password);
// Connection successful
// You can perform queries on the Access database using this connection
// For example: $result = $connection->query("SELECT * FROM your_table");
} catch (PDOException $e) {
// Connection failed
echo 'PDO Connection Error: ' . $e->getMessage();
}
```

Adjust the `Dbq` parameter in the `$dsn` variable to the path of your Access database file.

Remember to replace `'your_username'`, `'your_password'`, and the database file paths with your actual credentials and paths.

With these modifications, you should be able to connect to the Pervasive database and the Access database from PHP.
 
Back
Top