enter into mysql

Discussion in 'PHP' started by izlik, Jun 4, 2007.

  1. #1
    Hello.

    i have this script bellow wich reads a .txt file and get's it's contents into my .php and i wanted to ask if it's possible to make and mysql entry each time a specific line changes in the txt?

    in the TXT is this line "Name: p3403_dpdp-ii TIP3P ff96" is it somehow possible to make an mysql entry into my database as soon as it changes to someting else? like if i want it to place a count of 1 into the database table each time so i could for example se how many time in total it has changed.

    <?php
    $file = fopen("myfile.txt", "r") or exit("Cannot to open file!");
    //Read a line of the file until found what you are looking for
    while(!feof($file))
      {
      echo fgets($file). "<br />";
      }
    fclose($file);
    ?>
    PHP:
     
    izlik, Jun 4, 2007 IP
  2. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #2
    sure. just a simple pattern match against the contents of the file.

    
    <?php
        $file = "mytext.txt";
        
        if (file_exists($file))
        {
    	$fh = fopen($file,"r");
    	$data = fread( $fh, filesize($file) );
        }
    
        if(!preg_match("/name: p3403_dpdp-ii tip3p ff96/i",$data))
        {
            // it changed do sql insert here.
        }
        else
        {
            return; // it didn't change
        }
    ?>
    
    PHP:
     
    ansi, Jun 4, 2007 IP
  3. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #3
    hey ansi and thanks, now my question is that if the name that changed does a mysql entry, and later the new name that replaced "p3403_dpdp-ii tip3p ff96" changes again, how will that be recorded into the database?
     
    izlik, Jun 4, 2007 IP
  4. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #4
    store the string inside the database and select it before doing the pattern match and then match against that. if it has changed, update the rows you want on you database and then update the keyword in there as well so next time it is searching for the new string instead of the old. hope this helped some.
     
    ansi, Jun 4, 2007 IP