/** * array getLatLongFromZipCode(int). * * Retrieves information about a given zip-code from the Drupal database. If the given ZC is * not found in the database _getLatLongFromZipCode_lookupAndCache() is called and its * responce is returned. * * Example return: * return array( "lat" => "38.931479", "lng" => "-77.40085", "state" => "VA", "city" => "Herndon" ); */ function getLatLongFromZipCode($zip) { if (intval($zip) === 0) { return array(false, false); } $zip = substr('00000' . intval($zip), -5); if ($zip === '22070') { // Bug killer for REI HQ $zip = '20171'; } /* * resource connectMySQL() * Connects to the MySQL database that this Drupal instance is/will-be using * This is meant to create a connection to the database that bypasses Drupal's db_query() and query alter hooks * This is also meant to be used in situations where a connection to the database is needed when Drupal is not fully boot-strapped * NOTE: If the database connection information is not found in global $databases, then this script will search for settings.php and load it */ if (function_exists('connectMySQL') == false) { function connectMySQL() { // If the global $databases is not set, then settings.php is not loaded... if (!isset($GLOBALS["databases"]) && !isset($databases)) { while (!file_exists('sites/default/settings.php')) { chdir('../'); } include 'sites/default/settings.php'; } if (!isset($databases) && isset($GLOBALS["databases"])) { $databases = $GLOBALS["databases"]; } $dbAuth = $databases["default"]["default"]; $host = $dbAuth["host"]; $user = $dbAuth["username"]; $pass = $dbAuth["password"]; $port = $dbAuth["port"]; $db = $dbAuth["database"]; if (!empty($port)) { $host .= ":" . $port; } $link = mysql_connect($host, $user, $pass); mysql_select_db($db, $link); return $link; } } $mySqlLink = connectMySQL(); $query = "\n SELECT id, zccity, zcstate, latitude, longitude, zipcode \n FROM zipcodes \n WHERE zipcode = {$zip} \n LIMIT 1 \n "; $result = mysql_query($query, $mySqlLink); while ($row = mysql_fetch_assoc($result)) { return array("lat" => $row['latitude'], "lng" => $row['longitude'], "state" => $row['zcstate'], "city" => $row['zccity']); } // If we have not returned by this line, then this ZC is not in the database... look it up. return _getLatLongFromZipCode_lookupAndCache($zip); }
function ensureQuickLinksTableExists($linkMySQL = false) { if ($linkMySQL === false) { $linkMySQL = connectMySQL(); } $sql = "\n CREATE TABLE quicklinks (\n id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,\n url VARCHAR( 767 ) NOT NULL ,\n post_data VARCHAR( 767 ) NULL COMMENT 'a php serialized array, where the key is the name, and the value is the post-data-value',\n created_time INT UNSIGNED NULL COMMENT 'a unix timestamp of when this record was created',\n nav_count INT UNSIGNED NOT NULL DEFAULT '0' COMMENT 'a count of how many times origin has been hit to resolve this bookmark',\n INDEX ( url , post_data )\n )\n "; mysql_query($sql, $linkMySQL); }
function get_config() { } function &connectDB($dsn, $query_builder_override = NULL) { $connectedDB =& DB($dsn, $query_builder_override); return $connectDB; } function &connectMySQL($hostname, $username, $password, $dbname, $port = 3306) { $dsn = "mysqli://{$username}:{$password}@{$hostname}:{$port}/{$dbname}"; $connectedDB =& DB($dsn, true); return $connectedDB; } //function &connectSQLite($filename) //{ // $dsn = "sqlite:$filename"; // $connectedDB =& DB($dsn, true); // return $connectedDB; //} /* Load database via Database source name, eg. "mysql://*****:*****@localhost/mydatabase" */ //$db =& connectDB("mysql://*****:*****@localhost/mydatabase", true); $db =& connectMySQL("hostname", "username", "password", "dbName"); //--------------------------------------------------------- /* Sample below */ $db->where('fieldName', 'value'); $query = $db->get('tableName'); foreach ($query->result_array() as $data) { print_r($data); } $query->free_result();
<?php include "../config.php"; global $LINK_DB; global $NAME_DB; $LINK_DB = connectMySQL(); extract($_REQUEST, EXTR_PREFIX_ALL | EXTR_REFS, ''); mb_internal_encoding("UTF-8"); $this_script_URL = "list_hypo.php"; include "../lib/header.php"; ?> <h3>Generation of list of hyponyms and hypernyms</h3> <?php print "Database version: {$NAME_DB}<BR>"; //$labels_all = TLabel::getAllLabels(); $lang_all = TLang::getAllLang(); $relation_type_all = TRelationType::getAllRelations(); $pos_all = TPOS::getAllPOS(); $lang_id_ru = TLang::getIDByLangCode($lang_all, "ru"); print "lang_id_ru = {$lang_id_ru}<BR>"; $pos_id_noun = TPOS::getIDByName($pos_all, "noun"); $pos_id_noun_class = TPOS::getIDByName($pos_all, "noun class"); print "ID of part of speech \"noun\" = {$pos_id_noun}<BR>"; print "ID of part of speech \"noun class\" = {$pos_id_noun_class}<BR>"; $relation_type_id_hyponyms = TRelationType::getIDByName($relation_type_all, "hyponyms"); $relation_type_id_hypernyms = TRelationType::getIDByName($relation_type_all, "hypernyms"); print "ID of relation type \"hyponyms\" = {$relation_type_id_hyponyms}<BR>"; print "ID of relation type \"hypernyms\" = {$relation_type_id_hypernyms}<BR>"; print "<BR>";