PHP 4D database connection

Attempting to connect to a 4D database. PHPINFO says PDO is installed, etc. Etc. Testing on the local MAMP system. However, when I run my code, I get:

Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in /Applications/MAMP/htdocs/4d/index.php:12 Stack trace: #0 /Applications/MAMP/htdocs/4d/index.php(12): PDO->__construct('4D:host=127.0.0...', 'test', 'test') #1 {main} thrown in /Applications/MAMP/htdocs/4d/index.php on line 12 

My code is:

 $dsn = '4D:host=127.0.0.1;charset=UTF-8'; $user = 'test'; $pass = 'test'; // Connection to the 4D SQL server $db = new PDO($dsn, $user, $pass); try { echo "OK"; } catch (PDOException $e) { die("Error 4D : " . $e->getMessage()); } 

I can not put my finger on the error, I use the settings under the PHP tab ...

Thanks.

+4
source share
2 answers

Yes, you need to install the PDO_4D module as follows:

 pecl install channel://pecl.php.net/pdo_4D-0.3 

Notes: If you are using MAMP, try:

 /Applications/MAMP/bin/php/(phpversion)/bin/pecl install channel://pecl.php.net/pdo_4D-0.3 

After installation, you can check phpinfo(); if PDO_4d is set correctly, for example:

pdo_4d

0
source

Not sure if your PDO is installed, you can confirm the connection via ODBC

 $odbc_string = 'DRIVER={4D v14 ODBC Driver};SSL=false;SERVER=<ip>;PORT=<19812>;UID=<user>;PWD=<password>'; $connect = odbc_connect($odbc_string,"",""); 

Must return is_resource on $connect

0
source

Source: https://habr.com/ru/post/1493316/


All Articles