Using PHP for ODBC Sage Line 50 connection

I am looking into connecting to Sage's database using PHP. It appears to use MSSQL. I am not familiar with how to connect to non-mysql datasources. These are the connection details that excel uses to do it, which work;
Driver={Sage Line 50 v15};

How would I connect to the database using these details?
Thanks for your help
Who is Participating?
Bruce DenneyConnect With a Mentor Sage 50 Consultant and IntegratorCommented:
There are a couple of problems with what you are looking to do.

The Sage Database needs to be on the same server as your PHP script or at least have very fast (Gigabit connection) to the database as ODBC

You will need to update your code every time the users upgrade their Sage, Sage are very keen on getting users to upgrade every year.

ODBC is VERY slow especially with large amounts of data.

There are lots of ways around this issues if they affect your usage.

For example if your PHP is on a Linux hosted server and the Data is on the Users Network you are not going to get very far.

I have done various workarounds, for example a windows scheduled task that dumps the data from the appropriate tables puts them in a CSV file uploads to the web server and then hits a url to update the SQL database on web hosting with the latest data.   This avoids the problems of narrow bandwidth and the poor performance of ODBC however, it is not real time.  I used a 3rd party bit of software that did the reverse as well, downloaded stuff from the site and put it into sage, this had the advantage that they just needed to upgrade the 3rd party stuff each time they upgraded sage, all the rest of the code was static.

I think that you need to tell us more about the actual scenario as whilst nothing anyone has suggested is wrong, it might not be a particle path for you to follow.

You will need to use ODBC in PHP
jdav357Author Commented:
I have found where the files that I think from other posts say I need. These are located:

Where would I put these details in the connection? (I have changed some bits of the string for test only)
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

jdav357Author Commented:
I am not entirely sure what would go in the string you posted,
I presume that UID is really the DB_SERVER_USERNAME and DB_SERVER_PASSWORD is the password?

I am not sure where I put:
Driver={Sage Line 50 v15};

jdav357Author Commented:
sorry meant:
You will need to create an ODBC DNS on the server where IIS is being used
 define('DB_SERVER', 'SageLine50v13'); // eg, localhost - should not be empty for productive servers
 define('DB_SERVER_PASSWORD', 'password');
Here is a PHP page i built for my tests
It will list ALL the tables on a given connection (in this case it was v13)
You can add in the url ?table=tablename to list the contents of the table
also add &where=your where clause  - to limit the results returned
or even ?all=y which will dump ALL tables with ALL contents...


$table = @$_GET["table"];
$where = @$_GET["where"];
$all = @$_GET["all"];

	$rConn = odbc_connect("SageLine50v13", "manager", "password");
	if ($rConn == 0)
	 die('Unable to connect to the Sage Line 50 V12 ODBC datasource.');
	// Get a list of tables as I cannot remember ANY of the L50 table names!
	$query = "SELECT * FROM ". $table;
	if ($where != "") {
		$query .= ' WHERE ' .$where;
	 if ($all == "y") {
		echo "Listing Everything<br>";
		$rRes = odbc_tables($rConn);
		while(odbc_fetch_row ($rRes))
			echo "Table:" . odbc_result($rRes,'TABLE_NAME').'<br>';		
			$query = "SELECT  * FROM ". odbc_result($rRes,'TABLE_NAME');
			$tableexe = odbc_do($rConn, $query);  
	 } else {   
	    $queryexe = odbc_do($rConn, $query);  
		$rRes = odbc_tables($rConn);

// Output the entire result set as a HTML table - quick dump!

// Close the ODBC connection.

Open in new window

GMGeniusConnect With a Mentor Commented:
<The Sage Database needs to be on the same server as your PHP script or at least have very fast (Gigabit connection) to the database as ODBC >
Not true, you can install the ODBC driver on any server , you just need to have the ODBC driver working on the IIS server you want to use.
<You will need to update your code every time the users upgrade their Sage, Sage are very keen on getting users to upgrade every year.>
That goes without saying but in the code I provided you just change the ODBC name or (using registry editor) you can change the ODBC Driver used for the ODBC name in the PHP page
I personally dont think its a difficult job to create the new ODBC and change a PHP config page
jdav357Author Commented:
Thanks for your help. I've had to find alternative solution.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.