<?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>Hayden Kibble &#187; mysql</title>
	<atom:link href="http://www.haydenkibble.com/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.haydenkibble.com</link>
	<description>PHP-SEO-IM-DESIGN</description>
	<lastBuildDate>Fri, 17 Dec 2010 23:06:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Basic SQL Injection Tutorial</title>
		<link>http://www.haydenkibble.com/2010/05/basic-sql-injection-tutorial/</link>
		<comments>http://www.haydenkibble.com/2010/05/basic-sql-injection-tutorial/#comments</comments>
		<pubDate>Fri, 07 May 2010 18:54:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP/MySQL/AJAX]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.haydenkibble.com/?p=57</guid>
		<description><![CDATA[Since first laying eyes on Magento, the open source eCommerce software, I been impressed by it&#8217;s power, flexibility and rigid code structure. But despite Magento&#8217;s almost endless list of strengths, it also has some significant weaknesses, that often leave me frustrated and confused. One such weakness is the apparent lack of any functionality in regards [...]]]></description>
			<content:encoded><![CDATA[<p>Since first laying eyes on Magento, the open source eCommerce software, I been impressed by it&#8217;s power, flexibility and rigid code structure. But despite Magento&#8217;s almost endless list of strengths, it also has some significant weaknesses, that often leave me frustrated and confused. One such weakness is the apparent lack of any functionality in regards to copying products and categories.</p>
<p>I had created a category, with about 10 child categories. Now I just wanted to duplicate that category 5 times, rather than creating another 4 from scratch, each with 10 children (4&#215;10=40 categories!). Rather than spend the next couple of hours adding categories, I knocked together this quick PHP script. Simply pass in the ID of the category you&#8217;d like to duplicate, and it will create a copy of the category, along with all of it&#8217;s child categories, as deep as they go!</p>
<p>Ideally, this would be a proper Magento module, but I&#8217;m just starting out with Magento. Give me 6 months, eh?!</p>
<p>To use the script, simply copy it into a file such as copycat.php in your Magento root directory and call it like so:</p>
<p>http://www.example.com/copycat.php?id=<em>[CATEGORY ID TO COPY]</em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Please specify a category ID'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$catId</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'app/etc/local.xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$host</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">global</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">resources</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">default_setup</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">host</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">global</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">resources</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">default_setup</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">username</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">global</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">resources</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">default_setup</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">password</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dbname</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">global</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">resources</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">default_setup</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbname</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$res</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_pconnect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dbname</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000088;">$catsDone</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
duplicate_entity<span style="color: #009900;">&#40;</span><span style="color: #000088;">$catId</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$catsDone</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' Categories duplicated.'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> duplicate_entity<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$parent_id</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$catsDone</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #666666; font-style: italic;">// Grab category to copy</span>
	<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM catalog_category_entity WHERE entity_id = &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$query_entity</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$entity</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query_entity</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$parent_id</span><span style="color: #009900;">&#41;</span><span style="color: #000088;">$parent_id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$entity</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">parent_id</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO catalog_category_entity (entity_type_id, attribute_set_id, parent_id, created_at, updated_at, path, position, level, children_count)
						VALUES (<span style="color: #006699; font-weight: bold;">{$entity-&gt;entity_type_id}</span>, <span style="color: #006699; font-weight: bold;">{$entity-&gt;attribute_set_id}</span>, <span style="color: #006699; font-weight: bold;">{$parent_id}</span>, NOW(), NOW(), '', <span style="color: #006699; font-weight: bold;">{$entity-&gt;position}</span>, <span style="color: #006699; font-weight: bold;">{$entity-&gt;level}</span>, <span style="color: #006699; font-weight: bold;">{$entity-&gt;children_count}</span>)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$newEntityId</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_insert_id</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT path FROM catalog_category_entity WHERE entity_id = &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$parent_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$parent</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$path</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$parent</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">path</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$newEntityId</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE catalog_category_entity SET path='&quot;</span><span style="color: #339933;">.</span> <span style="color: #000088;">$path</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' WHERE entity_id=&quot;</span><span style="color: #339933;">.</span> <span style="color: #000088;">$newEntityId</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'datetime'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'decimal'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'int'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'text'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'varchar'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$dataType</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM catalog_category_entity_&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$dataType</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;
				WHERE entity_id=&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$entity</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entity_id</span><span style="color: #339933;">;</span>
				<span style="color: #666666; font-style: italic;">//die($sql);</span>
		<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO catalog_category_entity_&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$dataType</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; (entity_type_id, attribute_id, store_id, entity_id, value)
							VALUES (<span style="color: #006699; font-weight: bold;">{$value-&gt;entity_type_id}</span>, <span style="color: #006699; font-weight: bold;">{$value-&gt;attribute_id}</span>, <span style="color: #006699; font-weight: bold;">{$value-&gt;store_id}</span>, <span style="color: #006699; font-weight: bold;">{$newEntityId}</span>, '<span style="color: #006699; font-weight: bold;">{$value-&gt;value}</span>')&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT entity_id FROM catalog_category_entity WHERE parent_id = &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$entity</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		duplicate_entity<span style="color: #009900;">&#40;</span><span style="color: #000088;">$entity</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entity_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$newEntityId</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$catsDone</span><span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><a href="http://www.haydenkibble.com/?ibsa=share&amp;id=57" id="share-link-">Share</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.haydenkibble.com/2010/05/basic-sql-injection-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

