Revision as of 13:48, 8 August 2019 by Daniel Baker (talk | contribs) (→‎SQL Insertion)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Please note; These snippets are extremely old. I realize they need massive updating. This will happen when I have everything moved over

SQL Insertion

   $ignorethis=do_sql_stuff($query); # Insert Query and we need no data back.

 function do_sql_stuff($query) {
   if (!$link = @mysql_connect($db_host, $db_user, $db_pass)) { $DB_ERR="Error Connecting to Host<br>$function"; DB_DED($DB_ERR); }
    else { if (!@mysql_select_db($db_name, $link))            { $DB_ERR="Error Connecting to Database at Host!!"; DB_DED($DB_ERR); }
    else { if(!$result = @mysql_query($query, $link))         { $DB_ERR="<br>Error with<br>$query"; DB_DED($DB_ERR); }
   $results = @mysql_fetch_array($result);
   return $results;  

 function db_ded($DB_ERR) { 
     echo"<FONT COLOR='Red'><B>$DB_ERR</b><br></font></B>\n"; 

SQL Query

Piece of code from my Eve API Tool. I left the variable names intact so connections are clear.

        $getValidCorps="SELECT corporationID FROM `eveapimgmt_valid_corporations` where 1";

	if (!$link = @mysql_connect($db_host, $db_user, $db_pass))		{$DB_ERR="Error Connecting to Host!!"; DB_DED($DB_ERR);}
    	else { if (!@mysql_select_db($db_name, $link))				{$DB_ERR="Error Connecting to Database at Host!!"; DB_DED($DB_ERR);}
       	else { if(!$CorpIDResult = @mysql_query($getValidCorps, $link))		{$DB_ERR="$CorpIDResult"; DB_DED($DB_ERR);}
       	else { while ($corporationID = mysql_fetch_array($CorpIDResult))
          # Do some work

Read a file

function Get_my_file($FileNameToGet) {
        $ContentsOfFile = file_get_contents($FileNameToGet);
        return $ContentsOfFile;

Write a File

Call the function with:

Push_Data_To_File($FileNameToOpen, $VariableDataToStore);


function Push_Data_To_File($FileNameToOpen, $VariableDataToStore) {
       $fh = fopen($FileNameToOpen, 'w') or die("can't open file for output");
       fwrite($fh, $VariableDataToStore); 
       return 0;