ZIPCodeWorld Utility PHP Component is a software development component which looks up the ZIPCodeWorld United States ZIP Code Database that is available in Basic, Premium and Gold Editions. It allows query by ZIP code, city name, alias city name, state code, phone area code, city type, county name, county FIPS, time zone, day light saving flag, latitude, longitude, etc. It also looks up the PostalCodeWorld Canada Postal Code Database which is available in Basic, Premium and Gold Editions and supports query by postal code, city name, province name, phone area code, timezone, daylight saving flag, latitude, longitude, population and much more.
ZIPCodeWorld is giving away free sample codes for the ZIPCodeWorld Utility PHP Component. You will need to run MySQL queries to fetch the data out of the database. We will guide you on how to create and import database in MySQL. We will also demonstrate to you how to call and query 3 functions which are the Get function, Distance function and Radius function using the ZIPCodeWorld United States Gold Edition database in PHP. If you have purchased the license key, you can use our query to upload the "license.key" file to your server.
Part 1: MySQL configuration
----------------------------
Step 1: Create and connect to 'ZIPCodeWorld' database
mysql> CREATE DATABASE ZIPCodeWorld
mysql> USE ZIPCodeWorld
Step 2: Create 'ZIPCODEWORLDUS' table
mysql> CREATE TABLE ZIPCODEWORLDUS
--> (
--> ZIP_CODE VARCHAR(5),
--> CITY VARCHAR(35),
--> STATE VARCHAR(2),
--> AREA_CODE VARCHAR(40),
--> CITY_ALIAS_NAME VARCHAR(35),
--> CITY_ALIAS_ABBR VARCHAR(13),
--> CITY_TYPE VARCHAR(1),
--> COUNTY_NAME VARCHAR(25),
--> STATE_FIPS VARCHAR(2),
--> COUNTY_FIPS VARCHAR(3),
--> TIME_ZONE VARCHAR(2),
--> DAY_LIGHT_SAVING VARCHAR(1),
--> LATITUDE DOUBLE,
--> LONGITUDE DOUBLE,
--> ELEVATION DOUBLE,
--> MSA2000 VARCHAR(4),
--> PMSA VARCHAR(4),
--> CBSA VARCHAR(5),
--> CBSA_DIV VARCHAR(5),
--> CBSA_TITLE VARCHAR(128),
--> PERSONS_PER_HOUSEHOLD DOUBLE,
--> ZIPCODE_POPULATION DOUBLE,
--> COUNTIES_AREA DOUBLE,
--> HOUSEHOLDS_PER_ZIPCODE DOUBLE,
--> WHITE_POPULATION DOUBLE,
--> BLACK_POPULATION DOUBLE,
--> HISPANIC_POPULATION DOUBLE,
--> INCOME_PER_HOUSEHOLD DOUBLE,
--> AVERAGE_HOUSE_VALUE DOUBLE,
--> INDEX (ZIP_CODE),
--> INDEX (CITY),
--> INDEX (STATE),
--> INDEX (CITY, STATE),
--> INDEX (ZIP_CODE, CITY, STATE),
--> INDEX (LATITUDE),
--> INDEX (LONGITUDE),
--> INDEX (LATITUDE, LONGITUDE)
--> );
Step 3. Import the 'ZIPCODEWORLD-US-GOLD.csv' database into table 'ZIPCODEWORLDUS'
mysql> LOAD DATA LOCAL INFILE '<PATH_TO_DATABASE>\\ZIPCODEWORLD-US-GOLD.CSV'
--> INTO TABLE ZIPCODEWORLDUS
--> FIELDS TERMINATED BY ','
--> ENCLOSED BY '"'
--> LINES TERMINATED BY '\r\n'
--> IGNORE 1 LINES;
Part 2: PHP
----------------------------
We demonstrate 3 functions (Get function, Distance function and Radius function) to query the ZIPCodeWorld US Gold Edition database in PHP.
First function is a normal data query for a particular ZIP Code. Second function is to query the distance between two given ZIP Codes. Last function is to query the data within a certain radius from the given ZIP Code.
<?php
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ /*:: Include “zipcodeworld.class.php” to call all available functions ::*/ /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/require('zipcodeworld.class.php');
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
/*:: Create new object ::*/
/*:: ::*/
/*:: $zcw = new ZIPCodeWorld('<HOST>', '<USER>', '<PASS>', '<DBNAME>', ::*/
/*:: '<TABLE>'); ::*/
/*:: ::*/
/*:: <HOST> is database host name. ::*/
/*:: <USER> and <PASS> are MySQL username and password. ::*/
/*:: <DBNAME> is the database name and <TABLE> is the name of table created.::*/
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
$zcw = new ZIPCodeWorld('localhost', 'root', 'password', 'zipcodeworld', 'zipcodeworldus');
// If you have purchased a license key, please upload the “license.key” file to your server.
$zcw->licenseKey('<PATH_TO_LICENSE_KEY_FILE>/license.key');
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ /*:: Function: get ::*/ /*:: array get (string $zip_code [,string $city] [,string $state_name]) ::*/ /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/// Search by ZIP Code:
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ /*:: Function: distance ::*/ /*:: double distance (string $zip_code1, $zip_code2 [,string $unit]) ::*/ /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/echo $zcw->distance('00610', '75303') . ' Miles';
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ /*:: Function: radius ::*/ /*:: array radius (string $zip_code, $distance [,string $unit]) ::*/ /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/$radius = $zcw->radius('00610', 10, 'miles');
<p><a href="http://www.zipcodeworld.com">www.zipcodeworld.com</a></p>