GIF89a; %PDF-1.5 %���� ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY
Server IP : 134.29.175.74 / Your IP : 216.73.216.160 Web Server : nginx/1.10.2 System : Windows NT CST-WEBSERVER 10.0 build 19045 (Windows 10) i586 User : Administrator ( 0) PHP Version : 7.1.0 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/nginx/html/JimMartinson/_Archive/MMDT1145/_Archive/Final/ |
Upload File : |
<? // InsertData.php // There are 14 data items to INSERT. // What tables you created and what the field (column) names in those tables was up to you. // In order for InsertData.php to work you must set the information below: // START of data to be setup before running InsertData.php // Host and database information. $hostname = "localhost"; // The hostname of your MySQL server (usually localhost). $database = ""; // The database name. $username = ""; // The username to use when connecting to the server and database. $password = ""; // The password for the username above. // Table to receive data. $dataTable = ""; // List of fields. $fieldArray = array(); // For each field, enter the field name for that field between the " marks below. $fieldArray[0] = ""; $fieldArray[1] = ""; $fieldArray[2] = ""; $fieldArray[3] = ""; $fieldArray[4] = ""; $fieldArray[5] = ""; $fieldArray[6] = ""; $fieldArray[7] = ""; $fieldArray[8] = ""; $fieldArray[9] = ""; $fieldArray[10] = ""; $fieldArray[11] = ""; $fieldArray[12] = ""; $fieldArray[13] = ""; // END of data to be setup before running InsertData.php // getQuoteCharacter($fieldType) // Returns an empty string if the fieldType is numeric and a single quote (') if the fieldType is apphanumeric. function getQuoteCharacter($fieldType) { $isAlpha = array('date', 'time', 'year', 'char', 'blob', 'text', 'enum', 'set'); $qc=""; for ($i = 0; $i < count($isAlpha); $i++) { if (strlen(stristr($fieldType,$isAlpha[$i]))) $qc="'"; } return $qc; } // Begin page. $TRACK = "<b>".basename(__FILE__)."</b> (".__FILE__.")\n<ol>\n"; if (strstr($_ENV['Path'],";")) { $s = ";"; } else { $s = ":"; } ini_set('include_path',"/Data_WWW/CST/$s".ini_get('include_path')); // ** Add the DOCUMENT_ROOT to the include_path. $skipAuthentication = true; $authorizedGroups="PUBLIC"; $skipAuthentication = true; include('Application.phpinc'); set_time_limit(10000); $headTitle = 'InsertData'; $pageTitle = 'InsertData'; if (isset($_SERVER['SERVER_NAME'])) { $thisFile = __FILE__; include('Common/pageHeader.phpinc'); } if (isset($_SERVER['SERVER_NAME'])) { echo "<br><b></b><br><br>\n"; } else { echo "\n\n"; } // List of data files. $fileResult = "product-list-1.txt,product-list-2.txt,product-list-3.txt,product-list-4.txt,product-list-5.txt,product-list-6.txt"; // Verify data setup. $errorExists = false; // START Verify that all files in the list exist. $fileArray = split(",",$fileResult); $allFilesExits = true; foreach($fileArray as $thisFile) { if (!file_exists($thisFile)) { $allFilesExits = false; $errorExists = true; if (isset($_SERVER['SERVER_NAME'])) { echo "<b>The file $thisFile does not exist.</b><br>\n"; } else { echo "The file $thisFile does not exist.\n"; } } } if (!$allFilesExits) { if (isset($_SERVER['SERVER_NAME'])) { echo "<b>Not all of the data files are copied to the folder.</b><br>\n"; } else { echo "Not all of the data files are copied to the folder.\n"; } } // END Verify that all files in the list exist. // START Verify that the database information has been set. // Verify $hostname. if ($hostname == '') { $errorExists = true; if (isset($_SERVER['SERVER_NAME'])) { echo "<b>The \$hostname variable is not set.</b><br>\n"; } else { echo "The \$hostname variable is not set.\n"; } } // Verify $database. if ($database == '') { $errorExists = true; if (isset($_SERVER['SERVER_NAME'])) { echo "<b>The \$database variable is not set.</b><br>\n"; } else { echo "The \$database variable is not set.\n"; } } // Verify $username. if ($username == '') { $errorExists = true; if (isset($_SERVER['SERVER_NAME'])) { echo "<b>The \$username variable is not set.</b><br>\n"; } else { echo "The \$username variable is not set.\n"; } } // Verify $password. if ($password == '') { $errorExists = true; if (isset($_SERVER['SERVER_NAME'])) { echo "<b>The \$password variable is not set.</b><br>\n"; } else { echo "The \$password variable is not set.\n"; } } // Verify the database connection. $hostIPerror = false; if ($hostname != '') { $hostIP = gethostbyname($hostname); #echo "\$hostIP=",$hostIP,"<br>\n"; if ($hostIP == $hostname) { $errorExists = true; $hostIPerror = true; if (isset($_SERVER['SERVER_NAME'])) { echo "<b>The host ($hostname) does not return a DNS record.</b><br>\n"; } else { echo "The host ($hostname) does not return a DNS record.\n"; } } #echo "gethostbyname($hostname)=",gethostbyname($hostname),"<br>\n"; } if (!$hostIPerror && $username != '' && $password != '') { $connection = @mysql_pconnect($hostname, $username, $password); if(!$connection) { $errorExists = true; if (isset($_SERVER['SERVER_NAME'])) { echo "<b>The mysql_pconnect($hostname, $username, $password) failed.</b><br>\n"; echo "Verify that your values for <b>\$hostname</b>, <b>\$username</b>, and <b>\$password</b> are correct.<br>\n"; } else { echo "The mysql_pconnect($hostname, $username, $password) failed.\n"; echo "Verify that your values for \$hostname, \$username, and \$password are correct.\n"; } } else { if(!mysql_select_db($database, $connection)) { $errorExists = true; if (isset($_SERVER['SERVER_NAME'])) { echo "<b>The mysql_select_db($database, \$connection) failed.</b><br>\n"; echo "Verify that your value for <b>\$database</b> is correct and that the user <b>$username</b> has rights to the <b>$database</b> database.<br>\n"; } else { echo "The mysql_select_db($database, \$connection) failed.\n"; echo "Verify that your value for \$database is correct and that the user '$username' has rights to the '$database' database.<br>\n"; } } } } // Verify $dataTable. $_SESSION['DB_HN'] = $hostname; $_SESSION['DB_DB'] = $database; $_SESSION['DB_UN'] = $username; $_SESSION['DB_PW'] = $password; if (isset($dataTable)) { if ($dataTable == '') { $errorExists = true; if (isset($_SERVER['SERVER_NAME'])) { echo "<b>\$dataTable is not set.</b><br>\n"; } else { echo "\$dataTable is not set.\n"; } } else { // Make sure that the table is in the database. // Get a list of tables from the database. $query="SHOW TABLES FROM ".$database; $ShowTables_QueryField = 'Tables_in_'.$database; $databaseTableResult = query_do($query,__FILE__,__LINE__); $tableCount = $_SESSION['mysql_num_rows']; if ($tableCount) { $databaseTableArray = array(); $databaseTableArrayCount = 0; while ($row = mysql_fetch_assoc($databaseTableResult)) { $databaseTableArray[$databaseTableArrayCount] = $row[$ShowTables_QueryField]; $databaseTableArrayCount++; } } // Test tables against database. for ($i=0; $i<count($dataTable); $i++) { if (!in_array($dataTable,$databaseTableArray)) { $errorExists = true; if (isset($_SERVER['SERVER_NAME'])) { echo "<b>The <b>$dataTable</b> table from <b>\$dataTable</b> was not found in the <b>$database</b> database.</b><br>\n"; } else { echo "The '$dataTable' table from \$dataTable was not found in the '$database' database..\n"; } } } } } else { // $dataTable does not exist $errorExists = true; if (isset($_SERVER['SERVER_NAME'])) { echo "<b>\$dataTable does not exist.</b><br>\n"; } else { echo "\$dataTable does not exist.\n"; } } // Verify $fieldArray. if (isset($fieldArray)) { for ($i=0; $i<13; $i++) { if (isset($fieldArray[$i])) { if ($fieldArray[$i] == '') { $errorExists = true; if (isset($_SERVER['SERVER_NAME'])) { echo "<b>\$fieldArray[$i] is not set.</b><br>\n"; } else { echo "\$fieldArray[$i] is not set.\n"; } } else { // Make sure that the field is in the table. $isAlpha = array('date', 'time', 'year', 'char', 'blob', 'text', 'enum', 'set'); $fieldResult = array(); $InsertDataDegug = false; $query="SHOW COLUMNS FROM ".$dataTable; $tableFieldResult = query_do($query,__FILE__,__LINE__); $fieldCount = $_SESSION['mysql_num_rows']; if ($InsertDataDegug) { echo "\$fieldCount=",$fieldCount,"<br>\n"; ?> <table><tr><td> <p><fieldset><legend><b><?=$dataTable?> fields</b></legend> <table> <tr class="bottom_info"><td class="bold_info">#</td><td class="bold_info right_info">Field</td><td class="bold_info">Type</td><td class="bold_info">QC</td></tr> <? } for ($i=0; $i<count($fieldArray); $i++) { $fieldResult[$i] = array(); $fieldResult[$i]['type'] = ""; $fieldResult[$i]['qc'] = ""; if ($fieldCount) { #echo "\$fieldCount=".$fieldCount."<br />\n"; mysql_data_seek($tableFieldResult, 0); while ($row = mysql_fetch_assoc($tableFieldResult)) { #echo $fieldArray[$i]," "; #print_r($row); #echo "<br>\n"; if ($row['Field'] == $fieldArray[$i]) { $fieldResult[$i]['type'] = $row['Type']; $fieldResult[$i]['qc'] = getQuoteCharacter($row['Type']); } } if ($InsertDataDegug) { ?> <tr> <td><?=$i?></td> <td class="right_info"><?=$fieldArray[$i]?></td> <td><?=$fieldResult[$i]['type']?></td> <td><?=$fieldResult[$i]['qc']?></td> </tr> <? } } } if ($InsertDataDegug) { ?> </table> </fieldset></p> </td></tr></table> <? } for ($i=0; $i<count($fieldArray); $i++) { if ($fieldResult[$i]['type'] == '') { // Field not found. $errorExists = true; if (isset($_SERVER['SERVER_NAME'])) { echo "The <b>$fieldArray[$i]</b> field was not found in the <b>$dataTable</b> table.<br>\n"; } else { echo "The '$fieldArray[$i]' field was not found in the '$dataTable' table.\n"; } } } } } else { $errorExists = true; if (isset($_SERVER['SERVER_NAME'])) { echo "<b>\$fieldArray[$i] does not exist.</b><br>\n"; } else { echo "\$fieldArray[$i] does not exist.\n"; } } } } else { // $fieldArray does not exist if (isset($_SERVER['SERVER_NAME'])) { $errorExists = true; echo "<b>\$fieldArray does not exist.</b><br>\n"; } else { echo "\$fieldArray does not exist.\n"; } } // END Verify that the database information has been set. if ($errorExists) { if (isset($_SERVER['SERVER_NAME'])) { echo "<br><b>InsertData cannot continue.</b><br><br>\n"; } else { echo "\nInsertData cannot continue.\n\n"; } exit; } if (isset($_SERVER['SERVER_NAME'])) { echo "<br><b>No setup errors.</b><br><br>\n"; } else { echo "\nNo setup errors.\n\n"; } $productCount = 0; $fileArray = split(",",$fileResult); foreach($fileArray as $thisFile) { if (isset($_SERVER['SERVER_NAME'])) { echo "<b>\$thisFile=",$thisFile,"</b><br>\n"; } else { echo "\$thisFile=",$thisFile,"\n"; } $productData_fh = fopen($thisFile, 'r'); while (($productLine = fgets($productData_fh)) && $productCount < 10000) { $productCount++; if (isset($_SERVER['SERVER_NAME'])) { echo "<b>".$productCount,"</b><br>\n"; } else { echo $productCount,"\n"; } // INSERT data. $productData = split("\t",$productLine); $query = "INSERT INTO ".$dataTable." ( "; $lastField = count($fieldArray)-1; for ($i=0; $i<=$lastField; $i++) { $productData[$i] = trim(addslashes($productData[$i])); if ($productData[$i] != '') { $query .= " ".$fieldArray[$i].", "; } } $query = substr($query,0,strlen($query)-3)." ) VALUES ( "; for ($i=0; $i<=$lastField; $i++) { if ($productData[$i] != '') { $query .= " ".$fieldResult[$i]['qc'].$productData[$i].$fieldResult[$i]['qc'].", "; } } $query = substr($query,0,strlen($query)-3)." )"; $tableInsert = query_do($query,__FILE__,__LINE__); } fclose($productData_fh); } if (isset($_SERVER['SERVER_NAME'])) { } else { } $_SESSION['DB_HN'] = "localhost"; $_SESSION['DB_DB'] = "jimmarti_cst"; $_SESSION['DB_UN'] = "jimmarti_CST"; $_SESSION['DB_PW'] = "omega27omicron"; if (isset($_SERVER['SERVER_NAME'])) { $thisFile = __FILE__; include('Common/pageFooter.phpinc'); } ?>