You are here:  » export product in xml feed

Support Forum



export product in xml feed

Submitted by marco.saiu on Mon, 2011-07-25 16:07 in

Hello David i try this script for export product in xml format but i have some errors...

<?php
  set_time_limit(0);
  require("../includes/common.php");
  $fp = fopen("../export/products.xml","w");
  if (!$fp) die("Could not create output file, check permissions!");
  fwrite($fp,"<?xml version='1.0' encoding='UTF-8'?>");
    print "<products>";
    $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE `marchant` = 'Nokia'";
    if (database_querySelect($sql,$rows))
    {
      foreach($rows as $row)
      {
        fwrite($fp,"<product>");
        fwrite($fp,"<merchant>".$row["merchant"]."</merchant>");
        fwrite($fp,"<productname>".$row["name"]."</productname>");
        fwrite($fp,"<deeplink>".$row["buy_url"]."</deeplink>");
        fwrite($fp,"<price>".$row["price"]."</price>");
        fwrite($fp,"<description>".$row["description"]."</description>");
        fwrite($fp,"<image_url>".$row["image_url"]."</image_url>");
        fwrite($fp,"<category>".$row["category"]."</category>");
        fwrite($fp,"<brand>".$row["brand"]."</brand>");
        fwrite($fp,"</product>");
      }
    fwrite($fp,"</products>");
  }
  print "Done.";
?>

s01:~/admin/scripts$ php export.php
PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /var/www/vhosts/..../admin/includes/database.php on line 27
PHP Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /var/www/vhosts/..../admin/includes/database.php on line 32

Have any idea? I use last version of tp!

Thank's

Submitted by support on Mon, 2011-07-25 16:25

Hi Marco,

I think just this line:

    $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE `marchant` = 'Nokia'";

...marchant should be merchant (as it is still called in the database) - have a go with:

    $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE `merchant` = 'Nokia'";

Cheers,
David.
--
PriceTapestry.com

Submitted by marco.saiu on Mon, 2011-07-25 16:39

Sure... Lol!

For solve memory limit have any suggest?

Thank's

Submitted by support on Mon, 2011-07-25 18:48

Hi Marco,

Probably best to use an unbuffered query; in place of (including above correction)

    $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE `marchant` = 'Nokia'";
    if (database_querySelect($sql,$rows))
    {
      foreach($rows as $row)
      {

...have a go with:

    $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE `merchant` = 'Nokia'";
    $link = mysql_connect($config_databaseServer,$config_databaseUsername,$config_databasePassword);
    mysql_select_db($config_databaseName,$link);
    $result = mysql_unbuffered_query($sql,$link);
    if ($result)
    {
      while($row = mysql_fetch_array($result,MYSQL_ASSOC))
      {

Cheers,
David.
--
PriceTapestry.com

Submitted by marco.saiu on Tue, 2011-07-26 10:23

Hello David,

with this code the script run but save only 1 line!

    $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE `merchant` = 'Nokia'";
    $link = mysql_connect($config_databaseServer,$config_databaseUsername,$config_databasePassword);
    mysql_select_db($config_databaseName,$link);
    $result = mysql_unbuffered_query($sql,$link);
    if ($result)
    {
      while($row = mysql_fetch_array($result,MYSQL_ASSOC))
      {

You have complete and currect script?

Thank's!

Submitted by support on Tue, 2011-07-26 10:50

Hi Marco,

Can you email me the full file and I'll check it out...

Cheers,
David.
--
PriceTapestry.com

Submitted by marco.saiu on Tue, 2011-07-26 11:39

Okay David i have send my script.

Thank's
Marco