Jump to content

Can't insert time via Query - date_add & date_upd | Db::getInstance()->Execute


Im IN

Recommended Posts

Hi,
I'm trying insert product via query, everything is ok, but date_add & date_upd is not working.
I'm using Db::getInstance()->Execute();
if I use mysql_query(); everything works.

My code

$result = Db::getInstance()->Execute(' INSERT INTO `'._DB_PREFIX_.'product` 
       (`id_supplier`,
       `id_manufacturer`,
       `date_upd`) 

       VALUES (
       NULL,
       '.$id_manufacturer.',
       0000-00-00 00:00:00
       )');



or

$reqdate = date("Y-m-d H:i:s");
$result = Db::getInstance()->Execute(' INSERT INTO `'._DB_PREFIX_.'product` 
       (`id_supplier`,
       `id_manufacturer`,
       `date_upd`) 

       VALUES (
       NULL,
       '.$id_manufacturer.',
       '.$reqdate.'
       )');



Thank you

Link to comment
Share on other sites

hi,
i don't understand what's wrong with time... seems that is a problem with rss too... as it doesn't save added product time but only date... is it possible or am i wrong? please can you check the following rss.php and tell me what can i do about time? The output shows the correct date but "00:00:00" as time for every product...weird

include(dirname(__FILE__).'/../../config/config.inc.php');
require_once(dirname(__FILE__).'/../../init.php');

function datetimeUS2Time ( $datetime ) 
{ 
list( $date , $time ) = explode ( ' ' , $datetime ); 
list( $hour , $minute , $second ) = explode ( ':' , $time ); 
list( $year , $month , $day ) = explode ( '-' , $date ); 
$timestamp = mktime ( $hour , $minute , $second , $month , $day , $year ); 
return $timestamp ; 
}

// Get data
$number = ((int)(Tools::getValue('n')) ? (int)(Tools::getValue('n')) : 10);
$orderByValues = array(0 => 'date_add', 1 => 'price', 2 => 'name', 3 => 'date_upd', 4 => 'position');
$orderWayValues = array(0 => 'DESC', 1 => 'ASC');
$orderBy = Tools::strtolower(Tools::getValue('orderby', $orderByValues[(int)(Configuration::get('PS_PRODUCTS_ORDER_BY'))]));
$orderWay = Tools::strtoupper(Tools::getValue('orderway', $orderWayValues[(int)(Configuration::get('PS_PRODUCTS_ORDER_WAY'))]));
if (!in_array($orderBy, $orderByValues))
   $orderBy = $orderByValues[0];
if (!in_array($orderWay, $orderWayValues))
   $orderWay = $orderWayValues[0];
$id_category = ((int)(Tools::getValue('id_category')) ? (int)(Tools::getValue('id_category')) : 1);
$products = Product::getNewProducts(intval($cookie->id_lang), 0, 10, false, 'date_add', 'DESC');
$currency = new Currency((int)($cookie->id_currency));
$affiliate = (Tools::getValue('ac') ? '?ac='.(int)(Tools::getValue('ac')) : '');
$datepub = date ( DATE_RSS );

// Send feed
header("Content-Type:text/xml; charset=utf-8");
echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";
?>


       <title><![CDATA[<?php echo Configuration::get('PS_SHOP_NAME') ?>]]></title>
       <link><?php echo _PS_BASE_URL_.__PS_BASE_URI__; ?></link>
<?php echo Configuration::get('PS_SHOP_EMAIL') ?>
PrestaShop
<?php echo Language::getIsoById((int)($cookie->id_lang)); ?>

           <title><![CDATA[<?php echo Configuration::get('PS_SHOP_NAME') ?>]]></title>
<?php echo _PS_BASE_URL_.__PS_BASE_URI__.'img/logo.jpg'; ?>
           <link><?php echo _PS_BASE_URL_.__PS_BASE_URI__; ?></link>
           <?php $now = date("D, d M Y H:i:s O");?>

<?php echo $now; ?>
<?php
   foreach ($products AS $product)
   {
       $logged = date ( DATE_RSS , datetimeUS2Time ( $product[ 'date_add' ] ));
       $image = Image::getImages((int)($cookie->id_lang), $product['id_product']);
       echo "\t\t\n";
       echo "\t\t\t<title><![CDATA[".$product['name']." - ".html_entity_decode(Tools::displayPrice(Product::getPriceStatic($product['id_product']), $currency), ENT_COMPAT, 'UTF-8')." ]]></title>\n";
       echo "\t\t\t" . $logged . "\n" ;
       echo "\t\t\t";
       $cdata = true;
       if (is_array($image) AND sizeof($image))
       {
           echo "<![CDATA[";
           $cdata = false;
       }
       if ($cdata)
           echo "<![CDATA[";
       echo $product['description_short']."]]>\n";

       echo "\t\t\t<link><![CDATA[".htmlspecialchars($link->getproductLink($product['id_product'], $product['link_rewrite'], Category::getLinkRewrite((int)($product['id_category_default']), $cookie->id_lang))).$affiliate."]]></link>\n";
       echo "\t\t\n";
   }
?>


Link to comment
Share on other sites

Hi all,

@Im IN

Could you try to put some quote before and after your $reqdate in your SQL request.
I recommend you to use Product Object, it will be easier instead of injecting directly data with an Execute (you can also use autoExecute function for sql INSERT :))


@mmsh

I don't think that time is your only problem on this script.
You have a parse error here :

echo "<![CDATA[";


How did you manage to make it work ? o_O

Link to comment
Share on other sites

sorry Fabien... is an error of posting... not my mistake, if i paste the entire code here at that line it truncates, i don't know why
i'm not able to post the correct code...why?
anyway... attached the zip with the php code inside...if you wanna take a look

but it doesn't work... time is 00:00:00
maybe it depends by an import from .csv instead of manual insertion of products???

rss4.zip

Link to comment
Share on other sites

I execute your script and I saw this :

...

           <title><![CDATA[MacBook Air - 1 799,00 € ]]></title>
Mon, 20 Jun 2011 17:23:56 +0200
<![CDATA[MacBook Air is ultrathin, ultraportable, and ultra unlike anything else. But you don’t lose inches and pounds overnight. It’s the result of rethinking conventions. Of multiple wireless innovations. And of breakthrough design. With MacBook Air, mobile computing suddenly has a new standard.]]>

           <link><![CDATA[http://localhost/prestashop.1.4.x/product.php?id_product=5]]></link>


           <title><![CDATA[MacBook - 1 400,00 € ]]></title>
Mon, 20 Jun 2011 17:23:56 +0200
<![CDATA[MacBook makes it easy to hit the road thanks to its tough polycarbonate case, built-in wireless technologies, and innovative MagSafe Power Adapter that releases automatically if someone accidentally trips on the cord.]]>
           <link><![CDATA[http://localhost/prestashop.1.4.x/product.php?id_product=6]]></link>

...



So I think the problem come from your database.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...