<?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>alexyz &#187; MySQL</title>
	<atom:link href="http://alexyz.com/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://alexyz.com</link>
	<description>developer notes</description>
	<lastBuildDate>Tue, 13 Dec 2011 19:09:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>MYSQL Query clear all data in a column</title>
		<link>http://alexyz.com/mysql-query-clear-all-data-in-a-column/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql-query-clear-all-data-in-a-column</link>
		<comments>http://alexyz.com/mysql-query-clear-all-data-in-a-column/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 19:09:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[phpMyAdmin]]></category>
		<category><![CDATA[all]]></category>
		<category><![CDATA[clear]]></category>
		<category><![CDATA[column]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[erase]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://alexyz.com/?p=1420</guid>
		<description><![CDATA[UPDATE table SET column = &#8221; example: UPDATE wp_posts SET post_excerpt = &#8221;]]></description>
			<content:encoded><![CDATA[<p>UPDATE <strong>table</strong> SET <strong>column</strong> = &#8221;</p>
<p>example:</p>
<p>UPDATE <strong>wp_posts</strong> SET <strong>post_excerpt</strong> = &#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://alexyz.com/mysql-query-clear-all-data-in-a-column/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress creating users in MySQL via script wp_user_level wp_capabilities wp_users</title>
		<link>http://alexyz.com/wordpress-creating-users-in-mysql-via-script-wp_user_level-wp_capabilities-wp_users/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wordpress-creating-users-in-mysql-via-script-wp_user_level-wp_capabilities-wp_users</link>
		<comments>http://alexyz.com/wordpress-creating-users-in-mysql-via-script-wp_user_level-wp_capabilities-wp_users/#comments</comments>
		<pubDate>Mon, 03 Jan 2011 22:16:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://alexyz.com/?p=1000</guid>
		<description><![CDATA[Scenario: Creating a WordPress blog with an entire company of users. We want employees to already have an account, so that registration may be turned OFF otherwise. From an excel list of employees, we&#8217;ll extract their email, make an account for each email in the WordPress database, and then they may change their passwords themselves. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Scenario:</strong><br />
Creating a WordPress blog with an entire company of users.<br />
We want employees to already have an account, so that registration may be turned OFF otherwise.<br />
From an excel list of employees, we&#8217;ll extract their email, make an account for each email in the WordPress database, and then they may change their passwords themselves.  You can imagine what the php script will look like, to extract the email, and foreach insert the following (uniqueusername and 5 replaced of course with incrementing id numbers and changing emailnames@ourcompany.com):</p>
<p>&nbsp;</p>
<p><span style="color: #008000;">INSERT INTO wp_users<br />
(id,user_login,user_pass,user_email,display_name)<br />
VALUES<br />
(&#8217;5&#8242;,&#8217;uniqueusername&#8217;,md5(&#8216;pass&#8217;),&#8217;uniqueusername@ourcompany.com&#8217;,'uniqueusername&#8217;);</span></p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;">// to note, this below is simultaneously a nice example of how to insert multiple rows with one MySQL INSERT statement</span></p>
<p>&nbsp;</p>
<p><span style="color: #008000;">INSERT INTO wp_usermeta<br />
(user_id,meta_key,meta_value)<br />
VALUES<br />
(&#8217;5&#8242;,&#8217;wp_capabilities&#8217;,'a:1:{s:6:&#8221;author&#8221;;s:1:&#8221;1&#8243;;}&#8217;),<br />
(&#8217;5&#8242;,&#8217;wp_user_level&#8217;,&#8217;10&#8242;);</span></p>
<p>&nbsp;</p>
<p><strong>Thus, the full script looks something like this:</strong></p>
<p>&nbsp;</p>
<p>$employees = array(&#8216;employee1@somesite.com&#8217;,'employee2@somesite.com&#8217;,'employee3@somesite.com&#8217;,'andsoon&#8230;&#8217;);</p>
<p>&nbsp;</p>
<p>$startNumber = 10; <span style="color: #ff0000;">// if you already have users, pick the next highest number, as it uses this for several tables below, we need them to happen at the same time so that attributes belong to specific users&#8230;</span></p>
<p>&nbsp;</p>
<p>$db_name = &#8220;databasename&#8221;;<br />
$db_host = &#8220;localhost&#8221;;<br />
$db_username = &#8220;username&#8221;;<br />
$db_password = &#8220;password&#8221;;</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;">// note the nice error reporting so that we can troubleshoot connections, users, table selections, and so forth&#8230;</span><br />
$link = <span style="color: #ff0000;">mysql_connect</span>($db_host, $db_username, $db_password);<br />
if (!$link) {<br />
die(&#8216;Could not connect: &#8216; . mysql_error());<br />
}<br />
else<br />
{<br />
echo &#8216;Connected successfully&lt;br /&gt;&#8217;;<br />
}</p>
<p>&nbsp;</p>
<p>$db_selected = <span style="color: #ff0000;">mysql_select_db</span>($db_name, $link);<br />
if (!$db_selected) {<br />
die (&#8216;Can\&#8217;t use foo : &#8216; . <span style="color: #ff0000;">mysql_error()</span>);<br />
}<br />
else<br />
{<br />
echo &#8216;Selected manyvoices database successfully&lt;br /&gt;&#8217;;<br />
}</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;">foreach</span>($employees as $employee)<br />
{<br />
list($user_name, $therest) = <span style="color: #ff0000;">explode</span>(&#8216;@&#8217;,$employee);</p>
<p>&nbsp;</p>
<p>$query1 = &#8220;<span style="color: #ff0000;">INSERT INTO wp_users<br />
(id,user_login,user_pass,user_email,display_name)<br />
VALUES<br />
(&#8216;&#8221; . $startNumber . &#8220;&#8216;,&#8217;&#8221; . $user_name . &#8220;&#8216;,md5(&#8216;pass&#8217;),&#8217;&#8221; . $employee . &#8220;&#8216;,&#8217;&#8221; . $user_name . &#8220;&#8216;)</span>&#8220;;<br />
//echo $query1 . &#8220;&lt;br /&gt;&#8221;;</p>
<p>&nbsp;</p>
<p>$result1 = <span style="color: #ff0000;">mysql_query</span>($query1);<br />
if(!result1){<br />
die(&#8216;Error: &#8216; . <span style="color: #ff0000;">mysql_error()</span>);<br />
}<br />
else{<br />
echo &#8220;User: &#8221; . $user_name . &#8221; : Added&lt;br /&gt;&#8221;;<br />
}</p>
<p>&nbsp;</p>
<p>$query2 = &#8220;<span style="color: #ff0000;">INSERT INTO wp_usermeta<br />
(user_id,meta_key,meta_value)<br />
VALUES<br />
(&#8216;&#8221; . $startNumber . &#8220;&#8216;,&#8217;wp_capabilities&#8217;,'a:1:{s:6:\&#8221;author\&#8221;;s:1:\&#8221;1\&#8221;;}&#8217;),<br />
(&#8216;&#8221; . $startNumber . &#8220;&#8216;,&#8217;wp_user_level&#8217;,&#8217;10&#8242;)</span>&#8220;;<br />
//echo $query2 . &#8220;&lt;br /&gt;&#8221;;</p>
<p>&nbsp;</p>
<p>$result2 = <span style="color: #ff0000;">mysql_query</span>($query2);<br />
if(!result2){<br />
die(&#8216;Error: &#8216; . <span style="color: #ff0000;">mysql_error()</span>);<br />
}<br />
else<br />
{<br />
echo &#8220;User Credentials: &#8221; . $user_name . &#8221; : Updated&lt;br /&gt;&#8221;;<br />
}</p>
<p>&nbsp;</p>
<p>$startNumber++;<br />
}</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;">mysql_close</span>($link);</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://alexyz.com/wordpress-creating-users-in-mysql-via-script-wp_user_level-wp_capabilities-wp_users/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL optimization refresher notes</title>
		<link>http://alexyz.com/mysql-optimization-refresher-notes/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql-optimization-refresher-notes</link>
		<comments>http://alexyz.com/mysql-optimization-refresher-notes/#comments</comments>
		<pubDate>Wed, 17 Nov 2010 18:48:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://alexyz.com/?p=712</guid>
		<description><![CDATA[reference: http://www.databasejournal.com/features/mysql/article.php/10897_1382791_1/Optimizing-MySQL-Queries-and-Indexes.htm Notes from above reference: place EXPLAIN before your SELECT and learn a lot! index index index&#8230; in query, if possible, leave indexed field (usually after WHERE&#8230;) alone, or else every record must be calculated prior to conditional analysis&#8230; ANALYZE TABLE tablename; OPTIMIZE TABLE tablename [quote block] EXPLAIN SELECT employee_number,firstname,surname FROM employee WHERE employee_number= [...]]]></description>
			<content:encoded><![CDATA[<p>reference: <a href="http://www.databasejournal.com/features/mysql/article.php/10897_1382791_1/Optimizing-MySQL-Queries-and-Indexes.htm">http://www.databasejournal.com/features/mysql/article.php/10897_1382791_1/Optimizing-MySQL-Queries-and-Indexes.htm</a></p>
<p>Notes from above reference:</p>
<ul>
<li>place EXPLAIN before your SELECT and learn a lot!</li>
<li>index index index&#8230;</li>
<li>in query, if possible, leave indexed field (usually after WHERE&#8230;) alone, or else every record must be calculated prior to conditional analysis&#8230;</li>
<li><code>ANALYZE TABLE tablename;</code></li>
<li><code>OPTIMIZE TABLE tablename </code></li>
</ul>
<pre><code>[quote block]

EXPLAIN SELECT employee_number,firstname,surname
FROM employee
WHERE employee_number= '10875';
</code></pre>
<pre>+--------+----+-------------+----+-------+----+---+---------+
|table   |type|possible_keys|key |key_len|ref |rows| Extra  |
+--------+----+-------------+----+-------+----+---+---------+
|employee|ALL |NULL         |NULL|   NULL|NULL|  2|whereused|
+--------+----+-------------+----+-------+----+---+---------+
</pre>
<p>So what are all these things?</p>
<ul>
<li><em>table</em> shows us which table the output is about (for when you join many tables in the query)</li>
<li><em>type</em> is an important one &#8211; it tells us which type of  join is being used. From best to worst the types are: system, const,  eq_ref, ref, range, index, all</li>
<li><em>possible_keys</em> Shows which possible indexes apply to this table</li>
<li><em>key</em> And which one is actually used</li>
<li><em>key_len</em> give us the length of the key used. The shorter that better.</li>
<li><em>ref</em> Tells us which column, or a constant, is used</li>
<li><em>rows</em> Number of rows mysql believes it must examine to get the data</li>
<li><em>extra</em> Extra info &#8211; the bad ones to see here are &#8220;using temporary&#8221; and &#8220;using filesort&#8221;</li>
</ul>
<p>[quote block end]</p>
]]></content:encoded>
			<wfw:commentRss>http://alexyz.com/mysql-optimization-refresher-notes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>framework.zend.com &#8220;Create a Model and Database Table&#8221; tutorial fixed, full working code, adapted for MySQL</title>
		<link>http://alexyz.com/framework-zend-com-create-a-model-and-database-table-tutorial-fixed-full-working-code-adapted-for-mysql/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=framework-zend-com-create-a-model-and-database-table-tutorial-fixed-full-working-code-adapted-for-mysql</link>
		<comments>http://alexyz.com/framework-zend-com-create-a-model-and-database-table-tutorial-fixed-full-working-code-adapted-for-mysql/#comments</comments>
		<pubDate>Mon, 20 Sep 2010 18:02:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend]]></category>

		<guid isPermaLink="false">http://alexyz.com/?p=539</guid>
		<description><![CDATA[http://framework.zend.com/manual/1.10/en/learning.quickstart.create-model.html Well, I agonized over getting this, and if you read the comments on the tutorial, many others have as well, working on my home Snow Leopard as well as on my work XP pc, and I spent countless hours looking for a post just such as this one is now, to no avail, so [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://framework.zend.com/manual/1.10/en/learning.quickstart.create-model.html">http://framework.zend.com/manual/1.10/en/learning.quickstart.create-model.html</a></p>
<p>Well, I agonized over getting this, and if you read the comments on the tutorial, many others have as well, working on my home Snow Leopard as well as on my work XP pc, and I spent countless hours looking for a post just such as this one is now, to no avail, so here it all is, hope it helps somebody:</p>
<p><strong>hosts</strong></p>
<p>In the event that you don&#8217;t have this done already, here is what should go in your environment&#8217;s hosts file&#8230;</p>
<p>Mac: <span style="color: #800000;">/private/etc/hosts<br />
</span></p>
<p>PC:  <span style="color: #800000;">C:\WINDOWS\system32\drivers\etc</span></p>
<p># Setup &#8220;components&#8221; Virtual Host<br />
&lt;VirtualHost *:80&gt;<br />
ServerName <span style="color: #000000;"><strong>project</strong></span><br />
DocumentRoot &#8220;<span style="color: #800000;">C:\xampp\htdocs\<span style="color: #000000;">project</span>\public</span>&#8221; <span style="color: #800000;">// <strong><span style="color: #000000;">or</span></strong> /Library/WebServer/Documents/<span style="color: #000000;">project</span>/public</span></p>
<p>&lt;Directory &#8220;<span style="color: #800000;">C:\xampp\htdocs\<span style="color: #000000;">project</span>\public</span>&#8221; // <strong>or</strong> <span style="color: #800000;">/Library/WebServer/Documents/<span style="color: #000000;">project</span>/public</span>&gt;<br />
Options Indexes FollowSymLinks Includes<br />
AllowOverride All<br />
Order allow,deny<br />
Allow from all<br />
&lt;/Directory&gt;<br />
&lt;/VirtualHost&gt;</p>
<p><span style="color: #000000;"><strong>create the database that this will use</strong></span></p>
<p><span style="color: #800000;">CREATE TABLE IF NOT EXISTS `guestbook` (<br />
`id` int(11) NOT NULL AUTO_INCREMENT,<br />
`email` varchar(32) DEFAULT NULL,<br />
`comment` text,<br />
`created` datetime DEFAULT NULL,<br />
PRIMARY KEY (`id`)<br />
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;</span></p>
<p><span style="color: #000000;"><strong>add dummy data to the database</strong></span></p>
<p><span style="color: #800000;">INSERT INTO `guestbook` (`id`, `email`, `comment`, `created`) VALUES<br />
(1, &#8216;ralph@schindler.com&#8217;, &#8216;hello&#8217;, &#8217;2010-09-17 00:00:00&#8242;),<br />
(2, &#8216;foo@bar.com&#8217;, &#8216;goodbye&#8217;, &#8217;2010-09-17 00:00:00&#8242;);</span></p>
<p><strong>if you haven&#8217;t done so already, create the user this app will use to connect, and give the user the priviledges they&#8217;ll need</strong></p>
<p><span style="color: #800000;">CREATE USER &#8216;guestbook&#8217;@'localhost&#8217; IDENTIFIED BY &#8216;guestbook&#8217;;</span></p>
<p><span style="color: #800000;">GRANT ALL ON &#8216;guestbook&#8217; TO &#8216;guestbook&#8217;@'localhost&#8217;;</span></p>
<p><strong><span style="color: #000000;">project/application/Bootstrap.php</span></strong></p>
<p><span style="color: #800000;"><span style="color: #ff0000;">&lt;?php</span><br />
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap<br />
{<br />
public function _initAutoloader()<br />
{<br />
// Create an resource autoloader component<br />
$autoloader = new Zend_Loader_Autoloader_Resource(array(<br />
&#8216;basePath&#8217;    =&gt; APPLICATION_PATH,<br />
&#8216;namespace&#8217; =&gt; &#8216;Application&#8217;<br />
));</span></p>
<p>// Add some resource types<br />
$autoloader-&gt;addResourceTypes(array(<br />
&#8216;forms&#8217; =&gt; array(<br />
&#8216;path&#8217; =&gt; &#8216;forms&#8217;,<br />
&#8216;namespace&#8217; =&gt; &#8216;Form&#8217;<br />
),<br />
&#8216;models&#8217; =&gt; array(<br />
&#8216;path&#8217; =&gt; &#8216;models&#8217;,<br />
&#8216;namespace&#8217; =&gt; &#8216;Model&#8217;<br />
),<br />
));</p>
<p>// Return to bootstrap resource registry<br />
return $autoloader;<br />
}</p>
<p>protected function _initActionHelpers() <span style="color: #800000;"><br />
{<br />
Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH .&#8217;/helpers&#8217;);<br />
}</span></p>
<p>protected function _initDoctype() <span style="color: #800000;"><br />
{<br />
$this-&gt;bootstrap(&#8216;view&#8217;);<br />
$view = $this-&gt;getResource(&#8216;view&#8217;);<br />
$view-&gt;doctype(&#8216;XHTML1_STRICT&#8217;);<br />
}<br />
}</span></p>
<p><span style="color: #800000;"><span style="color: #000000;"><strong>project/public/index.php</strong></span></span></p>
<p><span style="color: #800000;"><span style="color: #ff0000;">&lt;?php</span><br />
// Define path to application directory<br />
defined(&#8216;APPLICATION_PATH&#8217;)<br />
|| define(&#8216;APPLICATION_PATH&#8217;, realpath(dirname(__FILE__) . &#8216;/../application&#8217;));</span></p>
<p>// Define application environment<br />
defined(&#8216;APPLICATION_ENV&#8217;)<br />
|| define(&#8216;APPLICATION_ENV&#8217;, (getenv(&#8216;APPLICATION_ENV&#8217;) ? getenv(&#8216;APPLICATION_ENV&#8217;) : &#8216;development&#8217;));</p>
<p>// Ensure library/ is on include_path<br />
set_include_path(implode(PATH_SEPARATOR, array(<br />
realpath(APPLICATION_PATH . &#8216;/../library&#8217;),<br />
get_include_path(),<br />
)));</p>
<p>/** Zend_Application */<br />
require_once &#8216;Zend/Application.php&#8217;;</p>
<p>// Create application, bootstrap, and run<br />
$application = new Zend_Application(<br />
APPLICATION_ENV,<br />
APPLICATION_PATH . &#8216;/configs/application.ini&#8217;<br />
);<br />
$application-&gt;bootstrap()<br />
-&gt;run();</p>
<p><strong>project/application/configs/application.ini</strong></p>
<p><span style="color: #800000;">[production]<br />
phpSettings.display_startup_errors = 0<br />
phpSettings.display_errors = 0<br />
includePaths.library = APPLICATION_PATH &#8220;/../library&#8221;<br />
bootstrap.path = APPLICATION_PATH &#8220;/Bootstrap.php&#8221;<br />
bootstrap.class = &#8220;Bootstrap&#8221;<br />
appnamespace = &#8220;Application&#8221;<br />
resources.frontController.controllerDirectory = APPLICATION_PATH &#8220;/controllers&#8221;<br />
resources.frontController.params.displayExceptions = 0<br />
resources.view[] =<br />
resources.layout.layoutPath = APPLICATION_PATH &#8220;/layouts/scripts/&#8221;</span></p>
<p>resources.db.adapter = &#8220;PDO_MYSQL&#8221;<br />
resources.db.params.host = &#8220;localhost&#8221;<br />
resources.db.params.username = &#8220;guestbook&#8221;<br />
resources.db.params.password = &#8220;guestbook&#8221;<br />
resources.db.params.dbname = &#8220;guestbook&#8221;</p>
<p>[staging : production]</p>
<p>[testing : production]<br />
phpSettings.display_startup_errors = 1<br />
phpSettings.display_errors = 1</p>
<p>[development : production]<br />
phpSettings.display_startup_errors = 1<br />
phpSettings.display_errors = 1<br />
resources.frontController.params.displayExceptions = 1</p>
<p><strong>project/application/controllers/GuestbookController.php</strong></p>
<p><span style="color: #800000;"><span style="color: #ff0000;">&lt;?php</span><br />
class GuestbookController extends Zend_Controller_Action<br />
{</span></p>
<p>public function init() <span style="color: #800000;"><br />
{<br />
/* Initialize action controller here */<br />
}</span></p>
<p>public function indexAction() <span style="color: #800000;"><br />
{<br />
$guestbook = new Application_Model_GuestbookMapper();<br />
$guestbook-&gt;fetchAll();<br />
//var_dump($guestbook);<br />
$this-&gt;view-&gt;entries = $guestbook-&gt;fetchAll();<br />
}<br />
}</span></p>
<p><strong>project/application/models/Guestbook.php</strong></p>
<p><span style="color: #800000;"><span style="color: #ff0000;">&lt;?php</span><br />
class Application_Model_Guestbook<br />
{<br />
protected $_comment;<br />
protected $_created;<br />
protected $_email;<br />
protected $_id;</span></p>
<p>public function __construct(array $options = null)<br />
{<br />
if (is_array($options)){<br />
$this-&gt;setOptions($options);<br />
}<br />
}</p>
<p>public function __set($name, $value) <span style="color: #800000;"><br />
{<br />
$method = &#8216;set&#8217; . $name;<br />
if ((&#8216;mapper&#8217; == $name) || !method_exists($this, $method)){<br />
throw new Exception(&#8216;Invalid guestbook property&#8217;);<br />
}<br />
$this-&gt;$method($value);<br />
}</span></p>
<p>public function __get($name) <span style="color: #800000;"><br />
{<br />
$method = &#8216;get&#8217; . $name;<br />
if ((&#8216;mapper&#8217; == $name) || !method_exists($this, $method)){<br />
throw new Exception(&#8216;Invalid guestbook property&#8217;);<br />
}<br />
return $this-&gt;$method();<br />
}</span></p>
<p>public function setOptions(array $options) <span style="color: #800000;"><br />
{<br />
$methods = get_class_methods($this);<br />
foreach($options as $key =&gt; $value){<br />
$method = &#8216;set&#8217; . ucfirst($key);<br />
if (in_array($method, $methods)){<br />
$this-&gt;$method($value);<br />
}<br />
}<br />
}</span></p>
<p>public function setComment($text) <span style="color: #800000;"><br />
{<br />
$this-&gt;_comment = (string) $text;<br />
return $this;<br />
}</span></p>
<p>public function getComment() <span style="color: #800000;"><br />
{<br />
return $this-&gt;_comment;<br />
}</span></p>
<p>public function setEmail($email) <span style="color: #800000;"><br />
{<br />
$this-&gt;_email = (string) $email;<br />
return $this;<br />
}</span></p>
<p>public function getEmail() <span style="color: #800000;"><br />
{<br />
return $this-&gt;_email;<br />
}</span></p>
<p>public function setCreated($ts) <span style="color: #800000;"><br />
{<br />
$this-&gt;_created = $ts;<br />
return $this;<br />
}</span></p>
<p>public function getCreated() <span style="color: #800000;"><br />
{<br />
return $this-&gt;_created;<br />
}</span></p>
<p>public function setId($id) <span style="color: #800000;"><br />
{<br />
$this-&gt;_id = (int) $id;<br />
return $this;<br />
}</span></p>
<p>public function getId() <span style="color: #800000;"><br />
{<br />
return $this-&gt;_id;<br />
}<br />
}</span></p>
<p><strong><span style="color: #800000;"><span style="color: #000000;">project/application/models/GuesbookMapper.php</span></span></strong></p>
<p><span style="color: #800000;"><span style="color: #ff0000;">&lt;?php</span><br />
class Application_Model_GuestbookMapper<br />
{<br />
protected $_dbTable;</span></p>
<p>public function setDbTable($dbTable) <span style="color: #800000;"><br />
{<br />
if (is_string($dbTable)){<br />
$dbTable = new $dbTable();<br />
}<br />
if (!$dbTable instanceof Zend_Db_Table_Abstract){<br />
throw new Exception(&#8216;Invalid table data gateway provided&#8217;);<br />
}<br />
$this-&gt;_dbTable = $dbTable;<br />
return $this;<br />
}</span></p>
<p>public function getDbTable() <span style="color: #800000;"><br />
{<br />
if (null === $this-&gt;_dbTable){<br />
$this-&gt;setDbTable(&#8216;Application_Model_DbTable_Guestbook&#8217;);<br />
}<br />
return $this-&gt;_dbTable;<br />
}</span></p>
<p>public function save(Application_Model_Guestbook $guestbook) <span style="color: #800000;"><br />
{<br />
$data = array(<br />
&#8216;email&#8217;    =&gt;    $guestbook-&gt;getEmail(),<br />
&#8216;comment&#8217;    =&gt;    $guestbook-&gt;getComment(),<br />
&#8216;created&#8217;    =&gt;    date(&#8216;Y-m-d H:i:s&#8217;),<br />
);</span></p>
<p>if (null === ($id = $guestbook-&gt;getId())){ <span style="color: #800000;"><br />
unset($data['id']);<br />
$this-&gt;getDbTable()-&gt;insert($data);<br />
} else {<br />
$this-&gt;getDbTable()-&gt;update($data,array(&#8216;id = ?&#8217; =&gt; $id));<br />
}<br />
}</span></p>
<p>public function find($id, Application_Model_Guestbook $guestbook) <span style="color: #800000;"><br />
{<br />
$result = $this-&gt;getDbTable()-&gt;find($id);<br />
if (0 == count($result)){<br />
return;<br />
}<br />
$row = $result-&gt;current();<br />
$guestbook-&gt;setId($row-&gt;id)<br />
-&gt;setEmail($row-&gt;email)<br />
-&gt;setComment($row-&gt;comment)<br />
-&gt;setCreated($row-&gt;created);<br />
}</span></p>
<p>public function fetchAll() <span style="color: #800000;"><br />
{<br />
$resultSet = $this-&gt;getDbTable()-&gt;fetchAll();<br />
//var_dump($resultSet);<br />
$entries = array();<br />
foreach ($resultSet as $row){<br />
$entry = new Application_Model_Guestbook();<br />
$entry-&gt;setId($row-&gt;id)<br />
-&gt;setEmail($row-&gt;email)<br />
-&gt;setComment($row-&gt;comment)<br />
-&gt;setCreated($row-&gt;created);<br />
$entries[] = $entry;<br />
}<br />
return $entries;<br />
}<br />
}</span></p>
<p><span style="color: #000000;"><strong>project/application/models/DbTable/Guestbook.php</strong></span></p>
<p><span style="color: #800000;"><span style="color: #ff0000;">&lt;?php</span><br />
class Application_Model_DbTable_Guestbook extends Zend_Db_Table_Abstract<br />
{<br />
/** Table name */<br />
protected $_name    = &#8216;guestbook&#8217;;<br />
}</span></p>
<p><span style="color: #800000;"><strong><span style="color: #000000;">project/application/views/scripts/guestbook/index.phtml</span></strong></span></p>
<p><span style="color: #800000;">&lt;p&gt;&lt;a href=&#8221;<span style="color: #ff0000;">&lt;?php</span> echo $this-&gt;url(<br />
array(<br />
&#8216;controller&#8217; =&gt; &#8216;guestbook&#8217;,<br />
&#8216;action&#8217; =&gt; &#8216;sign&#8217;<br />
),<br />
&#8216;default&#8217;,<br />
true) <span style="color: #ff0000;">?&gt;</span>&#8220;&gt;Sign Our Guestbook&lt;/a&gt;&lt;/p&gt;</span></p>
<p>Guestbook Entries: &lt;br /&gt; <span style="color: #800000;"><br />
&lt;dl&gt;<br />
<span style="color: #ff0000;">&lt;?php</span> foreach ($this-&gt;entries as $entry): <span style="color: #ff0000;">?&gt;</span><br />
&lt;dt&gt;<span style="color: #ff0000;">&lt;?php</span> echo $this-&gt;escape($entry-&gt;email) <span style="color: #ff0000;">?&gt;</span>&lt;/dt&gt;<br />
&lt;dd&gt;<span style="color: #ff0000;">&lt;?php</span> echo $this-&gt;escape($entry-&gt;comment)<span style="color: #ff0000;">?&gt;</span>&lt;/dd&gt;<br />
<span style="color: #ff0000;">&lt;?php</span> endforeach <span style="color: #ff0000;">?&gt;</span><br />
&lt;/dl&gt;</span></p>
<p><strong><span style="color: #000000;">final URL to hit: <span style="color: #000080;">http://<span style="color: #000000;">project</span>/guestbook</span></span></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://alexyz.com/framework-zend-com-create-a-model-and-database-table-tutorial-fixed-full-working-code-adapted-for-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Mac osx Terminal change root password</title>
		<link>http://alexyz.com/mysql-mac-osx-terminal-change-root-password/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql-mac-osx-terminal-change-root-password</link>
		<comments>http://alexyz.com/mysql-mac-osx-terminal-change-root-password/#comments</comments>
		<pubDate>Sat, 18 Sep 2010 03:53:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://alexyz.com/?p=537</guid>
		<description><![CDATA[Silly thing to note, but I had to Google for this too long to do it again&#8230; Have to give credit where credit is due, thank you: http://www.cyberciti.biz/faq/mysql-change-root-password/ conclusion, command: mysqladmin -u root password NEWPASSWORD]]></description>
			<content:encoded><![CDATA[<p>Silly thing to note, but I had to Google for this too long to do it again&#8230;</p>
<p>Have to give credit where credit is due, thank you:</p>
<p><a href="http://www.cyberciti.biz/faq/mysql-change-root-password/">http://www.cyberciti.biz/faq/mysql-change-root-password/</a></p>
<p>conclusion, command:</p>
<p><strong><span style="color: #ff0000;">mysqladmin -u root password NEWPASSWORD</span></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://alexyz.com/mysql-mac-osx-terminal-change-root-password/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mac OSX remove MySQL</title>
		<link>http://alexyz.com/mac-osx-remove-mysql/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mac-osx-remove-mysql</link>
		<comments>http://alexyz.com/mac-osx-remove-mysql/#comments</comments>
		<pubDate>Sun, 12 Sep 2010 08:41:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://alexyz.com/?p=533</guid>
		<description><![CDATA[sudo rm /usr/local/mysql sudo rm -rf /usr/local/mysql* sudo rm -rf /Library/StartupItems/MySQLCOM sudo rm -rf /Library/PreferencePanes/My* (Edit /etc/hostconfig) sudo vi /etc/hostconfig (Remove line MYSQLCOM=-YES) sudo rm -rf /Library/Receipts/mysql* sudo rm -rf /Library/Receipts/MySQL* sudo rm -rf /var/db/receipts/com.mysql.*]]></description>
			<content:encoded><![CDATA[<ol>
<li>sudo rm /usr/local/mysql</li>
<li>sudo rm -rf /usr/local/mysql*</li>
<li>sudo rm -rf /Library/StartupItems/MySQLCOM</li>
<li>sudo rm -rf /Library/PreferencePanes/My*</li>
<li>(Edit /etc/hostconfig) sudo vi /etc/hostconfig (Remove line MYSQLCOM=-YES)</li>
<li>sudo rm -rf /Library/Receipts/mysql*</li>
<li>sudo rm -rf /Library/Receipts/MySQL*</li>
<li>sudo rm -rf /var/db/receipts/com.mysql.*</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://alexyz.com/mac-osx-remove-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQl sub query example 2</title>
		<link>http://alexyz.com/mysql-sub-query-example-2/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql-sub-query-example-2</link>
		<comments>http://alexyz.com/mysql-sub-query-example-2/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 21:09:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://alexyz.com/?p=440</guid>
		<description><![CDATA[SELECT q.questionId, q.question, q.questionTopic, q.questionDate, q.courseId, q.customerId, v.voted_this FROM &#8221; . $course_database_questions_table_name . &#8221; q LEFT JOIN (SELECT questionId voted_this FROM votes WHERE customerId = &#8216;&#8221; . $customer_id . &#8220;&#8216;) v ON q.questionId = v.voted_this WHERE q.courseId = &#8221; . $courseId . &#8221; ORDER BY q.questionDate DESC]]></description>
			<content:encoded><![CDATA[<p><span style="color: #ff0000;">SELECT</span><br />
q.questionId,<br />
q.question,<br />
q.questionTopic,<br />
q.questionDate,<br />
q.courseId,<br />
q.customerId,<br />
v.voted_this<br />
<span style="color: #ff0000;">FROM</span><br />
&#8221; . $course_database_questions_table_name . &#8221; <span style="color: #ff0000;">q</span><br />
<span style="color: #ff0000;">LEFT JOIN</span><br />
<span style="color: #800000;">(SELECT <span style="color: #000000;">questionId</span> <span style="color: #ff0000;">voted_this</span> FROM <span style="color: #000000;">votes</span> WHERE <span style="color: #000000;">customerId = &#8216;&#8221; . $customer_id . &#8220;&#8216;</span>) v</span><br />
<span style="color: #ff0000;">ON</span><br />
q.questionId = v.voted_this<br />
<span style="color: #ff0000;">WHERE</span><br />
q.courseId = &#8221; . $courseId . &#8221;<br />
<span style="color: #ff0000;">ORDER BY</span> q.questionDate <span style="color: #ff0000;">DESC</span></p>
]]></content:encoded>
			<wfw:commentRss>http://alexyz.com/mysql-sub-query-example-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL sub query example &#8211; nice</title>
		<link>http://alexyz.com/mysql-sub-query-example-nice/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql-sub-query-example-nice</link>
		<comments>http://alexyz.com/mysql-sub-query-example-nice/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 22:20:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://alexyz.com/?p=437</guid>
		<description><![CDATA[$cp_output = &#8220;&#8221;; if(!$get_cp_data = mysql_query(&#8221; SELECT q.*, c.*, vote_counts.Tally FROM questions q LEFT JOIN (SELECT questionId, count(1) as Tally FROM votes GROUP BY questionId ) vote_counts ON q.questionId = vote_counts.questionId LEFT JOIN customers c ON c.customerId = q.customerId WHERE q.courseId = 1 ORDER BY vote_counts.Tally desc &#8220;)){ echo mysql_error(); } while($get_cp_data_array = mysql_fetch_array($get_cp_data)){ $q_id [...]]]></description>
			<content:encoded><![CDATA[<p>$cp_output = &#8220;&#8221;;<br />
if(!$get_cp_data = mysql_query(&#8221;<br />
<span style="color: #ff0000;">SELECT<br />
q.*,<br />
c.*,<br />
vote_counts.Tally<br />
FROM<br />
questions q<br />
LEFT JOIN<br />
(SELECT<br />
questionId,<br />
count(1) as Tally<br />
FROM<br />
votes<br />
GROUP BY<br />
questionId<br />
) vote_counts<br />
ON<br />
q.questionId = vote_counts.questionId<br />
LEFT JOIN<br />
customers c<br />
ON<br />
c.customerId = q.customerId<br />
WHERE<br />
q.courseId = 1<br />
ORDER BY<br />
vote_counts.Tally desc</span><br />
&#8220;)){ echo mysql_error(); }</p>
<p>while($get_cp_data_array = mysql_fetch_array($get_cp_data)){<br />
$q_id = $get_cp_data_array['questionId'];</p>
<p>$q_fname = $get_cp_data_array['customerFName'];<br />
$q_lname = $get_cp_data_array['customerLName'];<br />
$q_email = $get_cp_data_array['customerEmail'];</p>
<p>$q_topic = $get_cp_data_array['questionTopic'];<br />
$q_question = $get_cp_data_array['question'];<br />
$q_date = $get_cp_data_array['questionDate'];<br />
//$q_count = $get_cp_data_array['votecount'];<br />
$q_customer = $get_cp_data_array['customerId'];</p>
<p>if($q_topic == &#8220;&#8221;){ $q_topic = &#8220;&#8211;&#8221;; }<br />
if($q_fname != &#8220;&#8221; || $q_lname != &#8220;&#8221;){<br />
$from = &#8216;&lt;strong&gt;&#8217; . $q_fname . &#8216; &#8216; . $q_lname . &#8216;&lt;/strong&gt; &#8211; &#8216;;<br />
}</p>
<p># Parse the question text.<br />
$old = array(&#8220;\n&#8221;);<br />
$new   = array(&#8220;&lt;br/&gt;&#8221;);<br />
$q_question = str_replace($old, $new, $q_question);</p>
<p># Output the question.<br />
$cp_output = $cp_output . &#8216;<br />
&lt;div&gt;&#8217; . $q_id . &#8216;&lt;/div&gt;<br />
&lt;div&gt;<br />
&lt;div&gt;&lt;strong&gt;&#8217; . $q_topic . &#8216;&lt;/strong&gt;&lt;/div&gt;<br />
&lt;div&gt;&#8217; . $q_question . &#8216;&lt;/div&gt;<br />
&lt;div&gt;&lt;strong&gt;Submitted&lt;/strong&gt; &#8216; . $q_date . &#8216; by &#8216; . $from . &#8216;&lt;a href=&#8221;mailto:&#8217; . $q_email . &#8216;&#8221;&gt;&#8217; . $q_email . &#8216;&lt;/a&gt;&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;div&gt;&lt;/div&gt;<br />
&#8216;;<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://alexyz.com/mysql-sub-query-example-nice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL refresher</title>
		<link>http://alexyz.com/mysql-refresher/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql-refresher</link>
		<comments>http://alexyz.com/mysql-refresher/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 04:28:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://alexyz.com/?p=403</guid>
		<description><![CDATA[datatypes: http://w3schools.com/sql/sql_datatypes.asp Order results by 2 columns: SELECT column_name(s) FROM table_name ORDER BY column1, column2 Simple delete: &#60;?php $con = mysql_connect(&#8220;localhost&#8221;,&#8221;peter&#8221;,&#8221;abc123&#8243;); if (!$con) { die(&#8216;Could not connect: &#8216; . mysql_error()); } mysql_select_db(&#8220;my_db&#8221;, $con); mysql_query(&#8220;DELETE FROM Persons WHERE LastName=&#8217;Griffin&#8217;&#8221;); mysql_close($con); ?&#62;]]></description>
			<content:encoded><![CDATA[<p>datatypes:</p>
<p><a href="http://w3schools.com/sql/sql_datatypes.asp">http://w3schools.com/sql/sql_datatypes.asp</a></p>
<p>Order results by 2 columns:</p>
<p><span style="color: #888888;">SELECT column_name(s)<br />
FROM table_name<br />
ORDER BY column1, column2</span></p>
<p><span style="color: #888888;"><span style="color: #000000;">Simple delete:</span></span></p>
<p><span style="color: #ff0000;">&lt;?php<br />
$con = mysql_connect(&#8220;localhost&#8221;,&#8221;peter&#8221;,&#8221;abc123&#8243;);<br />
if (!$con)<br />
{<br />
die(&#8216;Could not connect: &#8216; . mysql_error());<br />
}<br />
mysql_select_db(&#8220;my_db&#8221;, $con);<br />
mysql_query(&#8220;DELETE FROM Persons WHERE LastName=&#8217;Griffin&#8217;&#8221;);<br />
mysql_close($con);<br />
?&gt;</span></p>
]]></content:encoded>
			<wfw:commentRss>http://alexyz.com/mysql-refresher/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>date() and timestamp refresher</title>
		<link>http://alexyz.com/date-and-timestamp-refresher/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=date-and-timestamp-refresher</link>
		<comments>http://alexyz.com/date-and-timestamp-refresher/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 02:42:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://alexyz.com/?p=393</guid>
		<description><![CDATA[date(format,timestamp) format is required, example: date(&#8220;Y-m-d&#8221;) of course, Y, m, and d stand for Year, month, day, and they may be separated by whatever you like, so the above example returns 2010-07-27, while date(&#8220;m/d/Y&#8221;) returns 07/27/2010 now for the timestamp parameter MAKE what should be supplied for the timestamp, with mktime(hour,minute,second,month,day,year,is_dst) $tomorrow = mktime(0,0,0,date(&#8220;m&#8221;),date(&#8220;d&#8221;)+1,date(&#8220;Y&#8221;)) date(&#8220;Y/m/d&#8221;,$tomorrow) [...]]]></description>
			<content:encoded><![CDATA[<p><span style="color: #ff0000;">date(<em>format</em>,<em>timestamp</em>)</span></p>
<p>format is required, example:</p>
<p><span style="color: #ff0000;">date(&#8220;Y-m-d&#8221;)</span></p>
<p>of course, Y, m, and d stand for Year, month, day, and they may be separated by whatever you like, so the above example returns 2010-07-27, while <span style="color: #ff0000;">date(&#8220;m/d/Y&#8221;)</span> returns 07/27/2010</p>
<p>now for the <span style="color: #ff0000;">timestamp</span> parameter</p>
<p>MAKE what should be supplied for the <span style="color: #ff0000;">timestamp</span>, with <span style="color: #ff0000;">mktime(hour,minute,second,month,day,year,is_dst)</span></p>
<p><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;">$tomorrow = mktime(0,0,0,date(&#8220;m&#8221;),date(&#8220;d&#8221;)+1,date(&#8220;Y&#8221;))</span></span></span></p>
<p><span style="color: #ff0000;">date(&#8220;Y/m/d&#8221;,$tomorrow) <span style="color: #000000;">returns tomorrow!</span><br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://alexyz.com/date-and-timestamp-refresher/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>using a PHP variable in a MySQL IN batch query example</title>
		<link>http://alexyz.com/using-a-php-variable-in-a-mysql-query-example/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-a-php-variable-in-a-mysql-query-example</link>
		<comments>http://alexyz.com/using-a-php-variable-in-a-mysql-query-example/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 23:13:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://alexyz.com/?p=383</guid>
		<description><![CDATA[Note the &#8216;s $product_list = &#8220;&#8217;1869&#8242;, &#8217;1929&#8242;, &#8217;549&#8242;, &#8217;189&#8242;, &#8217;419&#8242;, &#8217;176&#8242;, &#8217;192&#8242;, &#8217;310&#8242;, &#8217;291&#8242;, &#8217;514&#8242;, &#8217;1643&#8242;, &#8217;1033&#8242;&#8220;; $db_name = &#8220;dbName&#8221;; //conditional platform logic to support multiple connection scenarios switch($_SERVER['HTTP_HOST']) { case &#8216;localhost&#8217;: $db_host = &#8220;localhost&#8221;; $db_username = &#8220;userName&#8221;; $db_password = &#8220;Password&#8221;; $dblink = mysql_connect ($db_host, $db_username, $db_password); mysql_select_db($db_name, $dblink); break; case &#8216;www-staging.site.com&#8217;: break; case &#8216;www.site.com&#8217;: [...]]]></description>
			<content:encoded><![CDATA[<p><span style="color: #800080;">Note the &#8216;s</span></p>
<p><strong>$product_list</strong> <span style="color: #339966;">= &#8220;</span><span style="color: #ff0000;">&#8217;1869&#8242;, &#8217;1929&#8242;, &#8217;549&#8242;, &#8217;189&#8242;, &#8217;419&#8242;, &#8217;176&#8242;, &#8217;192&#8242;, &#8217;310&#8242;, &#8217;291&#8242;, &#8217;514&#8242;, &#8217;1643&#8242;, &#8217;1033&#8242;</span><span style="color: #339966;">&#8220;</span><span style="color: #339966;">;</span></p>
<p><strong>$db_name</strong> = &#8220;dbName&#8221;<span style="color: #339966;">;</span><br />
<span style="color: #993366;">//conditional platform logic to support multiple connection scenarios</span></p>
<p><span style="color: #339966;">switch(</span><span style="color: #ff0000;">$_SERVER</span>['HTTP_HOST']<span style="color: #339966;">)</span><br />
<span style="color: #339966;">{</span><br />
<span style="color: #339966;">case</span> &#8216;localhost&#8217;<span style="color: #339966;">:</span><br />
<strong>$db_host</strong> = &#8220;localhost&#8221;<span style="color: #339966;">;</span><br />
<strong>$db_username</strong> = &#8220;userName&#8221;<span style="color: #339966;">;</span><br />
<strong>$db_password</strong> = &#8220;Password&#8221;<span style="color: #339966;">;</span><br />
<strong>$dblink</strong> = <span style="color: #ff0000;">mysql_connect</span> (<strong>$db_host</strong>, <strong>$db_username</strong>, <strong>$db_password</strong>);<br />
<span style="color: #ff0000;">mysql_select_db</span>(<strong>$db_name</strong>, <strong>$dblink</strong>);<br />
<span style="color: #339966;">break;</span><br />
<span style="color: #339966;">case</span> &#8216;www-staging.site.com&#8217;<span style="color: #339966;">: break;</span><br />
<span style="color: #339966;">case</span> &#8216;www.site.com&#8217;<span style="color: #339966;">:</span><br />
<span style="color: #339966;">include(</span>&#8216;/var/www/includes/connection_script.php&#8217;<span style="color: #339966;">);</span><br />
<span style="color: #339966;">break;</span><br />
<span style="color: #339966;">}</span></p>
<p><strong>$result</strong> = <span style="color: #ff0000;">mysql_query(&#8221;<br />
SELECT<br />
product_id,<br />
product_name<br />
FROM<br />
tableNameHere<br />
WHERE<br />
product_id IN</span><span style="color: #ff0000;"> (&#8220;<span style="color: #000000;">.</span></span><strong>$product_list</strong>.<span style="color: #ff0000;">&#8220;)</span><br />
<span style="color: #ff0000;">&#8220;)</span><span style="color: #339966;">;</span><br />
<span style="color: #339966;">if (!<strong>$result</strong>) { echo &#8220;</span>Could not successfully run query ($sql) from DB:<span style="color: #339966;"> &#8220;</span> . <span style="color: #ff0000;">mysql_error</span>()<span style="color: #339966;">; exit; }</span></p>
<p><span style="color: #993366;"><br />
//let&#8217;s break out the resource so that it can be singularly requested when needed</span></p>
<p><span style="color: #339966;">while(</span><strong>$one</strong> = <span style="color: #ff0000;">mysql_fetch_assoc</span><span style="color: #339966;">(</span><strong>$result</strong><span style="color: #339966;">))</span><br />
<span style="color: #339966;">{</span><br />
<strong>$prod_id</strong> <span style="color: #339966;">=</span> <strong>$one</strong>['<span style="color: #ff0000;">product_id</span>']<span style="color: #339966;">;</span><br />
<strong>$product_name[</strong><strong>$prod_id]</strong> <span style="color: #339966;">=</span> <strong>$one</strong>['<span style="color: #ff0000;">product_name</span>']<span style="color: #339966;">;</span><br />
<span style="color: #339966;">}<br />
@</span><span style="color: #ff0000;">mysql_close</span>(<strong>$dblink</strong>)<span style="color: #339966;">;</span></p>
]]></content:encoded>
			<wfw:commentRss>http://alexyz.com/using-a-php-variable-in-a-mysql-query-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL phpMyAdmin text string find replace Query</title>
		<link>http://alexyz.com/mysql-phpmyadmin-text-string-find-replace-query/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql-phpmyadmin-text-string-find-replace-query</link>
		<comments>http://alexyz.com/mysql-phpmyadmin-text-string-find-replace-query/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 23:21:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[phpMyAdmin]]></category>

		<guid isPermaLink="false">http://alexyz.com/?p=317</guid>
		<description><![CDATA[update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME,&#8217;find this string&#8217;,'replace it with this one&#8217;); example (for videodb to turn all &#8220;wanted&#8221; titles into &#8220;DVD&#8221; titles): update videodb_videodata set mediatype = replace(mediatype,’50’,&#8217;1’);]]></description>
			<content:encoded><![CDATA[<p>update TABLE_NAME set FIELD_NAME =<br />
replace(FIELD_NAME,&#8217;find this string&#8217;,'replace it with this one&#8217;);</p>
<p>example (for videodb to turn all &#8220;wanted&#8221; titles into &#8220;DVD&#8221; titles):</p>
<p>update videodb_videodata set mediatype =<br />
replace(mediatype,’50’,&#8217;1’);</p>
]]></content:encoded>
			<wfw:commentRss>http://alexyz.com/mysql-phpmyadmin-text-string-find-replace-query/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP MySQL date &amp; time reference</title>
		<link>http://alexyz.com/php-mysql-date-time-reference/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=php-mysql-date-time-reference</link>
		<comments>http://alexyz.com/php-mysql-date-time-reference/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 22:19:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://alexyz.com/?p=299</guid>
		<description><![CDATA[http://www.eltcalendar.com/stuff/datemysqlphp.html thank you for this great handy reference! pasted verbatim: Format PHP MySQL Time The function is: date(format) where &#8220;format&#8221; consists of the letters given below. The functions are: date_format(string, format) time_format(string, format) where &#8220;format&#8221; consists of the letters given below.) hour, 2-digit, 12-hour (01-12) h %h hour, 2-digit, 24-hour (00-23) H %H hour, numeric, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.eltcalendar.com/stuff/datemysqlphp.html">http://www.eltcalendar.com/stuff/datemysqlphp.html</a></p>
<p>thank you for this great handy reference!</p>
<p>pasted verbatim:</p>
<table border="1">
<tbody>
<tr>
<td><strong>Format</strong></td>
<td><strong>PHP</strong></td>
<td><strong>MySQL</strong></td>
</tr>
<tr>
<td><strong>Time</strong></td>
<td>The  function is:<br />
date(format)<br />
where &#8220;format&#8221; consists of the letters  given below.</td>
<td>The functions are:<br />
date_format(string, format)<br />
time_format(string,  format)<br />
where &#8220;format&#8221; consists of the letters given below.)</td>
</tr>
<tr>
<td>hour,  2-digit, 12-hour (01-12)</td>
<td>h</td>
<td>%h</td>
</tr>
<tr>
<td>hour,  2-digit, 24-hour (00-23)</td>
<td>H</td>
<td>%H</td>
</tr>
<tr>
<td>hour,  numeric, 12-hour (1-12)</td>
<td>g</td>
<td>%l</td>
</tr>
<tr>
<td>hour,  numeric, 24-hour (0-23)</td>
<td>G</td>
<td>%k</td>
</tr>
<tr>
<td>minute,  2-digit (00-59)</td>
<td>i</td>
<td>%i</td>
</tr>
<tr>
<td>seconds, 2-digit  (00-59)</td>
<td>s</td>
<td>%S</td>
</tr>
<tr>
<td>time, 24-hour  (hh:mm:ss)</td>
<td>none, use date(&#8220;H:i:s&#8221;)</td>
<td>%T</td>
</tr>
<tr>
<td>time,  12-hour (hh:mm:ss AM/PM)</td>
<td>none, use date(&#8220;g:i:s A&#8221;)</td>
<td>%r</td>
</tr>
<tr>
<td>AM  / PM (uppercase letters)</td>
<td>A</td>
<td>%p</td>
</tr>
<tr>
<td>am /  pm (lowercase letters)</td>
<td>a</td>
<td>none</td>
</tr>
<tr>
<td><strong>Days</strong></td>
<td></td>
<td></td>
</tr>
<tr>
<td>day  name, full (Sunday)</td>
<td>l (a lowercase L)</td>
<td>%W</td>
</tr>
<tr>
<td>day  name, abbreviation (Sun)</td>
<td>D</td>
<td>%a</td>
</tr>
<tr>
<td>day as  number of week (0-6)</td>
<td>none, use a getdate() array:<br />
First do  this:<br />
$dateInfo = getdate();<br />
Your day as number of the week is  $dateInfo[wday];</td>
<td>%w</td>
</tr>
<tr>
<td>day number of the year</td>
<td>z<br />
(Note: 0-365; <em>ex: </em>January 1st is 0)</td>
<td>%j<br />
(Note:  001-366; <em>ex: </em>January 1st is 001)</td>
</tr>
<tr>
<td><strong>Dates</strong></td>
<td></td>
<td></td>
</tr>
<tr>
<td>month  name in full (January)</td>
<td>F</td>
<td>%M</td>
</tr>
<tr>
<td>month  name, abbreviated (Jan)</td>
<td>M</td>
<td>%b</td>
</tr>
<tr>
<td>month,  2-digit (01-12)</td>
<td>m</td>
<td>%m</td>
</tr>
<tr>
<td>month, no  leading 0 (1, 2, 3 &#8211; 12)</td>
<td>n</td>
<td>%c</td>
</tr>
<tr>
<td>day of  month, 2-digit (01, 02, &#8230;)</td>
<td>d</td>
<td>%d</td>
</tr>
<tr>
<td>day  of month, no leading 0 (1, 2)</td>
<td>j</td>
<td>%e</td>
</tr>
<tr>
<td>day  of month with ordinal suffix (1st, 2nd, 3rd, 4th&#8230;)</td>
<td>none. Use  jS</td>
<td>%D</td>
</tr>
<tr>
<td>ordinal suffix (st, nd, rd, th)</td>
<td>S</td>
<td>none;  use %D (above)</td>
</tr>
<tr>
<td>year, 4 digit (2001)</td>
<td>Y</td>
<td>%Y</td>
</tr>
<tr>
<td>year,  2 digit (00-99)</td>
<td>y</td>
<td>%y</td>
</tr>
<tr>
<td height="3"></td>
<td height="3"></td>
<td height="3"></td>
</tr>
<tr>
<td><strong>Examples: To  write:</strong></td>
<td><strong>Use this:</strong></td>
<td><strong>Use this:</strong></td>
</tr>
<tr>
<td>Sunday,  June 03, 2001</td>
<td>date(&#8216;l, F d, Y&#8217;)</td>
<td>date_format(<em>date</em>,  &#8216;%W, %M %d, %Y&#8217;)</td>
</tr>
<tr>
<td>Sun., Jun 3rd, 2001. 11:30 AM</td>
<td>date(&#8216;D.,  M jS, Y.g:i A&#8217;)</td>
<td>date_format(<em>datetime</em>, &#8216;%a., %b %D, %Y.  %l: %i %p&#8217;)<br />
Or if there are two columns, one <em>date</em> and one <em>time</em>,  you&#8217;d use:<br />
date_format(<em>date</em>, &#8216;%a., %b %D, %Y.&#8217;)<br />
time_format(<em>time</em>,  &#8216;%l: %i %p&#8217;)<br />
See the note below)</td>
</tr>
<tr>
<td>2001-06-03</td>
<td>date(&#8216;Y-m-d&#8217;)</td>
<td>(see  important note below; this is default for date-type columns so you  don&#8217;t have to use any special function or formatting at all.)</td>
</tr>
</tbody>
</table>
<p><strong>Important  Note:</strong></p>
<p>The choice in MySQL between date_format() and  time_format() depends on the type of column you have stored your date  in.</p>
<table border="1">
<tbody>
<tr>
<td width="237">MySQL column  type:</td>
<td width="237">Data format in the column (all parts  are required)</td>
<td width="237">Example:</td>
<td width="237">Use:</td>
</tr>
<tr>
<td width="237"><strong>date</strong></td>
<td width="237">YYYY-MM-DD</td>
<td width="237">2001-06-03</td>
<td width="237">date_format() to get date values</td>
</tr>
<tr>
<td width="237"><strong>time</strong> (see &#8220;NB&#8221; below)</td>
<td width="237">hh:mm:ss</td>
<td width="237">13:30:00</td>
<td width="237">time_format() to get  time values</td>
</tr>
<tr>
<td width="237"><strong>datetime</strong></td>
<td width="237">YYY-MM-DD hh:mm:ss</td>
<td width="237">2001-06-03  13:30:00</td>
<td width="237">date_format() to get date and/or  time values</td>
</tr>
</tbody>
</table>
<p>NB: the <strong>time</strong> type for  MySQL columns actually represents an amount of time <em>elapsed</em>;  thus, it can be negative or positive. However, it can also be used to  represent the time of day, where it represents the amount of time  elapsed since 1 second past midnight. If you forget to add :00 for  seconds (for example, using 13:30 for 1:30 p.m.), your time value will  be interpreted as the number of minutes and seconds after midnight, or  12:30 a.m. plus 30 seconds.</p>
]]></content:encoded>
			<wfw:commentRss>http://alexyz.com/php-mysql-date-time-reference/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL phpMyAdmin Query change table names syntax</title>
		<link>http://alexyz.com/mysql-phpmyadmin-query-change-table-names-syntax/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql-phpmyadmin-query-change-table-names-syntax</link>
		<comments>http://alexyz.com/mysql-phpmyadmin-query-change-table-names-syntax/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 19:30:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://alexyz.com/?p=285</guid>
		<description><![CDATA[RENAME TABLE database_name.table_name TO database_name.new_table_name, database_name.table2_name TO database_name.new_table2_name; NOTE the comma and the semicolon!]]></description>
			<content:encoded><![CDATA[<p><span style="color: #333300;">RENAME TABLE</span></p>
<p><span style="color: #333300;">database_name.table_name TO database_name.new_table_name,</span></p>
<p><span style="color: #333300;">database_name.table2_name TO database_name.new_table2_name;</span></p>
<p><span style="color: #008080;">NOTE the comma and the semicolon!</span></p>
]]></content:encoded>
			<wfw:commentRss>http://alexyz.com/mysql-phpmyadmin-query-change-table-names-syntax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>phpMyAdmin Server config.inc.php remote database connection</title>
		<link>http://alexyz.com/phpmyadmin-server-config/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=phpmyadmin-server-config</link>
		<comments>http://alexyz.com/phpmyadmin-server-config/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 05:19:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Godaddy]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://alexyz.com/?p=142</guid>
		<description><![CDATA[C:\xampp\phpMyAdmin\config.inc.php add this (or similar) at the bottom: $i++; $cfg['Servers'][$i]['auth_type'] = &#8216;config&#8217;; $cfg['Servers'][$i]['user'] = &#8216;user&#8217;; $cfg['Servers'][$i]['password'] = &#8216;password&#8217;; $cfg['Servers'][$i]['host'] = &#8216;your_host&#8217;; $cfg['Servers'][$i]['verbose'] = &#8216;Description to appear in phpMyAdmin&#8217;; //end params/reference: http://wiki.phpmyadmin.net/pma/Config And then control remote MySQL databases in your localhost/phpmyadmin under Actions: Server: dropdown *note: When connecting to a Godaddy DB, you must enable accessible [...]]]></description>
			<content:encoded><![CDATA[<p>C:\xampp\phpMyAdmin\config.inc.php</p>
<p>add this (or similar) at the bottom:</p>
<p><span style="color: #ff0000;">$i++;</span></p>
<p><span style="color: #ff0000;">$cfg['Servers'][$i]['auth_type'] = &#8216;config&#8217;;<br />
$cfg['Servers'][$i]['user'] = &#8216;user&#8217;;<br />
$cfg['Servers'][$i]['password'] = &#8216;password&#8217;;<br />
$cfg['Servers'][$i]['host'] = &#8216;your_host&#8217;;<br />
$cfg['Servers'][$i]['verbose'] = &#8216;Description to appear in phpMyAdmin&#8217;;</span></p>
<p><span style="color: #ff0000;">//end</span></p>
<p>params/reference: <a href="http://wiki.phpmyadmin.net/pma/Config" target="_blank">http://wiki.phpmyadmin.net/pma/Config</a></p>
<p>And then control remote MySQL databases in your localhost/phpmyadmin</p>
<p>under Actions: Server: dropdown</p>
<p><span style="color: #ff00ff;">*note: When connecting to a Godaddy DB, you must enable accessible remotely when creating the database!</span></p>
]]></content:encoded>
			<wfw:commentRss>http://alexyz.com/phpmyadmin-server-config/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Php db connection close()</title>
		<link>http://alexyz.com/php-db-connection-close/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=php-db-connection-close</link>
		<comments>http://alexyz.com/php-db-connection-close/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 14:33:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://alexyz.com/?p=131</guid>
		<description><![CDATA[@mysql_close($dblink); or the network persistence traffic cop might come calling&#8230;YOU]]></description>
			<content:encoded><![CDATA[<p><span style="color: #ff0000;">@mysql_close($dblink); </span></p>
<p>or the network persistence traffic cop might come calling&#8230;YOU</p>
]]></content:encoded>
			<wfw:commentRss>http://alexyz.com/php-db-connection-close/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL comments</title>
		<link>http://alexyz.com/mysql-comments/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql-comments</link>
		<comments>http://alexyz.com/mysql-comments/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 14:27:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://alexyz.com/?p=125</guid>
		<description><![CDATA[start of line left only (must have space after dashes): &#8211; comment OR /* */ example: if(!$result = mysql_query(&#8221; SELECT products_id, FROM runwayProductInfo, WHERE products_id IN (&#8217;545&#8242;,&#8217;100&#8242;) /* hello */ &#8211; comment ORDER BY FIELD(runwayProductInfo.products_id, &#8217;100&#8242;,&#8217;545&#8242;) &#8220;)){ echo mysql_error(); exit; }]]></description>
			<content:encoded><![CDATA[<p>start of line left only (must have space after  dashes):<br />
<strong>&#8211; comment</strong></p>
<p>OR<br />
<strong>/* */</strong></p>
<p>example:</p>
<p>if(!$result = mysql_query(&#8221;<br />
SELECT<br />
products_id,<br />
FROM<br />
runwayProductInfo,<br />
WHERE<br />
products_id IN (&#8217;545&#8242;,&#8217;100&#8242;)<br />
/* hello */<br />
&#8211; comment<br />
ORDER BY FIELD(runwayProductInfo.products_id, &#8217;100&#8242;,&#8217;545&#8242;)<br />
&#8220;)){ echo mysql_error(); exit; }</p>
]]></content:encoded>
			<wfw:commentRss>http://alexyz.com/mysql-comments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Php MySQL query shortcut syntax</title>
		<link>http://alexyz.com/php-mysql-query-shortcut-syntax/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=php-mysql-query-shortcut-syntax</link>
		<comments>http://alexyz.com/php-mysql-query-shortcut-syntax/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 06:26:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://alexyz.com/?p=123</guid>
		<description><![CDATA[$query = &#8220;SELECT o.FirstName, o.LastName, o.Addr1, o.Addr2, o.City, s.Name AS State, s.Abbrv as StateAbbrv, o.ZipCode, o.Phone1, o.EmailAddr, o.CCLastFour, o.CCExp, o.PromoCode FROM orders o INNER JOIN states s ON s.StateID = o.StateID WHERE o.OrderID = &#8221; . $this-&#62;_orderID;]]></description>
			<content:encoded><![CDATA[<p><span style="color: #ff0000;">$query  = &#8220;SELECT<br />
o.FirstName, o.LastName, o.Addr1, o.Addr2, o.City,<br />
s.Name AS State, s.Abbrv as StateAbbrv, o.ZipCode,<br />
o.Phone1, o.EmailAddr, o.CCLastFour, o.CCExp,  o.PromoCode<br />
FROM orders o<br />
INNER JOIN states s ON s.StateID = o.StateID<br />
WHERE o.OrderID = &#8221; . $this-&gt;_orderID;</span></p>
]]></content:encoded>
			<wfw:commentRss>http://alexyz.com/php-mysql-query-shortcut-syntax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

