<?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>PHP Log &#187; MySQL</title>
	<atom:link href="http://www.php-log.de/tags/mysql/feed" rel="self" type="application/rss+xml" />
	<link>http://www.php-log.de</link>
	<description>Eine feine Sammlung nützlicher PHP Notizen</description>
	<lastBuildDate>Thu, 27 May 2010 04:43:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>CakePHP &#8211; Arbeiten mit zwei Datenbanken</title>
		<link>http://www.php-log.de/505/php/cakephp-arbeiten-mit-zwei-datenbanken</link>
		<comments>http://www.php-log.de/505/php/cakephp-arbeiten-mit-zwei-datenbanken#comments</comments>
		<pubDate>Thu, 18 Mar 2010 14:00:21 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=505</guid>
		<description><![CDATA[Im Prinzip ist es sehr einfach mit zwei Datenbanken zu arbeiten. CakePHP erlaubt ja über die Member Variable $useDbConfig die Konfiguration zu ändern. Dieses Verfahren wird hier ganz schön beschrieben: http://blog.4webby.com/posts/view/6/cakephp_models_using_multiple_db_connections Aaaahber, was ist wenn es keine weitere Konfiguration gibt, weil mit einer flammneuen Datenbank gearbeitet werden soll, die man gerade eben erst selbst erzeugt [...]]]></description>
			<content:encoded><![CDATA[<p>Im Prinzip ist es sehr einfach mit zwei Datenbanken zu arbeiten. CakePHP erlaubt ja über die Member Variable $useDbConfig die Konfiguration zu ändern.</p>
<p><span id="more-505"></span></p>
<p>Dieses Verfahren wird hier ganz schön beschrieben: <a href="http://blog.4webby.com/posts/view/6/cakephp_models_using_multiple_db_connections">http://blog.4webby.com/posts/view/6/cakephp_models_using_multiple_db_connections</a></p>
<p>Aaaahber, was ist wenn es keine weitere Konfiguration gibt, weil mit einer flammneuen Datenbank gearbeitet werden soll, die man gerade eben erst selbst erzeugt hat? In diesem Fall hilft das &#8220;USE&#8221; Statement. Hier ein Bespiel:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// DB Wechseln</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;USE `other_db` ;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Query auf der neuen DB absetzen</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE configuration SET configuration_value = 'foo' WHERE configuration_key =  'bar' ;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Und wieder zurück zur alten DB</span>
<span style="color: #000088;">$current_config</span>    <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDataSource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$original_db</span> 	    <span style="color: #339933;">=</span> <span style="color: #000088;">$current_config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'database'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;USE `<span style="color: #006699; font-weight: bold;">$original_db</span>` ;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/505/php/cakephp-arbeiten-mit-zwei-datenbanken/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend_Date in ein MySQL kompatibles Datum konvertieren</title>
		<link>http://www.php-log.de/378/php/zend_date-in-ein-mysql-kompatibles-datum-konvertieren</link>
		<comments>http://www.php-log.de/378/php/zend_date-in-ein-mysql-kompatibles-datum-konvertieren#comments</comments>
		<pubDate>Tue, 14 Jul 2009 15:58:47 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=378</guid>
		<description><![CDATA[Zend_Date hat für alle erdenklichen Ausgabeformate eine Lösung. Nur für den Einsatz als MySQL Datum nicht. das muss man noch &#8216;händisch&#8217; einrichten. Die Lösung ist natürlich sehr einfach, aber da ich das Zend Framework nur gelegentlich benutze musste ich trotzdem danach googlen. Fündig wurde ich hier: http://www.eatmybusiness.com/food/2009/01/31/how-to-get-zend-date-in-sql-timestamp-format-eg-mysql-yyyy-mm-dd-hhmmss/90/ Hier die vereinfachte Zusammenfassung: $date = new Zend_Date&#40;&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>Zend_Date hat für alle erdenklichen Ausgabeformate eine Lösung. Nur für den Einsatz als MySQL Datum nicht. das muss man noch &#8216;händisch&#8217; einrichten.<span id="more-378"></span></p>
<p>Die Lösung ist natürlich sehr einfach, aber da ich das Zend Framework nur gelegentlich benutze musste ich trotzdem danach googlen. Fündig wurde ich hier: <a href="http://www.eatmybusiness.com/food/2009/01/31/how-to-get-zend-date-in-sql-timestamp-format-eg-mysql-yyyy-mm-dd-hhmmss/90/" target="_blank">http://www.eatmybusiness.com/food/2009/01/31/how-to-get-zend-date-in-sql-timestamp-format-eg-mysql-yyyy-mm-dd-hhmmss/90/</a> </p>
<p>Hier die vereinfachte Zusammenfassung:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$date</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sql_date_pattern</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'yyyy-MM-dd HH:mm:ss'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$date</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql_date_pattern</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Achja, dann gibt es auch noch eine kleine Falle wenn man mit ein Zend_Date Object, mit einem Datum aus einer MySQL DB initialisieren will. Wer das Datum nicht vorher mit <code>strtotime()</code> behandelt kann sich einen gut versteckten Fehler einfangen.:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$day</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;2009-10-11&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Falsch</span>
<span style="color: #000088;">$date</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Date<span style="color: #009900;">&#40;</span><span style="color: #000088;">$day</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$week</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$date</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span>Zend_Date<span style="color: #339933;">::</span><span style="color: #004000;">WEEK</span><span style="color: #009900;">&#41;</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: #666666; font-style: italic;">#-&gt; Nov 10, 2009 12:00:00 AM
</span>
<span style="color: #666666; font-style: italic;">// Richtig</span>
<span style="color: #000088;">$date</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Date<span style="color: #009900;">&#40;</span><span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$day</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$week</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$date</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span>Zend_Date<span style="color: #339933;">::</span><span style="color: #004000;">WEEK</span><span style="color: #009900;">&#41;</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: #666666; font-style: italic;">#-&gt; Oct 11, 2009 12:00:00 AM</span></pre></div></div>

<p>Kurioserweise tritt dieses Phänomen bei mir nur dann auf, wenn ich das Script via CLI auf der Shell aufrufe.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/378/php/zend_date-in-ein-mysql-kompatibles-datum-konvertieren/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP &#8211; SaveField mit MySQL Funktionen wie z.B. Now()</title>
		<link>http://www.php-log.de/328/mysql/cakephp-savefield-mit-mysql-funktionen-wie-zb-now</link>
		<comments>http://www.php-log.de/328/mysql/cakephp-savefield-mit-mysql-funktionen-wie-zb-now#comments</comments>
		<pubDate>Fri, 15 May 2009 10:09:44 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Controller]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=328</guid>
		<description><![CDATA[Dummerweise erlaubt es CakePHP nicht beim aktualisieren eines einzelnen Datenbankfeldes auf MySQL aufzurufen. Eine kurze Rechereche braucht auch keine wirkliche Abhilfe. Das einzige was ich gefunden habe ist ein Hinweis darauf dass schon mal jemand diese Funktion vermisst hat, auch eine Patch möglich ist, dieser aber nicht in die das offizielle Release aufgenommen wird.Einzelheiten dazu [...]]]></description>
			<content:encoded><![CDATA[<p>Dummerweise erlaubt es CakePHP nicht beim aktualisieren eines einzelnen Datenbankfeldes auf MySQL aufzurufen. Eine kurze Rechereche braucht auch keine wirkliche Abhilfe. Das einzige was ich gefunden habe ist ein Hinweis darauf dass schon mal jemand diese Funktion vermisst hat, auch eine Patch möglich ist, dieser aber nicht in die das offizielle Release aufgenommen wird.<span id="more-328"></span>Einzelheiten dazu findet man im Cake <a href="https://trac.cakephp.org/ticket/3341" target="_blank">Ticketsystem</a></p>
<p>Ich mich dazu entschieden meine Datenbank Klasse nicht zu patchen, es reicht ja schon dass ich für eine saubere Ausgabe von Monatsnamen im Core rumstochern muss. Auf eine weitere Ausnahme und Fehlerquelle habe ich keine Lust mehr. Statdessen habe ich mir lieber eine simple Funktion in den Application Controller gelegt.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Im Application Controller</span>
<span style="color: #009933; font-style: italic;">/**
 * creates a date value, suitable for mysql datetime fields
 *
 * @return string
 * @author Ralf Kramer
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> now<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">strftime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%Y-%m-%d %H:%M:%S'</span><span style="color: #339933;">,</span> <span style="color: #990000;">time</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: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Im Controller dann:</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">saveField</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a_datetime_field'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">now</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/328/mysql/cakephp-savefield-mit-mysql-funktionen-wie-zb-now/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
