<?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>El Blog de Manu Garcia &#187; mysqldump</title>
	<atom:link href="http://www.manugarcia.es/tag/mysqldump/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.manugarcia.es</link>
	<description>Programador Web y emprendedor</description>
	<lastBuildDate>Thu, 06 Oct 2011 10:48:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Restaurar un Mysql Backup con php</title>
		<link>http://www.manugarcia.es/2009/09/05/restaurar-un-mysql-backup-con-php/</link>
		<comments>http://www.manugarcia.es/2009/09/05/restaurar-un-mysql-backup-con-php/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 09:38:28 +0000</pubDate>
		<dc:creator>Manu Garcia</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysqldump]]></category>

		<guid isPermaLink="false">http://mgarcia.info/?p=73</guid>
		<description><![CDATA[Escribo un post rápido sobre algo tan sencillo que ni se me había pasado por la cabeza, acostumbrado al acceso shell y el uso de mysqldump. Hace poco un amigo me comentaba el problema que tuvo al subir a un servidor un sql porque no tenía acceso shell para hacer mysqldump y tuvo que dividir [...]]]></description>
			<content:encoded><![CDATA[<p>Escribo un post rápido sobre algo tan sencillo que ni se me había pasado por la cabeza, acostumbrado al acceso shell y el uso de mysqldump. Hace poco un amigo me comentaba el problema que tuvo al subir a un servidor un sql porque no tenía acceso shell para hacer mysqldump y tuvo que dividir el sql en varias partes para su uso en PhpMyAdmin&#8230;</p>
<p>Pero hay una solución más sencilla y mucho más rapida, que podemos encontrar en el <a href="http://d15.biz/blog/2006/12/restore-mysql-dump-using-php/">blog de Daniel15</a></p>
<blockquote>
<div>
<div>
<pre 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 <img src='http://www.manugarcia.es/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />
 */</span>

<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>

<span style="color: #666666; font-style: italic;">//////////////////////////////////////////////////////////////////////////////////////////////</span>

<span style="color: #666666; font-style: italic;">// Connect to MySQL server</span>
<span style="color: #990000;">mysql_connect</span><span style="color: #009900;">(</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;">)</span> or <span style="color: #990000;">die</span><span style="color: #009900;">(</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;">(</span><span style="color: #009900;">)</span><span style="color: #009900;">)</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;">(</span><span style="color: #000088;">$mysql_database</span><span style="color: #009900;">)</span> or <span style="color: #990000;">die</span><span style="color: #009900;">(</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;">(</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>

<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;">(</span><span style="color: #000088;">$filename</span><span style="color: #009900;">)</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;">(</span><span style="color: #000088;">$lines</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$line</span><span style="color: #009900;">)</span>
<span style="color: #009900;">{</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;">(</span><span style="color: #990000;">substr</span><span style="color: #009900;">(</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;">)</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;">)</span>
		<span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>

	<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;">(</span><span style="color: #990000;">substr</span><span style="color: #009900;">(</span><span style="color: #990000;">trim</span><span style="color: #009900;">(</span><span style="color: #000088;">$line</span><span style="color: #009900;">)</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;">)</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">';'</span><span style="color: #009900;">)</span>
	<span style="color: #009900;">{</span>
		<span style="color: #666666; font-style: italic;">// Perform the query</span>
		<span style="color: #990000;">mysql_query</span><span style="color: #009900;">(</span><span style="color: #000088;">$templine</span><span style="color: #009900;">)</span> or <span style="color: #990000;">print</span><span style="color: #009900;">(</span><span style="color: #0000ff;">'Error performing query \'</span><span style="color: #339933;">&lt;</span>strong<span style="color: #339933;">&gt;</span><span style="color: #0000ff;">' . $templine . '</span>\<span style="color: #0000ff;">': '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;br /&gt;&lt;br /&gt;'</span><span style="color: #009900;">)</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;">}</span>
<span style="color: #009900;">}</span>

<span style="color: #000000; font-weight: bold;">?&gt;</span></pre>
</div>
</div>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.manugarcia.es/2009/09/05/restaurar-un-mysql-backup-con-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

