KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Note: PDO_4D Driver
PRODUCT: 4D | VERSION: 12 | PLATFORM: Mac & Win
Published On: April 16, 2010

The PDO_4D driver is a brand new product that enables Apache and IIS web servers to easily access 4D databases by way of PHP. 4D has sponsored an Open Source project, with the goal being the PDO_4D driver, which can be installed in any web server that uses PHP and can be used to run SQL code and 4D methods. The purpose of this Technical Note is to explain: the different pieces involved, how the pieces work together, and how to use the PDO_4D driver. Some examples are included and since PHP is being used, some basic PHP information is also included.

Download Complete Tech Note and Example: Windows | Mac

Commented by Pascal Foubert on October 9, 2010 at 10:20 AM
Same here

I've compiled the pdo_4d 0.3 from pecl :
phpize
./configure
make
make install

The make test returns 88 errors on 90 (I think it is 90)

my phpinfo show that pdo_4d is loaded

I create a 4D V12 base, set the sql server to start, then create a php test page as :
$dsn = '4D:host=127.0.0.1;charset=UTF-8';
$user = 'Admin';
$pass = 'test';

// Connection to the 4D SQL server
$db = new PDO($dsn, $user, $pass);

try {
$db->exec('CREATE TABLE test(id varCHAR(1) NOT NULL, val VARCHAR(10))');
} catch (PDOException $e) {
die("Erreur 4D : " . $e->getMessage());
}

$db->exec("INSERT INTO test VALUES('A', 'A')");
$db->exec("INSERT INTO test VALUES('B', 'A')");
$db->exec("INSERT INTO test VALUES('C', 'C')");

$stmt = $db->prepare('SELECT id, val from test');

$stmt->execute();
print_r($stmt->fetchAll());

unset($stmt);
unset($db);
echo "OK";
?>

launch it and see the OK
No error returns by try/catch

But nothing happens in the 4d database.
Same with a call to a function

If I stop the 4D sql server, then I have an error, so it looks like the pdo_4d driver is "talking" to the 4d server but nothing happens

Any idea why ?
Does the pdo_4d compatible with the last 4d_v12.1 and php 5.3.2 ?
Thanks for your help/comments
Commented by Christophe Flament on May 14, 2010 at 10:23 PM
Jesse

I am trying to test pdo_4D following the your tech note . I am on Mac Snow Leopard and using MAMP. I have some problems.

1/ The link in the tech note to download is :
http://pecl.php.net/package/PDO_4D
No trace of "pdo_4d.so". So I used an other link that I got from the 4d forum :
http://forums.4d.fr/4DBB_Main/x_User/1776570/files/3588446.zip
I installed the "pdo_4d.so" in the following folder
MAMP/bib/php5/lib/php/extensions/no-debug-non-zts-20060613
I added the "extension=pdo_4D.so" in file "php.ini" in the following folder
MAMP/conf/php5/
All OK - In my php info page I can see the "pdo_4d" info - Same inof that the one in your tech note on page 8 (build date is $Date: 2009-08-26 19:15:13 +0200 (Wed, 26 Aug 2009) $ )

2/ I created a v12 MC 2 database - I made starting the SQL Server automatic at startup on the default port - I put a password 'test' for 'Administrator'

3/ I created a trace in the On SQL Authentication database method - this method return $0:=True

4/ I created a php page with the following code taken from the tech note:
$dsn = '4D:host=localhost;port=19812;charset=UTF-8';
$user = 'Administrator';
$pswd = 'test';
$db = new PDO($dsn, $user, $pswd);
$db->exec('CREATE TABLE IF NOT EXISTS myTable(id INT NOT NULL, value VARCHAR(100))');
unset($db);
echo 'done'; // if you see this then the code ran successfully
?>

5/ Here comes the problem ...
When I run my php page ... I get the trace in 4D but nothing happens after and do not get the echo 'done'

What is wrong ?

Christophe
Commented by Jennifer Fink on May 11, 2010 at 6:39 AM
The driver file(s) can be obtained from PECL at http://pecl.php.net/package/PDO_4D/download.
Commented by Chris Norman on May 4, 2010 at 3:38 PM
Cool. Can you do the same thing with Ruby and ActiveRecord? http://en.wikipedia.org/wiki/Active_record_pattern