Knowledgebase: Tutorials
[QODBC-ALL] How to use QODBC with PHP
Posted by Jack - QODBC Support on 02 March 2015 11:42 AM

How to use QODBC with PHP

Instructions for using QODBC with PHP:

Using PHP, whether it's an internal Intranet or on the World Wide Web, requires the Server Edition of QODBC. QuickBooks must be running with the company file open. 

Download Sample

Sample Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<title>QODBC PHP Script To Display SQL Results</title>
<body topmargin="3" leftmargin="3" marginheight="0" marginwidth="0" bgcolor="#ffffff" link="#000066" vlink="#000000" alink="#0000ff" text="#000000">
<table border="0" border="0" bgcolor="lightgreen" bordercolor="black" cellpadding="0" cellspacing="0">
<table border="2" bordercolor="black" bgcolor="white" cellpadding="5" cellspacing="0">
<caption align="top">QODBC PHP Script To Display SQL Results</caption>

#Connect to a System DSN "QuickBooks Data" with no user or password
$oConnect = odbc_connect("QuickBooks Data QRemote", "", "");

#Set the SQL Statement
$sSQL = "SELECT Top 10 Name,FullName FROM Customer";

#Perform the query
$oResult = odbc_exec($oConnect, $sSQL);
$lFldCnt = 0;
$lFieldCount = odbc_num_fields($oResult);
while ($lFldCnt < $lFieldCount) {
$sFieldName = odbc_field_name($oResult, $lFldCnt);
print(" <th>$sFieldName</th>\n");
$lRecCnt = 0;
#Fetch the data from the database
while(odbc_fetch_row($oResult)) {
print(" <tr>\n");
print(" <td>$lRecCnt</td>\n");
$lFldCnt = 0;
$lFieldCount = odbc_num_fields($oResult);
while ($lFldCnt < $lFieldCount) {
$sFieldValue = trim(odbc_result($oResult, $lFldCnt));
If ($sFieldValue == "") {
print(" <td> </td>\n");
else {
print(" <td valign=\"Top\">$sFieldValue</td>\n");
print(" </tr>\n");
#Close the connection
print(" <caption align=\"bottom\">Results of: $sSQL</caption>");

Please refer: How to configure QRemote

Please Note: If you have the 64-bit application, then you need to use QRemote 64-bit DSN "QuickBooks Data 64-bit QRemote"

Result in Web Browser:

(1 vote(s))
Not helpful

Comments (0)
Post a new comment
Full Name:
CAPTCHA Verification 
Please complete the captcha below (we use this to prevent automated submissions).