Results 1 to 12 of 12
  1. #1
    Newbie
    Join Date
    January 24th, 2006
    Posts
    15
    Problems with php datafeed download script
    Hi, I am having major problems downloading a datafeed with this script
    Code:
    <?php
    	   
    $ftp_server = 'aftp.linksynergy.com';
    $ftp_user_name = 'username';
    $ftp_user_pass = 'password';
    
    $local_path = ".";
    
    $server_files = array(
    	 "/2613_160021_mp.txt.gz.lmp",	
    );	
    $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
    
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
     if (!$login_result) {
         die(" couldn't login.<br>")
    	                 ;}
    foreach($server_files as $server_file)
    {
    	$local_file = $local_path.$server_file;
    
    	if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
       		echo "Successfully written to $local_file\n";
    	} else {
       		echo "There was a problem\n";
    	}
    }	
    ftp_close($conn_id);
    
    ?>
    when I run the script it says htere was a problem.

    I have tried to download the file using command prompt and it said " no such file or directory exists" I am extremely frustrated and desperately need some help. Also I suspect that my SID may be wrong so does anyone know where I can find it? I read a post that said it was in a link on the run reports page and when you hove over the link it will apear in the url. Please, Please, Please help me.

  2. #2
    ABW Ambassador Snib's Avatar
    Join Date
    January 18th, 2005
    Location
    Virginia
    Posts
    5,303
    Remove the comma in this line:

    "/2613_160021_mp.txt.gz.lmp",

    Unless you're going to have a value after that, the comma will cause a syntax error.

    - Scott
    Hatred stirs up strife, But love covers all transgressions.

  3. #3
    Newbie
    Join Date
    January 24th, 2006
    Posts
    15
    Hi, Thank you for the tip. It turns out that my sid was wrong. Again thank you for the help.
    Last edited by steven420; November 17th, 2006 at 07:35 PM.

  4. #4
    ABW Ambassador Snib's Avatar
    Join Date
    January 18th, 2005
    Location
    Virginia
    Posts
    5,303
    You might want to log in to the FTP and see if the file you're requesting exists. Is that the error you're getting?

    - Scott
    Hatred stirs up strife, But love covers all transgressions.

  5. #5
    Newbie
    Join Date
    January 24th, 2006
    Posts
    15
    Red face
    Hi, thanks for the help the problem was in my sid. But now I am having problems loading the file into a table on my database. I'm using php and mysql. I'm not sure how to work with the .lmp . Does this need to be removed or something? I would really appreciate it if someone could tell me how I can get the data to go into my database. The script runs fine but when I go to see if there is data in the table it shows nothing.

    Thanks,
    Steven.

  6. #6
    Animal Lover
    Join Date
    January 18th, 2005
    Location
    oz
    Posts
    1,210
    Get rid of the imp in the file name ie

    "/2613_160021_mp.txt.gz"

    cheers
    Oscar
    My DataFeed Scripts - php datafeed scripts for your site
    Shareasale datafeed scripts - to display Shareasale datafeeds
    Linkshare datafeed scripts - for multiple Linkshare merchants

  7. #7
    Newbie
    Join Date
    January 24th, 2006
    Posts
    15
    Hi, Thanks guys for the help. I downloaded the file without the .lmp and tried that and it still won't load any data to the table. I have no idea what is going on. This is the script I'm using:
    Code:
    <?php
      
      $feedfile = '/2613_1600216_mp.txt.gz';
      $feed = gzopen($feedfile, 'r');  
       $link = mysql_connect('localhost', 'username', 'password');
        if (!$link) {
          die('Could not connect: ' . mysql_error());
                    }
      $DB = mysql_select_db ("testdatabase");
        if (!$DB) {
    	  die('Could not connect to testdatabase: ' . mysql_error());
    	          }
               mysql_query("drop table overstock"); 
      $table = mysql_query("CREATE TABLE overstock (                    
                  id INT NOT NULL,
    	 KEY prod_id (id),
                  prod_name varchar(255) NOT NULL, 
                  sku varchar(40) NOT NULL,
    	 prim_category varchar(50) NOT NULL,
    	 prod_url varchar(200) NOT NULL,
    	 prod_desc blob NOT NULL,
    	 price INT NOT NULL,
    	 col_id INT NOT NULL AUTO_INCREMENT ,
    	 PRIMARY KEY (col_id)
    				       )
    			          ");
    	  if (!$table) {
    	    die('Could not create table: ' . mysql_error()) ;
    		           } 
    		while($data = fgetcsv($feed, 3000, "r")) {  
    		// Column variables
      $id = addslashes($data[1]);
      $prod_name = addslashes($data[2]);
      $sku = addslashes($data[3]);
      $prim_category = addslashes($data[4]);
      $prod_url = addslashes($data[6]);
      $prod_desc = addslashes($data[9]);
      $price = addslashes($data[14]);
      $reccount = 0;
      $insert = mysql_query ("insert into overstock( 
                              id, 
    		prod_name,						             sku, 
    		prim_category, 
    		prod_url, 
    		prod_desc, 
    		price)  
                                 values ('$id', 
                                            '$prod_name', 
    	                           '$sku', 
    	                           '$prim_category', 
    	                           '$prod_url', 
    	                           '$prod_desc', 
    		              '$price')")
    	          or die(mysql_error());
    	 $reccount++;  
    				                                    }
    gzclose ($feedfile);
    mysql_close($link);
    ?>
    Any help would be great.

    Thanks,
    Steven.

  8. #8
    ABW Ambassador Snib's Avatar
    Join Date
    January 18th, 2005
    Location
    Virginia
    Posts
    5,303
    Steven,

    First never use values() in your SQL query. Always use "set prod_name = 'name', prod_url = 'etc'" because your code won't need to change if you add a field to your database. What I would do is print your SQL query out then copy and paste it into mySQL. See what the problem is by doing that.

    - Scott
    Hatred stirs up strife, But love covers all transgressions.

  9. #9
    Animal Lover
    Join Date
    January 18th, 2005
    Location
    oz
    Posts
    1,210
    while($data = fgetcsv($feed, 3000, "r"))

    All my LS feeds have | as the delimitor ie (not sure if it's across the board)

    while($data = fgetcsv($feed, 3000, "|"))

    cheers
    Oscar
    My DataFeed Scripts - php datafeed scripts for your site
    Shareasale datafeed scripts - to display Shareasale datafeeds
    Linkshare datafeed scripts - for multiple Linkshare merchants

  10. #10
    Newbie
    Join Date
    January 24th, 2006
    Posts
    15
    Thank you oscar and snib for the help. Ok I am still having problems. I have re-written the script and the problem seems to be happening when I try to insert data into a table. Up until "$loop" there were no problems. When I run the script no messages are displayed. Please help and thank you for all the help so far. Here is the script:
    Code:
    <?php 
    $conn = mysql_connect('localhost', 'username', 'password') or die ("could not connect to server: " . mysql_error()); 
    if ($conn) { 
    echo "connected to server<br>"; 
    } 
    $database = mysql_select_db('testdatabase', $conn); 
    if (!$database) { 
    die('Could not connect to testdatabase: ' . mysql_error()); 
    } 
    if ($database) { 
    echo "connected to database<br>"; 
    } 
    $file = gzopen("2613_1600216_mp.txt.gz","r"); 
    if (!$file) { 
    die ('could not read file: ' . mysql_error()); 
    } 
    $rownum = 0; 
    $loop =while ($data = fgetcsv($file, 3000, "")) { 
    if ($rownum > 0) { 
    $name = mysql_real_escape_string($data[0]); 
    if (!$name) { 
    die ('problem with data?: ' . mysql_error()); 
    } 
    $sql = mysql_query("insert into overstock (set name = '$name')"); 
    if (!$sql) { 
    die ('could not insert: ' . mysql_error()); 
    } 
    } 
    } 
    if (!$loop) { 
    die ('could not run loop: ' . mysql_error()); 
    } 
    $gz_close = gzclose($file); 
    if (!$gz_close) { 
    die ('could not close gz: ' . mysql_error()); 
    } 
    $conn_close = mysql_close($conn); 
    if (!$conn_close) { die( "could not close connection: " . mysql_error());} 
    ?>

  11. #11
    ABW Ambassador Snib's Avatar
    Join Date
    January 18th, 2005
    Location
    Virginia
    Posts
    5,303
    I don't think you're testing your SQL queries. You shouldn't have parenthesis around your set statement. Always test your SQL statements manually with mySQL to ensure you're generating them properly.

    - Scott
    Hatred stirs up strife, But love covers all transgressions.

  12. #12
    ABW Ambassador MoneyBusiness's Avatar
    Join Date
    March 14th, 2006
    Posts
    2,051
    Quote Originally Posted by steven420
    Code:
    $rownum = 0; 
    $loop =while ($data = fgetcsv($file, 3000, "")) { 
       if ($rownum > 0) { 
           $name = mysql_real_escape_string($data[0]); 
           if (!$name) { 
               die ('problem with data?: ' . mysql_error()); 
           } 
           $sql = mysql_query("insert into overstock (set name = '$name')"); 
           if (!$sql) { 
                die ('could not insert: ' . mysql_error()); 
           } 
       } 
    }
    If you're not getting any messages, it's likely that the rest of your code seems to work, but the loop isn't (especially since you've got a lot of error handling in there). See where you have
    Code:
    $rownum = 0
    ? You haven't incremented it in your loop at all, and you have a condition of
    Code:
    if($rownum > 0)
    for anything to fire properly (which I'm guessing is to ignore the field names in the datafeed).

    You should simply need to increment your variable
    Code:
    $rownum++;
    right before the end of your loop and after your $rownum condition.

    HOpe that helps.

    EDIT: oh and by the way, consider changing the part inside your loop to this:

    Code:
    if ($rownum > 0) { 
           $name = mysql_real_escape_string($data[0]); 
           if (!empty($name)) { 
              $sql = mysql_query("insert into overstock (set name = '$name')");   
              if (!$sql) { 
                die ('could not insert: ' . mysql_error()); 
              } 
           } 
           
    }
    I say this because in the original, if no "name" value is returned, you issue a die statement and your script will abort. The problem with this, is that most datafeeds aren't perfect, and it might be quite possible that you'll come across a record that doesn't have this value in it (who knows). The way I did it above, if it doesn't find a "name" value, it simply ignores that record and moves on to the next. Make sense?
    Last edited by MoneyBusiness; November 29th, 2006 at 08:41 AM.

  13. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Php Script to Download Web File Not Working
    By Uncle Rico in forum Programming / Datafeeds / Tools
    Replies: 7
    Last Post: January 19th, 2009, 01:11 PM
  2. Non-PHP script to import datafeed to database
    By markwelch in forum Programming / Datafeeds / Tools
    Replies: 5
    Last Post: February 12th, 2007, 06:12 PM
  3. Linkshare Datafeed Download Script
    By Snib in forum Programming / Datafeeds / Tools
    Replies: 28
    Last Post: August 11th, 2006, 12:05 AM
  4. Datafeed Download w/ script???
    By cditty in forum Commission Junction - CJ
    Replies: 12
    Last Post: October 27th, 2003, 05:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •