PHP code example of eclipxe / sepomexphp

1. Go to this page and download the library: Download eclipxe/sepomexphp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

eclipxe / sepomexphp example snippets



/** @var string $databaseFilename set the database file location */
$sepomex = \Eclipxe\SepomexPhp\SepomexPhp::createForDatabaseFile($databaseFilename);

// query a zip code
$zipcode = $sepomex->getZipCodeData('86100');


/** @var string $pdoString set the database connection using Pdo */
$pdoString = "...";

// create the SepomexPhp Object
$sepomex = new \Eclipxe\SepomexPhp\SepomexPhp(
    new \Eclipxe\SepomexPhp\PdoDataGateway\PdoDataGateway(
        new \PDO($pdoString)
    )
);

// query a zip code
$zipcode = $sepomex->getZipCodeData((int) $argv[1]);


/**
 * @var string $destinationFile is the path where the destination file will be located. 
 */
$downloader = new \Eclipxe\SepomexPhp\Downloader\SymfonyDownloader();
printf("Download from %s to %s\n", $downloader::LINK, $destinationFile);
$downloader->downloadTo($destinationFile);


/**
 * @var PDO $pdo The PDO connection to your database.
 * @var string $sourceFile The path to the SEPOMEX database in TXT format. 
 */
$importer = new \Eclipxe\SepomexPhp\Importer\PdoImporter($pdo);
// drop tables if existed, create tables.
$importer->createStruct();
// perform data import
$importer->import($sourceFile);