<?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>Daniel15&#039;s Blog &#187; PHP</title>
	<atom:link href="http://dan.cx/blog/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://dan.cx/blog</link>
	<description>Blog of Daniel, a slightly awesome 19-year-old web developer from Melbourne, Australia</description>
	<lastBuildDate>Sun, 15 Aug 2010 02:22:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>MySpace Friend List Export &#8211; Code now available</title>
		<link>http://dan.cx/blog/2007/10/myspace-friend-list-export-code-now-available/</link>
		<comments>http://dan.cx/blog/2007/10/myspace-friend-list-export-code-now-available/#comments</comments>
		<pubDate>Sat, 27 Oct 2007 11:38:36 +0000</pubDate>
		<dc:creator>Daniel15</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[MySpace]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[cURL]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[Friends]]></category>
		<category><![CDATA[mspagerstate]]></category>
		<category><![CDATA[viewstate]]></category>

		<guid isPermaLink="false">http://www.daniel15.com/blog/2007/10/27/myspace-friend-list-export-code-now-available/</guid>
		<description><![CDATA[The code for the MySpace Friend List Export script I wrote a while back is now available for download. If you&#8217;re a PHP programmer and are interested in viewing the source code for it, take a look at http://stuff.daniel15.com/php/myspace/get_friends.txt The code is quite ugly, but, well, so is MySpace. That&#8217;s my excuse.]]></description>
			<content:encoded><![CDATA[<p>The code for the <a href="http://www.daniel15.com/blog/2007/09/19/myspace-friend-list-export/">MySpace Friend List Export</a> script I wrote a while back is now available for download. If you&#8217;re a PHP programmer and are interested in viewing the source code for it, take a look at <a href="http://stuff.daniel15.com/php/myspace/get_friends.txt">http://stuff.daniel15.com/php/myspace/get_friends.txt</a> <img src='http://dan.cx/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The code is quite ugly, but, well, so is MySpace. That&#8217;s my excuse. <img src='http://dan.cx/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://dan.cx/blog/2007/10/myspace-friend-list-export-code-now-available/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Restore MySQL dump (backup) using PHP</title>
		<link>http://dan.cx/blog/2006/12/restore-mysql-dump-using-php/</link>
		<comments>http://dan.cx/blog/2006/12/restore-mysql-dump-using-php/#comments</comments>
		<pubDate>Sat, 09 Dec 2006 01:03:28 +0000</pubDate>
		<dc:creator>Daniel15</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.daniel15.com/blog/2006/12/09/restore-mysql-dump-backup-using-php/</guid>
		<description><![CDATA[The other day, I was looking for an easy way to restore a MySQL dump (or backup, whatever you like to call it) in PHP. I&#8217;ve previously used a segment of the code from PHP MySQL Backup V 2.2 for this, but it didn&#8217;t seem to support FULLTEXT indicies that well. So, I searched around, [...]]]></description>
			<content:encoded><![CDATA[<p>The other day, I was looking for an easy way to restore a MySQL dump (or backup, whatever you like to call it) in PHP. I&#8217;ve previously used a segment of the code from <a href="http://www.absoft-my.com/pondok/backup.php">PHP MySQL Backup V 2.2</a> for this, but it didn&#8217;t seem to support FULLTEXT indicies that well. So, I searched around, but couldn&#8217;t find anything. I even asked on the PHP IRC channel, and they suggested to use shell_exec to call mysql (unfortunately, I&#8217;ve disabled shell_exec for  security reasons). Looking closer, I noticed that this was actually quite easy to do. <span id="more-45"></span>Here&#8217;s the code I wrote to restore a phpMyAdmin MySQL dump (not sure if it works with mysqldump dumps):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php
<span style="color: #666666; font-style: italic;">/*
 * Restore MySQL dump using PHP
 * (c) 2006 Daniel15
 * Last Update: 9th December 2006
 * Version: 0.2
 * Edited: Cleaned up the code a bit. 
 *
 * Please feel free to use any part of this, but please give me some credit :-)
 */</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Name of the file</span>
<span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'test.sql'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// MySQL host</span>
<span style="color: #000088;">$mysql_host</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// MySQL username</span>
<span style="color: #000088;">$mysql_username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'root'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// MySQL password</span>
<span style="color: #000088;">$mysql_password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Database name</span>
<span style="color: #000088;">$mysql_database</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'test'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//////////////////////////////////////////////////////////////////////////////////////////////</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Connect to MySQL server</span>
<span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mysql_host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mysql_username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mysql_password</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Error connecting to MySQL server: '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Select database</span>
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mysql_database</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Error selecting MySQL database: '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Temporary variable, used to store current query</span>
<span style="color: #000088;">$templine</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Read in entire file</span>
<span style="color: #000088;">$lines</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Loop through each line</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$lines</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$line</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Skip it if it's a comment</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$line</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'--'</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$line</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Add this line to the current segment</span>
	<span style="color: #000088;">$templine</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$line</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// If it has a semicolon at the end, it's the end of the query</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$line</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">';'</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Perform the query</span>
		<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$templine</span><span style="color: #009900;">&#41;</span> or <span style="color: #b1b100;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Error performing query \'&lt;strong&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$templine</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'\': '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;br /&gt;&lt;br /&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// Reset temp variable to empty</span>
		<span style="color: #000088;">$templine</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>See? How easy is that? <img src='http://dan.cx/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p><strong>Update:</strong> This also works for mysqldump dumps <img src='http://dan.cx/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://dan.cx/blog/2006/12/restore-mysql-dump-using-php/feed/</wfw:commentRss>
		<slash:comments>37</slash:comments>
		</item>
	</channel>
</rss>
