<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>NemoPS &#187; database</title>
	<atom:link href="http://nemops.com/tag/database/feed/" rel="self" type="application/rss+xml" />
	<link>http://nemops.com</link>
	<description>Prestashop Tutorials, Modules and More!</description>
	<lastBuildDate>Wed, 05 Dec 2018 13:25:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.35</generator>
	<item>
		<title>Creating Cron Jobs for PrestaShop Backups</title>
		<link>http://nemops.com/prestashop-backups-cron-jobs/</link>
		<comments>http://nemops.com/prestashop-backups-cron-jobs/#comments</comments>
		<pubDate>Tue, 28 Jun 2016 09:32:05 +0000</pubDate>
		<dc:creator><![CDATA[Nemo]]></dc:creator>
				<category><![CDATA[Tips n Tricks]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[prestashop]]></category>

		<guid isPermaLink="false">http://nemops.com/?p=2804</guid>
		<description><![CDATA[<p>Having regular backups is the very first important thing to consider, whenever you have a running web-shop. In this tutorial, we will see how to automate PrestaShop Backups using a simple script and a cron job. The backup script PrestaShop has a very simple way to create backups. In the back office controller, once you [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-backups-cron-jobs/">Creating Cron Jobs for PrestaShop Backups</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Having regular backups is the very first important thing to consider, whenever you have a running web-shop. In this tutorial, we will see how to automate PrestaShop Backups using a simple script and a cron job.</p>
<p><span id="more-2804"></span></p>
<h2>The backup script</h2>
<p>PrestaShop has a very simple way to create backups. In the back office controller, once you hit the button to create a new one, it will simply call the <strong>add()</strong> method on the <strong>PrestaShopBackup</strong> object instance.<br />
We can take advantage of this simplicity to create our own script, that can be called at any time to create a new backup.<br />
To keep things simple, let&#8217;s use the root folder of our shop. Inside it, create a new file named <strong>back-me-up.php</strong>. We will later create a cron job using cPanel to target this very script.<br />
Open it up, and start by including the following in php tags:</p>
<pre class="brush: php; title: ; notranslate">
include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/init.php');
</pre>
<p>This part initializes PrestaShop, and let&#8217;s us use its classes and functions.<br />
It is essential to create at least a bare minimum level of security, as it would be really unpleasant for us to find out HDD space filled up because someone executed our backup script dozens of time repetitively.</p>
<pre class="brush: php; title: ; notranslate">
include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/init.php');

$key = 'mypassword';

if(!Tools::getValue('k') || Tools::getValue('k') != $key)
	die('unauthorized');

</pre>
<p>We are almost done. At this point, we need to define the admin folder constant, in case it&#8217;s not been defined. This is needed for the backup script to run, otherwise it will simply die.</p>
<pre class="brush: php; title: ; notranslate">
include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/init.php');

$key = 'mypassword';

if(!Tools::getValue('k') || Tools::getValue('k') != $key)
	die('unauthorized');

if(!defined('_PS_ADMIN_DIR_'))
	define('_PS_ADMIN_DIR_',  getcwd().'/nameofmyadmin');
</pre>
<p>Make sure you replace the nameofmyadmin string with the name of your own admin folder.<br />
Lastly, let&#8217;s run the backup itself:</p>
<pre class="brush: php; title: ; notranslate">
include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/init.php');

$key = 'mypassword';

if(!Tools::getValue('k') || Tools::getValue('k') != $key)
	die('unauthorized');

if(!defined('_PS_ADMIN_DIR_'))
	define('_PS_ADMIN_DIR_',  getcwd().'/nameofmyadmin');

$backup = new PrestaShopBackup();
if($backup-&gt;add())
	die('success');
else die('error');
</pre>
<p>We are done with php! We just need to create a cron job that runs our script.<br />
Before that, I strongly recommend to manually check if it works, by reaching your site&#8217;s url /back-me-up.php?k=mypassword</p>
<div class="separator"></div>
<h2>Target our new file with a cron job</h2>
<p>You can skip this part if you already know how to create a cron job. If not, read on. I am using cPanel for the example, so if you have another control panel for your hosting space, you might have to find your way through the cron jobs setup screen.</p>
<p>Access your hosting&#8217;s cpanel, and navigate to Cron Jobs</p>
<p><a href="http://nemops.com/wp-content/uploads/2016/06/cronjobs_for_backups1.png"><img src="http://nemops.com/wp-content/uploads/2016/06/cronjobs_for_backups1.png" alt="Setting up Cron Jobs in PrestaShop 1" width="510" height="483" class="aligncenter size-full wp-image-2807" /></a></p>
<p>For the example, create a new cron job that runs every minute (you can choose it from the common settings)</p>
<p><a href="http://nemops.com/wp-content/uploads/2016/06/cronjobs_for_backups2.png"><img src="http://nemops.com/wp-content/uploads/2016/06/cronjobs_for_backups2-680x436.png" alt="PrestaShop Backup cron job settings" width="680" height="436" class="aligncenter size-large wp-image-2808" /></a></p>
<p>If you are new to cron jobs, you might have some trouble finding out the correct url. What we need to do here, in the cron command, is executing php on our script, adding the k parameter as well. Here is how the command is supposed to look like</p>
<pre class="brush: php; title: ; notranslate">
php /home/nameofyouraccount/public_html/path/to/your/main/folder/back-me-up.php k=mypassword
</pre>
<p>The account name is usually the cPanel login. If not, you can read it on the left side of the cPanel homepage, being part of <strong>Home Directory</strong></p>
<p><a href="http://nemops.com/wp-content/uploads/2016/06/cronjobs_for_backups3.png"><img src="http://nemops.com/wp-content/uploads/2016/06/cronjobs_for_backups3.png" alt="Find your account name in cPanel" width="377" height="324" class="aligncenter size-full wp-image-2809" /></a></p>
<p>Unlike with a direct url execution, when you pass in any query string parameter, they must not be preceded by a question mark, not separated by amperstands; they can simply be added one by one, separated by spaces, after the url<br />
If your site is in the root folder (public_html), the url will be</p>
<pre class="brush: php; title: ; notranslate">
php /home/nameofyouraccount/public_html/back-me-up.php k=mypassword
</pre>
<p>Save it, then go back to your PrestaShop admin, and reach <strong>Advanced Parameters > DB Backup</strong>. Wait a couple of minutes, then refresh the page. You should see a few new backup files (depending on the size of your shop, it might take a bit). If you do not, and your shop is relatively small, you might want to check the cron url is correct. It might take several minutes to back up your site, if you have more than a couple of hundreds of products.</p>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-backups-cron-jobs/">Creating Cron Jobs for PrestaShop Backups</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nemops.com/prestashop-backups-cron-jobs/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Essential Prestashop Functions – Day 2</title>
		<link>http://nemops.com/prestashop-functions-2/</link>
		<comments>http://nemops.com/prestashop-functions-2/#comments</comments>
		<pubDate>Tue, 28 Jul 2015 12:19:28 +0000</pubDate>
		<dc:creator><![CDATA[Nemo]]></dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[prestashop]]></category>

		<guid isPermaLink="false">http://nemops.com/?p=2492</guid>
		<description><![CDATA[<p>Prestashop has lots of time-saving functions that we can use when developing modules or extensions. In this second batch we will examine database-related methods. NOTICE: Values with &#8220;=&#8221; in the declaration are optionals. Database-related Functions These methods serve as helpers so that we don&#8217;t have to create a new mysql connection every time we want [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-functions-2/">Essential Prestashop Functions – Day 2</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Prestashop has lots of time-saving functions that we can use when developing modules or extensions. In this second batch we will examine database-related methods.</p>
<p><span id="more-2492"></span></p>
<p><strong>NOTICE: Values with &#8220;=&#8221; in the declaration are optionals.</strong></p>
<h2>Database-related Functions</h2>
<pre class="brush: php; title: ; notranslate">

// Retrieving an array of values from the given table
Db::getInstance()-&gt;executeS($sql, $array = true, $use_cache = true);

// Retrieving a single value
Db::getInstance()-&gt;getValue($sql, $use_cache = true);

// Retrieving a whole row
Db::getInstance()-&gt;getRow($sql, $use_cache = true);

// Executing a generic query, returns true if succeeded, false if failed
Db::getInstance()-&gt;execute($sql, $use_cache = true)

// Inserting a row
Db::getInstance()-&gt;insert($table, $data, $null_values = false, $use_cache = true, $type = Db::INSERT, $add_prefix = true)

// Updating values
Db::getInstance()-&gt;update($table, $data, $where = '', $limit = 0, $null_values = false, $use_cache = true, $add_prefix = true)

// Erase the given entry
Db::getInstance()-&gt;delete($table, $where = '', $limit = 0, $use_cache = true, $add_prefix = true)

// Escape data
Db::getInstance()-&gt;escape($string, $html_ok = false, $bq_sql = false)

// Get the primary key of the last item you added
Db::getInstance()-&gt;Insert_ID()

</pre>
<p>These methods serve as helpers so that we don&#8217;t have to create a new mysql connection every time we want to run a query</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">

// Returns an array with each item correspinding to a single database row
// It should only be used to retrieve values, use execute or the other helpers to insert/update them
$customers = Db::getInstance()-&gt;executeS('SELECT * FROM '._DB_PREFIX_.'customers');

// Returns product data of the ones that belong to the given category only (id = 4)
$products = Db::getInstance()-&gt;executeS('
	SELECT * FROM '._DB_PREFIX_.'product p
	LEFT JOIN '._DB_PREFIX_.'category_product cp ON (cp.id_product = p.id_product)
	WHERE cp.id_category = 4
');


// Retrieving the specific product name for our current language
$product_name = Db::getInstance()-&gt;getValue('SELECT name FROM '._DB_PREFIX_.'product_lang WHERE id_product = 1 AND id_lang = ' . $this-&gt;context-&gt;language-&gt;id);

// Get the whole row for customer id = 1
$customer = Db::getInstance()-&gt;getRow('SELECT * FROM '._DB_PREFIX_.'customer WHERE id_customer = 1');


// Insert some data manually (not recommended, unless you have some really specific SQL to use)
Db::getInstance()-&gt;execute('INSERT INTO '._DB_PREFIX_.'customer (id_customer, email, firstname, lastname) VALUES (9, &quot;nemo@nemops.com&quot;, &quot;Fabio&quot;, &quot;Porta&quot;)');

// Inserting a row
// The $data array must be configured like 
// 		column =&gt; value

$data = array(
	'id_customer' =&gt; 1,
	'email' =&gt; &quot;nemo@nemops.com&quot;,
	'firstname' =&gt; &quot;Fabio&quot;,
	'lastname' =&gt; &quot;Porta&quot;,
);
Db::getInstance()-&gt;insert('customer', $data);

// Updating values, array configured as above
$data = array(
	'id_customer' =&gt; 1,
	'email' =&gt; &quot;nemo@nemops.com&quot;,
	'firstname' =&gt; &quot;Fabio&quot;,
	'lastname' =&gt; &quot;Porta&quot;,
);
Db::getInstance()-&gt;update('customer', $data, 'id_customer = 1');

// Erase customer with id = 1
Db::getInstance()-&gt;delete('customer', 'id_customer = 1');

// Escape data
$sanitized = Db::getInstance()-&gt;escape('&lt;div class=&quot;test&quot;&gt;&lt;div&gt;', true);
// will return &lt;div class=\&quot;test\&quot;&gt;&lt;div&gt;

// Get the primary key of the last item you added

$data = array(
	'email' =&gt; &quot;nemo@nemops.com&quot;,
	'firstname' =&gt; &quot;Fabio&quot;,
	'lastname' =&gt; &quot;Porta&quot;,
);
Db::getInstance()-&gt;insert('customer', $data);
$last_id = Db::getInstance()-&gt;Insert_ID()
// $last_id will be the id_customer of the entry we just added


</pre>
<div class="separator"></div>
<h2>The Query object in Prestashop</h2>
<pre class="brush: php; title: ; notranslate">

DbQuery::select($fields)
DbQuery::from($table, $alias = null)
DbQuery::join($fields)
DbQuery::leftJoin($table, $alias = null, $on = null)
DbQuery::where($restriction)
DbQuery::having($restriction)
DbQUery::orderBy($fields)
DbQUery::groupBy($fields)
DbQuery::limit($limit, $offset = 0)

</pre>
<p>All these functions are used to streamline a query creation. Inspect the <strong>DbQuery</strong> class to have a complete list.</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">

	// get all products with id &gt; 3, with relative language data

	$query = new DbQuery();
	$query-&gt;select('p.*, pl.*')
		-&gt;from('product', 'p')
		-&gt;leftJoin('product_lang', 'pl', 'p.id_product = pl.id_product')
		-&gt;where('p.id_product &gt; 34')
		-&gt;where('pl.id_lang = ' . $this-&gt;context-&gt;language-&gt;id)
		-&gt;groupBy('p.id_product')
		-&gt;limit(5)

	$result = Db::getInstance()-&gt;getValue($query);

</pre>
<div class="separator"></div>
<h2>Quick escape in a SQL query</h2>
<pre class="brush: php; title: ; notranslate">

pSQL($string, $htmlOK = false)

</pre>
<p>Sanitize data which will be injected into SQL query</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">

	$search = '2&quot; clamps';
	// get aliases for the given search word, as you can see the above requires douple quotes to be escaped
	$aliases = Db::getInstance()-&gt;executeS('
	SELECT a.alias
	FROM `'._DB_PREFIX_.'alias` a
	WHERE `search` = \''.pSQL($search).'\'');

</pre>
<h2>Wrapping it up</h2>
<p>All of the methods we examined today are a huge time saver when dealing with the Database in Prestashop. I rarely use the query object, I admit, as I prefer relying on the other methods. However, since it&#8217;s getting more and more built into the standard workflow of core modules and methods, it&#8217;s good practice to start using that as well, and integrate it into your own Prestashop Module/Extension.</p>
<div class="separator"></div>
<h3>Additional Resources</h3>
<ul>
<li><a href="http://nemops.com/prestashop-functions-1/#.Vb8upPnzrmg" title="Essential Prestashop Functions – Day 1">Essential Prestashop Functions – Day 1</a></li>
<li><a href="http://nemops.com/prestashop-functions-3/#.Vb9EAPnzrmg" title="Essential Prestashop Functions – Day 3">Essential Prestashop Functions – Day 3</a></li>
<li><a href="http://nemops.com/prestashop-functions-4/#.Vc2cffnzrmg" title="Essential Prestashop Functions – Day 4">Essential Prestashop Functions – Day 4</a></li>
<li><a href="http://nemops.com/prestashop-functions-5/#.Ve6fNxHzrmg" title="Essential Prestashop Functions – Day 5">Essential Prestashop Functions – Day 5</a></li>
</ul>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-functions-2/">Essential Prestashop Functions – Day 2</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nemops.com/prestashop-functions-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Prestashop Cache Clearer &#8211; Free Prestashop module!</title>
		<link>http://nemops.com/prestashop-cache-clearer-free-prestashop-module/</link>
		<comments>http://nemops.com/prestashop-cache-clearer-free-prestashop-module/#comments</comments>
		<pubDate>Mon, 17 Nov 2014 11:47:23 +0000</pubDate>
		<dc:creator><![CDATA[Nemo]]></dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[prestashop]]></category>
		<category><![CDATA[prestashop cache]]></category>
		<category><![CDATA[prestashop speed]]></category>

		<guid isPermaLink="false">http://nemops.com/?p=2200</guid>
		<description><![CDATA[<p>The Prestashop Cache Cleaner is the Ultimate solution to your caching headaches with Prestashop One of the keys for a successful online store is speed. People don&#8217;t like browsing (nor buying from) slow websites. And if you run Prestashop you might need to get the most out of it in terms of performance. DesignHaus42 has [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-cache-clearer-free-prestashop-module/">Prestashop Cache Clearer &#8211; Free Prestashop module!</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>The Prestashop Cache Cleaner is the Ultimate solution to your caching headaches with Prestashop<br />
<span id="more-2200"></span></p>
<p><strong>One of the keys for a successful online store is speed</strong>. People don&#8217;t like browsing (nor buying from) slow websites. And if you run Prestashop you might need to get the most out of it in terms of performance. DesignHaus42 has posted an amazing article on how to use the caching system APC to boost your Prestashop speed as never before, here : <a title="Using APC to speed up Prestashop" href="http://dh42.com/blog/apc-speed-prestashop/" target="_blank">Using APC to Speed up Prestashop</a>.</p>
<p>Lesley, the article&#8217;s author, ultimately made me notice Prestashop doesn&#8217;t ever take care of cleaning server-side caching, and this might cause various headaches for both merchants and developers. With this in mind, and thanks to his wise advice, I came up with a small module that takes care of this fundamental point the default Prestashop Cache Clearer lacks.</p>
<p><strong>This Module will get rid of any kind of server-side caching, be it APC, xCache or Memcache</strong>, thus saving you from tons of headaches if you wonder why certain data or pages are completely stuck.</p>
<p>So! Head over to my addons store and get this Prestashop module for Free!</p>
<p style="text-align: center;"><a class="button style1" href="http://store.nemops.com/free-modules/38-prestashop-cache-clearer.html#.VGnf2fmjOr0">DOWNLOAD FOR FREE HERE</a></p>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-cache-clearer-free-prestashop-module/">Prestashop Cache Clearer &#8211; Free Prestashop module!</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nemops.com/prestashop-cache-clearer-free-prestashop-module/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
