<?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>tobias.bloggt &#187; agenturgeschichten</title>
	<atom:link href="http://tobias-bloggt.de/category/agenturleben/feed/" rel="self" type="application/rss+xml" />
	<link>http://tobias-bloggt.de</link>
	<description>von weiten reisen, nerdigen skripten und kreativem agenturleben</description>
	<lastBuildDate>Sat, 08 Oct 2011 19:59:40 +0000</lastBuildDate>
	<language>de</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to revise and correct E-Books</title>
		<link>http://tobias-bloggt.de/2009/11/22/how-to-revise-and-correct-e-books/</link>
		<comments>http://tobias-bloggt.de/2009/11/22/how-to-revise-and-correct-e-books/#comments</comments>
		<pubDate>Sun, 22 Nov 2009 12:27:04 +0000</pubDate>
		<dc:creator>Tobias</dc:creator>
				<category><![CDATA[agenturgeschichten]]></category>
		<category><![CDATA[kaum zu glauben]]></category>
		<category><![CDATA[technikkram]]></category>
		<category><![CDATA[Ebook]]></category>
		<category><![CDATA[epub]]></category>
		<category><![CDATA[Fax]]></category>

		<guid isPermaLink="false">http://tobias-bloggt.de/?p=557</guid>
		<description><![CDATA[As a part of my practical term in the past six months, I developed an XML-based workflow for automated E-Book-production. To be honest, we never thought about a revision or correction workflow. But the publishing-houses did! After delivering the produced epub-files to them we received the corrections and annotations via Fax – as shown in [...]]]></description>
			<content:encoded><![CDATA[<p><a rel="lightbox[epub]" href="http://tobias-bloggt.de/wp-content/gallery/blog_bilder/ebook_corrections.jpg"><img class="ngg-singlepic ngg-center alignright" style="float:right;" src="http://tobias-bloggt.de/wp-content/gallery/blog_bilder/thumbs/thumbs_ebook_corrections.jpg" alt="ebook_corrections" width="98" height="131" /></a>As a part of my practical term in the past six months, I developed an XML-based workflow for automated E-Book-production. To be honest, we never thought about a revision or correction workflow. But the publishing-houses did! After delivering the produced epub-files to them we received the corrections and annotations via Fax – as shown in the image on the right side.</p>
<p>D’oh! We developed a really cool high-technology workflow and they put their reading-device on the copier, copied it, made their annotations on the paper and old-school-faxed it back to our office.</p>
<p>Hehe ^^ No comment… <img src='http://tobias-bloggt.de/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<footer>–––––</footer>
<footer>Info: I’m studying printing and media technology and for my practical term I worked at a small publishing service provider, the <a title="pagina GmbH" href="http://www.pagina-online.de" target="_blank">pagina GmbH</a> in Tübingen, Germany. With collegues I developed this really cool XML-EPUB-workflow with integrated automated font-subsetting. Whoever is interested in this issue, feel free to ask me or the guys at pagina…</footer>
]]></content:encoded>
			<wfw:commentRss>http://tobias-bloggt.de/2009/11/22/how-to-revise-and-correct-e-books/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP: Doppelte Zeilenumbr&#252;che in E-Mails</title>
		<link>http://tobias-bloggt.de/2009/08/26/php-doppelte-zeilenumbrueche-in-e-mails/</link>
		<comments>http://tobias-bloggt.de/2009/08/26/php-doppelte-zeilenumbrueche-in-e-mails/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 12:25:14 +0000</pubDate>
		<dc:creator>Tobias</dc:creator>
				<category><![CDATA[agenturgeschichten]]></category>
		<category><![CDATA[technikkram]]></category>
		<category><![CDATA[E-Mail]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Zeilenumbruch]]></category>

		<guid isPermaLink="false">http://tobias-bloggt.de/?p=468</guid>
		<description><![CDATA[E-Mails mit PHP zu versenden geht ja ansich ganz einfach und komfortabel. Interessant wird es jedoch, wenn Textmails mit manuellen Zeilenumbr&#252;chen verschickt werden sollen. Ein Zeilenumbruch wird im Mailtext beispielsweise wie folgt erzeugt: $mailtext = &#34;Ich bin ein Absatz.\n&#34;; $mailtext.= &#34;Und ich auch!&#34;; Damit die Steuerzeichen \n, \r oder \t interpretiert werden m&#252;ssen sie in [...]]]></description>
			<content:encoded><![CDATA[<p>E-Mails mit PHP zu versenden geht ja ansich ganz einfach und komfortabel. Interessant wird es jedoch, wenn Textmails mit manuellen Zeilenumbrüchen verschickt werden sollen.</p>
<p>Ein Zeilenumbruch wird im Mailtext beispielsweise wie folgt erzeugt:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$mailtext</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Ich bin ein Absatz.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mailtext</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Und ich auch!&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Damit die Steuerzeichen <code>\n</code>, <code>\r</code> oder <code>\t</code> interpretiert werden müssen sie in doppelten Anführungszeichen stehen! Einfache Anführungszeichen im obigen Beispiel würden bewirken, dass das abschließende <code>\n</code> im E-Mail-Text ausgegeben wird.</p>
<p>Soll nun Text aus einer MySQL-Datenbank in die E-Mail fließen, und wurde dieser Text zuvor über ein <code>HTML-&lt;textarea></code>–Feld in der Datenbank gespeichert, werden plötzlich alle Datenbankinhalte mit doppelten Zeilenumbrüchen in der E-Mail dargestellt.</p>
<p>Grund dafür ist die Form des Zeilenumbruchs der beim Speichern in die Datenbank geschrieben wird. Und das ist bei der Übergabe des <code>HTML-&lt;textarea></code>–Feldes ein sogenannter „Windows-Zeilenumbruch“ im Format <code>\r\n</code>. Normalerweise interpretieren die meisten Programme diese Umbruchs-Kombination (<em>Carriage-Return + NewLine</em>) als einen zusammenhängenden Umbruch, die gängigen E-Mail-Clients hingegen interpretieren <code>\r\n</code> als doppelten Zeilenumbruch. Auch unter Windows.</p>
<p>Um diese Missinterpretation zu umgehen sollte vor Versand der E-Mail der komplette E-Mail-Text nach dieser Zeichenkombination durchsucht werden. Am einfachsten geht dies mit einem Regulären Ausdruck der alle Vorkomnisse von <code>\r\n</code> durch <code>\n</code> ersetzt.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$mailtext</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Ich bin ein Absatz.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mailtext</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Und ich auch! Nach mir kommt Datenbankinhalt.&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mailtext</span><span style="color: #339933;">.=</span> <span style="color: #000088;">$datenbankinhalt</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$mailtext</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;%<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>%&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mailtext</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://tobias-bloggt.de/2009/08/26/php-doppelte-zeilenumbrueche-in-e-mails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MediaWiki: Fehler beim Upload von epub-Dateien beheben</title>
		<link>http://tobias-bloggt.de/2009/08/25/mediawiki-fehler-beim-upload-von-epub-dateien-beheben/</link>
		<comments>http://tobias-bloggt.de/2009/08/25/mediawiki-fehler-beim-upload-von-epub-dateien-beheben/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 14:21:53 +0000</pubDate>
		<dc:creator>Tobias</dc:creator>
				<category><![CDATA[agenturgeschichten]]></category>
		<category><![CDATA[technikkram]]></category>
		<category><![CDATA[E-Book]]></category>
		<category><![CDATA[epub]]></category>
		<category><![CDATA[mediawiki]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://tobias-bloggt.de/?p=464</guid>
		<description><![CDATA[Vor einigen Monaten habe ich eine L&#246;sung zum Upload von docx– und xslx-Dateien in Mediawiki-Wiki’s gepostet. Inzwischen ist das E-Book in aller Munde, und nat&#252;rlich soll man auch frei verf&#252;gbare E-Books im Wiki hochladen d&#252;rfen. Doch auch hier wird der MimeType wieder nicht richtig erkannt. file -bi unter Linux liefert f&#252;r ein E-Book im popul&#228;ren [...]]]></description>
			<content:encoded><![CDATA[<p>Vor einigen Monaten habe ich eine <a href="http://tobias-bloggt.de/2009/04/13/mediawiki-fehler-beim-upload-von-docx-und-xlsx-dateien-beheben/" target="_self">Lösung zum Upload von docx– und xslx-Dateien in Mediawiki-Wiki’s</a> gepostet.</p>
<p>Inzwischen ist das E-Book in aller Munde, und natürlich soll man auch frei verfügbare E-Books im Wiki hochladen dürfen. Doch auch hier wird der MimeType wieder nicht richtig erkannt.</p>
<p><code>file -bi</code> unter Linux liefert für ein E-Book im populären „EPUB“-Format den MimeType <code>application/x-zip</code>, PHP interpretiert jedoch als <code>application/zip</code>. Ganz richtig wäre übrigens <code>application/epub+zip</code>.</p>
<p>Um den EPUB-Upload zu gestatten muss also die Extension <code>epub</code> dem Array <code>$wgFileExtensions</code> in der <code>LocalConfig.php</code> hinzugefügt werden. Danach muss noch die Datei <code>mime.types</code> im Ordner <code>/includes</code> angepasst werden. Dazu muss lediglich die Zeile <code>application/zip [...]</code> um den Eintrag <code>epub</code> erweitert werden.</p>
]]></content:encoded>
			<wfw:commentRss>http://tobias-bloggt.de/2009/08/25/mediawiki-fehler-beim-upload-von-epub-dateien-beheben/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Die wichtigsten CSS-Selektoren</title>
		<link>http://tobias-bloggt.de/2009/05/13/die-wichtigsten-css-selektoren/</link>
		<comments>http://tobias-bloggt.de/2009/05/13/die-wichtigsten-css-selektoren/#comments</comments>
		<pubDate>Wed, 13 May 2009 09:32:36 +0000</pubDate>
		<dc:creator>Tobias</dc:creator>
				<category><![CDATA[agenturgeschichten]]></category>
		<category><![CDATA[technikkram]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Selektoren]]></category>
		<category><![CDATA[Webdesign]]></category>

		<guid isPermaLink="false">http://tobias-bloggt.de/?p=387</guid>
		<description><![CDATA[Wer viel mit CSS arbeitet und („krasse“) tabellenfreie Web-Layouts erstellt, der wird nicht drumherum kommen, sich mit den CSS-Selektoren zu besch&#228;ftigen. Inzwischen bin ich etwas XPATH–verw&#246;hnt was Selektoren angeht, denn mit self, child, parent, descendant, descendant-or-self, ancestor, ancestor-or-self, preceding, following, preceding-sibling und following-sibling hat man dort alle, und damit meine ich wirklich ALLE, M&#246;glichkeiten im [...]]]></description>
			<content:encoded><![CDATA[<p>Wer viel mit CSS arbeitet und („krasse“) tabellenfreie Web-Layouts erstellt, der wird nicht drumherum kommen, sich mit den CSS-Selektoren zu beschäftigen.<br />
Inzwischen bin ich etwas <a href="http://de.wikipedia.org/wiki/XPath" target="_blank">XPATH</a>–verwöhnt was Selektoren angeht, denn mit <code>self</code>, <code>child</code>, <code>parent</code>, <code>descendant</code>, <code>descendant-or-self</code>, <code>ancestor</code>, <code>ancestor-or-self</code>, <code>preceding</code>, <code>following</code>, <code>preceding-sibling</code> und <code>following-sibling</code> hat man dort alle, und damit meine ich wirklich ALLE, Möglichkeiten im XML-(Struktur-)Baum zu navigieren und Elemente zu selektieren.</p>
<p>Die Möglichkeiten in CSS sind dagegen eher bescheiden. Hier eine kurze Übersicht über die wichtigsten CSS-Selektoren:</p>
<blockquote>
<ul>
<li><code>klasse klasse2</code><br />
Selektiert klasse2 die sich *irgendwo* innerhalb von klasse befindet.<br />
Beispiel:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;klasse&quot;&gt;
  &lt;span class=&quot;klasse2&quot;&gt;Dieser SPAN wird selektiert.
    &lt;p class=&quot;klasse2&quot;&gt;Dieser Absatz wird selektiert.&lt;/p&gt;
  &lt;/span&gt;
&lt;/div&gt;</pre></div></div>

</li>
<li><code>klasse<span style="color:red;">&gt;</span>klasse2</code><br />
Selektiert klasse2, wenn sich diese genau EINE Ebene unterhalb von klasse befindet.<br />
Beispiel:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;klasse&quot;&gt;
  &lt;span class=&quot;klasse2&quot;&gt;Dieser SPAN wird selektiert!
    &lt;p class=&quot;klasse2&quot;&gt;Dieser Absatz wird NICHT selektiert.&lt;/p&gt;
  &lt;/span&gt;
&lt;/div&gt;</pre></div></div>

</li>
<li><code>klasse<span style="color:red;">*</span>klasse2</code><br />
Selektiert klasse2, wenn sich diese genau ZWEI Ebenen unterhalb von klasse befindet.<br />
Beispiel:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;klasse&quot;&gt;
  &lt;span class=&quot;klasse2&quot;&gt;Dieser SPAN wird NICHT selektiert.
    &lt;p class=&quot;klasse2&quot;&gt;Dieser Absatz wird selektiert.&lt;/p&gt;
  &lt;/span&gt;
&lt;/div&gt;</pre></div></div>

</li>
<li><code>klasse<span style="color:red;">+</span>klasse2</code><br />
Selektiert klasse2, wenn sich diese direkt NACH klasse befindet.<br />
Beispiel:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;klasse&quot;&gt;
  &lt;span class=&quot;klasse2&quot;&gt;Dieser SPAN wird NICHT selektiert.&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;klasse2&quot;&gt;
  Dafür wird dieses DIV selektiert.
&lt;/div&gt;</pre></div></div>

</li>
</ul>
</blockquote>
<p>Was ich mir für CSS wirklich wünsche, ist ein parent-Selektor. Der würde viel Arbeit abnehmen! Ist aber in CSS3 leider nicht vorgesehen und bis CSS4 rauskommt könnten noch ein paar Jährchen vergehen. Schade…</p>
<p><em>CSS 4 You</em> bietet auf <a href="http://www.css4you.de/wscss/css03.html" target="_blank">zwei</a> <a href="http://www.css4you.de/wscss/css04.html" target="_blank">Seiten</a> noch weitere Infos zum Umgang mit Selektoren.</p>
]]></content:encoded>
			<wfw:commentRss>http://tobias-bloggt.de/2009/05/13/die-wichtigsten-css-selektoren/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP-Alternative zu mod_rewrite-Weiterleitung</title>
		<link>http://tobias-bloggt.de/2009/04/25/php-alternative-zu-mod_rewrite-weiterleitung/</link>
		<comments>http://tobias-bloggt.de/2009/04/25/php-alternative-zu-mod_rewrite-weiterleitung/#comments</comments>
		<pubDate>Sat, 25 Apr 2009 08:30:56 +0000</pubDate>
		<dc:creator>Tobias</dc:creator>
				<category><![CDATA[agenturgeschichten]]></category>
		<category><![CDATA[technikkram]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[weiterleitung]]></category>

		<guid isPermaLink="false">http://tobias-bloggt.de/?p=363</guid>
		<description><![CDATA[Wir nehmen folgenden Fall an: Es soll eine permanente Weiterleitung erfolgen von der alten URL http://www.domain.de/wiki/ nach http://wiki.domain.de/. Alle angeforderten Seiten und Verzeichnisse (beispielsweise index.php?title=Hauptseite) sollen ebenfalls weitergeleitet werden. Am effektivsten w&#228;re hier eine Weiterleitung mittels mod_rewrite, f&#252;r Anf&#228;nger jedoch nicht ohne weiteres zu implementieren, und auch nur dann m&#246;glich, wenn der Webserver, sprich Apache [...]]]></description>
			<content:encoded><![CDATA[<p>Wir nehmen folgenden Fall an:</p>
<p>Es soll eine permanente Weiterleitung erfolgen von der alten URL <code>http://www.domain.de/wiki/</code> nach <code>http://wiki.domain.de/</code>. Alle angeforderten Seiten und Verzeichnisse (beispielsweise <code>index.php?title=Hauptseite</code>) sollen ebenfalls weitergeleitet werden.</p>
<p>Am effektivsten wäre hier eine Weiterleitung mittels mod_rewrite, für Anfänger jedoch nicht ohne weiteres zu implementieren, und auch nur dann möglich, wenn der Webserver, sprich Apache dies erlaubt.</p>
<p>Eine Alternative dazu stellt das folgende kleine PHP-Script dar:</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>
<span style="color: #009933; font-style: italic;">/**
 * Permanente Weiterleitung
 * @author Tobias Fischer / tobias (at) mediaversal (punkt) de
 * @date 2009-04-24
 */</span>
&nbsp;
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$PHP_SELF</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'?'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$QUERY_STRING</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/wiki'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Status: 301 Moved Permanently&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: http://wiki.domain.de&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><code>$PHP_SELF</code> gibt das Verzeichnis und die aufgerufene Datei ab Domainebene zurück, in unserem Fall also <code>/wiki/index.php</code>. <code>$QUERY_STRING</code> liefert alle angehängten Variablen „nach dem Fragezeichen“.<br />
Nun müssen wir diese beiden Fragmente nur noch zusammensetzen, daraus das aktuelle Arbeitsverzeichnis <code>/wiki</code> entfernen und an die neue URL  <code>http://wiki.domain.de/</code> anhängen.</p>
<p>Die Statusmeldung <code>301</code> teilt dem Browser oder auch eventuellen Suchmaschinen mit, dass die angeforderte Seite permanent umgezogen ist – <code>302</code> dagegen würde temporär umleiten.</p>
]]></content:encoded>
			<wfw:commentRss>http://tobias-bloggt.de/2009/04/25/php-alternative-zu-mod_rewrite-weiterleitung/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL: Dubletten finden und l&#246;schen</title>
		<link>http://tobias-bloggt.de/2009/04/15/mysql-dubletten-finden-und-loeschen/</link>
		<comments>http://tobias-bloggt.de/2009/04/15/mysql-dubletten-finden-und-loeschen/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 08:00:08 +0000</pubDate>
		<dc:creator>Tobias</dc:creator>
				<category><![CDATA[agenturgeschichten]]></category>
		<category><![CDATA[technikkram]]></category>
		<category><![CDATA[doppelt]]></category>
		<category><![CDATA[dubletten]]></category>
		<category><![CDATA[löschen]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://tobias-bloggt.de/?p=332</guid>
		<description><![CDATA[Folgendes Szenario: Ein Datenbanktabelle enth&#228;lt alle Bankleitzahlen Deutschlands inklusive der Kurzbezeichnung der Bank. 20.107 Datens&#228;tze (Stand 04/2009). Allerdings enth&#228;lt die Datenbank viele doppelte Datens&#228;tze die gel&#246;scht werden sollen um Platz zu sparen. CREATE TABLE IF NOT EXISTS `bankcode` &#40; `ID` SMALLINT&#40;5&#41; UNSIGNED NOT NULL AUTO_INCREMENT, `Bankleitzahl` VARCHAR&#40;8&#41; NOT NULL, `Kurzbezeichnung` VARCHAR&#40;50&#41; NOT NULL, PRIMARY KEY [...]]]></description>
			<content:encoded><![CDATA[<p>Folgendes Szenario: Ein Datenbanktabelle enthält alle Bankleitzahlen Deutschlands inklusive der Kurzbezeichnung der Bank. 20.107 Datensätze <em>(Stand 04/2009)</em>. Allerdings enthält die Datenbank viele doppelte Datensätze die gelöscht werden sollen um Platz zu sparen.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> <span style="color: #ff0000;">`bankcode`</span> <span style="color: #66cc66;">&#40;</span>
<span style="color: #ff0000;">`ID`</span> <span style="color: #993333; font-weight: bold;">SMALLINT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">`Bankleitzahl`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">`Kurzbezeichnung`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span>  <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`ID`</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
<span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #ff0000;">`Bankleitzahl`</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`Bankleitzahl`</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>InnoDB  <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET<span style="color: #66cc66;">=</span>utf8 ROW_FORMAT<span style="color: #66cc66;">=</span>COMPACT COMMENT<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'Bankleitzahlen'</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">20108</span>;</pre></div></div>

<p><small><strong>Code:</strong> SQL-Tabellenstruktur</small></p>
<p>Eine reine SQL-Möglichkeit, Dubletten zu finden und zu löschen habe ich nicht herausgefunden, deshalb habe ich mir ein kurzes php-Script dazu geschrieben.<br /><em>Anmerkung: Bei 20.000 Datenbankeinträgen musste ich dazu jedoch die <code>max_execution_time</code> in der <code>php.ini</code> von 60 (Sekunden) auf 320 erhöhen. Ob dies bei einem Produktivsystem sinnvoll ist, sei dahingestellt, das Script lief bei mir lokal auf dem Rechner und ich habe die Änderung somit für gut heißen können.</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>
<span style="color: #009933; font-style: italic;">/**
 * Dubletten finden und löschen
 * @author Tobias Fischer / tobias (at) mediaversal (punkt) de
 * @date 2009-04-12
 */</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Datenbankverbindung aufbauen</span>
<span style="color: #666666; font-style: italic;">/*
...
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Anzahl der Datensätze auslesen und ausgeben</span>
<span style="color: #000088;">$result</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 `ID` FROM `bankcode`;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$datensaetze</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Datensätze: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$anzahl</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br /&gt;&lt;br /&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Arrays erstellen die in den for-Schleifen verwendet werden</span>
<span style="color: #000088;">$dubletten_ids</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//zählt die Dubletten eines Datensatzes</span>
<span style="color: #000088;">$overall_ids</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// zählt die Gesamtanzahl der Dubletten</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Erste Schleife - durchläuft jeden der 20.000 Datensätze einzeln</span>
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span> <span style="color: #000088;">$datensaetze</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span> <span style="color: #000088;">$overall_ids</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$fid</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">,</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$result2</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 * FROM `bankcode` WHERE `ID` = &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$fid</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$k</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000088;">$k</span><span style="color: #339933;">&lt;</span>mysql_num_rows<span style="color: #009900;">&#40;</span><span style="color: #000088;">$result2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000088;">$k</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$bcid</span> <span style="color: #339933;">=</span>  <span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result2</span><span style="color: #339933;">,</span><span style="color: #000088;">$k</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$blz</span> <span style="color: #339933;">=</span>  <span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result2</span><span style="color: #339933;">,</span><span style="color: #000088;">$k</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: #000088;">$kurz</span> <span style="color: #339933;">=</span>  <span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result2</span><span style="color: #339933;">,</span><span style="color: #000088;">$k</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// Sucht nach Datensätzen mit gleicher BLZ und gleicher Kurzbezeichnung</span>
      <span style="color: #666666; font-style: italic;">// AND `ID` &lt;&gt; '&quot;.$bcid.&quot;' schließt den aktuellen Datensatz aus</span>
      <span style="color: #000088;">$result3</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 `ID` FROM `bankcode` WHERE `Bankleitzahl` = '&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$blz</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;' AND `Kurzbezeichnung` = '&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$kurz</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;' AND `ID` &lt;&gt; '&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$bcid</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;';&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// Mache weiter falls Dubletten vorhanden sind</span>
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result3</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Durchläuft die Ergebnismenge und speichert alle ID's der gefundenen Dubletten </span>
        <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$m</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000088;">$m</span><span style="color: #339933;">&lt;</span>mysql_num_rows <span style="color: #009900;">&#40;</span><span style="color: #000088;">$result3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000088;">$m</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$dubletten_ids</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$bcid</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$m</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result3</span><span style="color: #339933;">,</span><span style="color: #000088;">$m</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'BLZ &quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$blz</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; und Kurzbez. &quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$kurz</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; (ID: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$bcid</span><span style="color: #339933;">.</span><span style="color: #0000ff;">') kommen unter folgenden IDs nochmals vor:'</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;br /&gt;&amp;nbsp;&amp;nbsp;'</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Aktuelles Dubletten-ID-Array nochmals durchlaufen und </span>
        <span style="color: #666666; font-style: italic;">// a) ID's ausgeben</span>
        <span style="color: #666666; font-style: italic;">// b) jede ID im Array $overall_ids speichern</span>
        <span style="color: #666666; font-style: italic;">//     dies hat den Zweck, dass Datensätze mit dieser ID in der ersten Schleife übersprungen werden</span>
        <span style="color: #666666; font-style: italic;">//     da sonst eine Dopplung vorliegen würde</span>
        <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">each</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dubletten_ids</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$bcid</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$overall_ids</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
&nbsp;
          <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;span '</span><span style="color: #339933;">;</span>
&nbsp;
          <span style="color: #666666; font-style: italic;">// Um die Dubletten sofort zu löschen, folgende Zeilen einkommentieren</span>
          <span style="color: #666666; font-style: italic;">/*
            $delete = mysql_query(&quot;DELETE FROM `bankcode` WHERE `ID` = &quot; . $value . &quot; LIMIT 1;&quot;);
            if($delete) {
              echo ' style=&quot;color:green;&quot;';
            } else {
              echo ' style=&quot;color:red;&quot;';
            }
          */</span>
&nbsp;
          <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&gt;'</span><span style="color: #339933;">;</span>
          <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
          <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">',&lt;/span&gt; '</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Frühzeitige Übergabe an den Browser</span>
        <span style="color: #990000;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Gesamtanzahl aller Dubletten</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$overall_ids</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><small><strong>Code:</strong> PHP-Code-Snippet</small></p>
<p>Ich konnte damit ca. 12.000 Dubletten aus der BLZ-Tabelle löschen und die Datenmenge somit um mehr als 50 % reduzieren.</p>
<p><strong>Für den Einsatz in einem anderen Datenbank– und Projektumfeld müssen die Datenbankabfragen, die HTML-Textausgaben und eventuell auch einige Variablen angepasst bzw. umbenannt werden!</strong></p>
<p><strong>Ich übernehme keine Gewähr für die Richtigkeit des Skripts und hafte somit auch nicht für eventuell entstandene Schäden durch falschen Einsatz auf Dritt– oder Produktivsystemen!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://tobias-bloggt.de/2009/04/15/mysql-dubletten-finden-und-loeschen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

