简体   繁体   中英

Connecting Laravel 5 to 4D application

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM