0

I am working on a new project, where Laravel will be my API to an mobile app that will be develop on Ionic 2. The company has an ERP build on 4D; sincerely I have never worked with an app build on this platform.

So what i need is to make queries to the database so i can send the info to my mobile app through web services.But I dont know how to connet to the database mentioned.

So if anyone could help me with this issue. How can I connect Laravel, PHP to this 4D database?

felipebla
  • 53
  • 5
  • 1
    I'm sure they have instructions somewhere in their website on how to interface with their stuff. A quick look found http://doc.4d.com/4Dv16/4D/16/4D-ODBC-Driver.100-3200467.en.html which means you have the ODBC option at least. Also, ODBC works with PDO so you can configure laravel to use that. – apokryfos Mar 16 '17 at 17:13

1 Answers1

2

You can enable the SQL Server in 4D Server to allow external connections (ODBC/SQL/PDO) connections to the 4D Server.

Once you have the SQL Server enabled then you can either use the 4D ODBC Driver on Windows/Mac or PDO_4D with PHP on Windows/Mac/Linux.

This tech tip demonstrates how to connect to 4D using PHP with both of these methods:

PDO_4D:

<?php
$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
?> 

ODBC:

<?php
$dsn = 'dsnName'; //DSN created by the 4D ODBC driver
$user = 'username';
$pswd = 'password';
$name ='Joe';
$conn = odbc_connect($dsn,$user,$pswd);
$sql_text = "INSERT INTO Customers(Name) VALUES('".$name."')";
$sql = odbc_prepare($conn,$sql_text);
$res = odbc_execute($sql);
echo $res; // if you see this then the code ran successfully
?>

More connectivity options for 4D are listed on github here and here

Tim Penner
  • 3,551
  • 21
  • 36
  • Thanks for your help I am stuck trying to install the pdo_4d driver since the odbc connection is not an alternative now. – felipebla Mar 21 '17 at 15:07