Zip2Tax Logo

Developers Information

Database Link (developers information)

 

Connecting directly to one of our database's assures the quickest possible response time. We offer a choice of both Microsoft SQL Server or MYSQL connections.

Microsoft SQL Server

Direct Connect to MSSQL using ASP
<%

strServer = "db.Zip2Tax.com"
strDBUsername = "z2t_Sample"
strDBPassword = "db_pwd"
strDatabase = "zip2tax"

'Open the connection
Set conn=server.CreateObject("ADODB.Connection")
conn.Open "driver=SQL Server;server=" & strServer & ";uid=" & strDBUsername & ";pwd=" & strDBPassword & ";database=" & strDatabase

'Assign values to the input variables
strZipCode = "90210" : 'sample zip code must be between 90001 and 92999
strUserName = "z2t_sample"
strUserPassword = "usr_pwd"

'Open the recordset using the stored procedure
Set rs = server.CreateObject("ADODB.Recordset")
rs.open "z2t_lookup('" & strZipCode & "', '" & strUserName & "', '" & strUserPassword & "')", conn, 3, 3, 4

'Read the results
If not rs.EOF then
    Response.write "Zip Code: " & rs("Zip_Code")
    Response.write "Sales Tax Rate: " & rs("Sales_Tax_Rate")
    Response.write "Post Office City: " & rs("Post_Office_City")
    Response.write "County: " & rs("County")
    Response.write "State: " & rs("State")
    Response.write "Shipping Taxable: " & rs("Shipping_Taxable")
End If

'Close the Database
rs.Close
conn.Close

%>


Direct Connect to MSSQL using PHP
<?php

$strServer = "db.Zip2Tax.com";
$strDBUsername = "z2t_sample";
$strDBPassword = "db_pwd";
$strDatabase = "zip2tax";

//Open the connection
$conn = mssql_connect($strServer, $strDBUsername, $strDBPassword, 0, 65536)
    or die("Failed to connect to MSSQL server on $strServer");

//Open the Database
mssql_select_db($strDatabase, $conn)
    or die("Could not open database $strDatabase");

//Set-up query variables
$strZipCode = "90210"; //sample zip code must be between 90001 and 92999
$strUserName = "z2t_sample";
$strUserPassword = "usr_pwd";

//Execute
$result = mssql_query( "CALL zip2tax.z2t_lookup(" . $strZipCode . ",'" . $strUserName . "', '" . $strUserPassword . "')" )
    or die( mssql_error() );

//Read the result
while($row = mssql_fetch_array($result))
    {
    echo "Zip Code: " . $row['Zip_Code'] . "<br>";
    echo "Sales Tax Rate: " . $row['Sales_Tax_Rate'] . "<br>";
    echo "Post Office City: " . $row['Post_Office_City'] . "<br>";
    echo "County: " . $row['County'] . "<br>";
    echo "State: " . $row['State'] . "<br>";
    echo "Shipping Taxable: " . $row['Shipping_Taxable'] . "<br>";
    }

//Close the Database
mssql_close($conn);

?>

MYSQL

Direct Connect to MYSQL using PHP
<?php

$strServer = "db.Zip2Tax.com";
$strDBUsername = "z2t_sample";
$strDBPassword = "db_pwd";
$strDatabase = "zip2tax";

//Open the connection
$conn = mysql_connect($strServer, $strDBUsername, $strDBPassword, 0, 65536)
    or die("Failed to connect to MySQL server on $strServer");

//Open the Database
mysql_select_db($strDatabase, $conn)
    or die("Could not open database $strDatabase");

//Set-up query variables
$strZipCode = "90210"; //sample zip code must be between 90001 and 92999
$strUserName = "z2t_sample";
$strUserPassword = "usr_pwd";

//Execute
$result = mysql_query( "CALL zip2tax.z2t_lookup(" . $strZipCode . ",'" . $strUserName . "', '" . $strUserPassword . "')" )
    or die( mysql_error() );

//Read the result
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
    echo "Zip Code: " . $row['Zip_Code'] . "<br>";
    echo "Sales Tax Rate: " . $row['Sales_Tax_Rate'] . "<br>";
    echo "Post Office City: " . $row['Post_Office_City'] . "<br>";
    echo "County: " . $row['County'] . "<br>";
    echo "State: " . $row['State'] . "<br>";
    echo "Shipping Taxable: " . $row['Shipping_Taxable'] . "<br>";
    }

//Close the Database
mysql_close($conn);

?>

Passing Request Variables

Another method of pulling information from our database is to incorporate request variables.

Quick Link

The simpliest form of this method is to click on the link below (use the browser's back button to return to here).

http://www.zip2tax.com/Link/Lookup_Sample.asp?zip=90210&pwd=user_pwd

Or you can paste this line of code into any browser's URL box.

You will see that you looked up the data using the request variables. You may wish to try other zip codes (between 90001 and 92999) to see the results.

Return the Results in a Useful Format

Now we want to have the results passed back to us in a useful format. At the end of the URL we are going to add a return request variable as shown.

http://www.zip2tax.com/Link/Lookup_Sample.asp?zip=90210&pwd=user_pwd&ret=http://www.Zip2Tax.com/Link/DisplayResults.asp

Instead of displaying the results directly to the browser as in the Quick Link example, the data is being passed to a separate page using request variables and the new page is displaying the data. This new page should reside on your server and can be written in any language.

Display Request Variable Results Using ASP

This is a separate asp page.<br><br>

Zip_Code: <%=Request("Zip_Code")%><br>
Sales_Tax_Rate: <%=Request("Sales_Tax_Rate")%><br>
Post_Office_City: <%=Request("Post_Office_City")%><br>
County: <%=Request("County")%><br>
State: <%=Request("State")%><br>
Shipping_Taxable: <%=Request("Shipping_Taxable")%><br>

Display Request Variable Results Using PHP

<?php

echo('This is a separate php page.<br><br>');

echo('Zip_Code: ');
echo($_REQUEST['Zip_Code'].'<br>');

echo('Sales_Tax_Rate: ');
echo($_REQUEST['Sales_Tax_Rate'].'<br>');

echo('Post_Office_City: ');
echo($_REQUEST['Post_Office_City'].'<br>');

echo('County: ');
echo($_REQUEST['County'].'<br>');

echo('State: ');
echo($_REQUEST['State'].'<br>');

echo('Shipping_Taxable: ');
echo($_REQUEST['Shipping_Taxable'].'<br>');

?>

Return Data Using XML

 

Rather Than returning the information in a plain string, you may prefer to have data passed back using the XML Format

Quick XML Link

The simpliest way to view XML is to click on the link below (use the browser's back button to return to here).

http://www.zip2tax.com/Link/Lookup_Sample_XML.asp?zip=90210&pwd=user_pwd

Or you can paste this line of code into any browser's URL box.

When XML is returned to your browser it will look differently depending on your browser brand (IE, Firefox) and version. But, the information is the same. In a practical application you would typically read the results into a requestXML object.

You may wish to try other zip codes (between 90001 and 92999) to see the results.

Error Handling

Two fields have been added for error handling, error_code and error_message. Below is a list of possible results . . .

0"No Errors"
1"Missing Zip Code"
2"Missing Password"
3"Connection Error"
4"Zip Code Less than 5 Characters"
5"Zip Code Out of Range for Sample"
6"Incorrect Password"
7"Zip Code Not Found"
99"Error Unknown"