<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments for The PHP Coder&#039;s Judy Chop</title>
	<atom:link href="http://phpadvocate.com/blog/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://phpadvocate.com/blog</link>
	<description>PHP, MySQL, SVN and Javascript Optimizations, Tips and Tricks</description>
	<lastBuildDate>Fri, 18 May 2012 15:04:03 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>Comment on How to Fix svn: Directory __DIR__ containing working copy admin area is missing (and other misc SVN shortcuts) by Jonathon Hibbard</title>
		<link>http://phpadvocate.com/blog/2009/12/how-to-fix-svn-directory-__dir__-containing-working-copy-admin-area-is-missing-and-other-misc-svn-shortcuts/comment-page-1/#comment-2350</link>
		<dc:creator>Jonathon Hibbard</dc:creator>
		<pubDate>Fri, 18 May 2012 15:04:03 +0000</pubDate>
		<guid isPermaLink="false">http://phpadvocate.com/php/?p=45#comment-2350</guid>
		<description>No problem, glad to have helped.</description>
		<content:encoded><![CDATA[<p>No problem, glad to have helped.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on How to Fix svn: Directory __DIR__ containing working copy admin area is missing (and other misc SVN shortcuts) by AHMAD FANANI</title>
		<link>http://phpadvocate.com/blog/2009/12/how-to-fix-svn-directory-__dir__-containing-working-copy-admin-area-is-missing-and-other-misc-svn-shortcuts/comment-page-1/#comment-2349</link>
		<dc:creator>AHMAD FANANI</dc:creator>
		<pubDate>Thu, 10 May 2012 13:06:28 +0000</pubDate>
		<guid isPermaLink="false">http://phpadvocate.com/php/?p=45#comment-2349</guid>
		<description>Thanks a lot... this article has helped me...!!!</description>
		<content:encoded><![CDATA[<p>Thanks a lot&#8230; this article has helped me&#8230;!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Helpful Links Every PHP/Web Developer Should Have by Helpful Links Every PHP/Web Developer Should Have &#124; The PHP &#8230; - Web 2.0 BLOG &#124; Web 2.0 BLOG</title>
		<link>http://phpadvocate.com/blog/2012/03/helpful-links-every-developer-should-have/comment-page-1/#comment-2347</link>
		<dc:creator>Helpful Links Every PHP/Web Developer Should Have &#124; The PHP &#8230; - Web 2.0 BLOG &#124; Web 2.0 BLOG</dc:creator>
		<pubDate>Sun, 06 May 2012 19:12:15 +0000</pubDate>
		<guid isPermaLink="false">http://phpadvocate.com/blog/?p=419#comment-2347</guid>
		<description>[...] original post here: Helpful Links Every PHP/Web Developer Should Have &#124; The PHP &#8230;  Bookmark on Delicious Digg this post Recommend on Facebook share via Reddit Share with Stumblers [...]</description>
		<content:encoded><![CDATA[<p>[...] original post here: Helpful Links Every PHP/Web Developer Should Have | The PHP &#8230;  Bookmark on Delicious Digg this post Recommend on Facebook share via Reddit Share with Stumblers [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on PHP Singleton Pattern &#8211; OOP by Jonathon Hibbard</title>
		<link>http://phpadvocate.com/blog/2011/04/php-using-a-singleton-pattern-with-oop/comment-page-1/#comment-2343</link>
		<dc:creator>Jonathon Hibbard</dc:creator>
		<pubDate>Mon, 30 Apr 2012 17:40:49 +0000</pubDate>
		<guid isPermaLink="false">http://phpadvocate.com/blog/?p=211#comment-2343</guid>
		<description>Steve, Thanks for the input!

In situations where you have multiple possible database connections, you could still use the singleton solution but it would absolutely be different in situations like the one that you&#039;ve presented.

In situations where you have the possibility of multiple database connections, a singleton solution is still possible.  

Realize, there are MULTIPLE other possibilities.  The example I&#039;m going to give (I do not believe it is the best) is only an example - it is not the only way...

The example strategy would be to have an array private to MyDBH that tracks all instances, and update MyDBH&#039;s getInstnace method to accept the name of the db connection you want to create.  In order to do this, either you&#039;d have to define every database conection&#039;s credentials in the MyDBH class, create a separate class that the MyDBH extends for storing DB configuration, create a configuration file that can be included to obtain an instances&#039;s credentials, or create an object that stores this sort of information.

This example just creates a dbconnection factory because I&#039;m trying to keep this short and sweet (and also show the factory pattern at the same time):
&lt;?php
// using the &quot;i&quot; prefix to indicate its an interface...
interface iDbConnection {
  public function getDbInfo();
  // anything else...
}

// Could make this abstract too obviously....
class DbConnectionFactory {
  // just an example for factory as well...
  public static function getInstance($db_connection) {
    if(class_exists($db_connection) &amp;&amp; method_exists()) {
       $dbConnection = new $db_connection;
       if(!($dbConnection instanceof iDbConnection)) {
         throw new Exception(&quot;Invalid DB Connection Requested!&quot;);
       }
       // do whatever
       return $dbConnection-&gt;getDbInfo();
    }
  }
}

class AdvertisementDbConnection implements iDbConnection {
  private $db_info = array(&quot;host&quot; =&gt; &quot;localhost&quot;, &quot;dbname&quot; =&gt; &quot;myAdvertisementDB&quot;, &quot;username&quot; =&gt; &quot;myAdvertisementDB_user&quot;, &quot;password&quot; =&gt; &quot;myAdvertisementDB_password&quot;);

  // whatever else 

  public function getDbInfo() {
    return $this-&gt;db_info;
  }
}

class MyDBH {
  // changed this to an array...
  private static $instances = array();
  
  // .......
  // 
  // same logic/methods/properties from above...
  // 
  // .......
 
  public static function getInstance($db_connection = &#039;default&#039;) {
    // keep it all consistent...
    $db_connection = strtolower($db_connection);
    if(!isset(self::$instances[$db_connection])) {
      $db_info = (strtolower($db_connection) == &#039;default&#039; ? null : DbConnectionFactory::getInstance($db_connection));
      self::$instances[$db_connection] = new MyDBH($db_info);
    }
    return self::$instances[$db_connection];
  }
}

// same ole, same ole..
$dbh = MyDBH::getInstance();


// get advertisement
$dbh = MyDBH::getInstance(&#039;AdvertisementDbConnection&#039;);

While crude, this shows a basic example..  You could improve this in many, many different ways.  Up to you how to do this.

Also, I&#039;d like to point out that multiple user&#039;s on a page does not affect the singleton since PHP creates a new thread per user that accesses your page.  In other words, the logic that checks for &quot;current state&quot; to display a page, and will still use everything you would normally expect.

Note: I didn&#039;t actually test the above so feel free to make improvements where needed!</description>
		<content:encoded><![CDATA[<p>Steve, Thanks for the input!</p>
<p>In situations where you have multiple possible database connections, you could still use the singleton solution but it would absolutely be different in situations like the one that you&#8217;ve presented.</p>
<p>In situations where you have the possibility of multiple database connections, a singleton solution is still possible.  </p>
<p>Realize, there are MULTIPLE other possibilities.  The example I&#8217;m going to give (I do not believe it is the best) is only an example &#8211; it is not the only way&#8230;</p>
<p>The example strategy would be to have an array private to MyDBH that tracks all instances, and update MyDBH&#8217;s getInstnace method to accept the name of the db connection you want to create.  In order to do this, either you&#8217;d have to define every database conection&#8217;s credentials in the MyDBH class, create a separate class that the MyDBH extends for storing DB configuration, create a configuration file that can be included to obtain an instances&#8217;s credentials, or create an object that stores this sort of information.</p>
<p>This example just creates a dbconnection factory because I&#8217;m trying to keep this short and sweet (and also show the factory pattern at the same time):<br />
< ?php<br />
// using the "i" prefix to indicate its an interface...<br />
interface iDbConnection {<br />
  public function getDbInfo();<br />
  // anything else...<br />
}</p>
<p>// Could make this abstract too obviously....<br />
class DbConnectionFactory {<br />
  // just an example for factory as well...<br />
  public static function getInstance($db_connection) {<br />
    if(class_exists($db_connection) &#038;&#038; method_exists()) {<br />
       $dbConnection = new $db_connection;<br />
       if(!($dbConnection instanceof iDbConnection)) {<br />
         throw new Exception("Invalid DB Connection Requested!");<br />
       }<br />
       // do whatever<br />
       return $dbConnection->getDbInfo();<br />
    }<br />
  }<br />
}</p>
<p>class AdvertisementDbConnection implements iDbConnection {<br />
  private $db_info = array(&#8220;host&#8221; => &#8220;localhost&#8221;, &#8220;dbname&#8221; => &#8220;myAdvertisementDB&#8221;, &#8220;username&#8221; => &#8220;myAdvertisementDB_user&#8221;, &#8220;password&#8221; => &#8220;myAdvertisementDB_password&#8221;);</p>
<p>  // whatever else </p>
<p>  public function getDbInfo() {<br />
    return $this->db_info;<br />
  }<br />
}</p>
<p>class MyDBH {<br />
  // changed this to an array&#8230;<br />
  private static $instances = array();</p>
<p>  // &#8230;&#8230;.<br />
  //<br />
  // same logic/methods/properties from above&#8230;<br />
  //<br />
  // &#8230;&#8230;.</p>
<p>  public static function getInstance($db_connection = &#8216;default&#8217;) {<br />
    // keep it all consistent&#8230;<br />
    $db_connection = strtolower($db_connection);<br />
    if(!isset(self::$instances[$db_connection])) {<br />
      $db_info = (strtolower($db_connection) == &#8216;default&#8217; ? null : DbConnectionFactory::getInstance($db_connection));<br />
      self::$instances[$db_connection] = new MyDBH($db_info);<br />
    }<br />
    return self::$instances[$db_connection];<br />
  }<br />
}</p>
<p>// same ole, same ole..<br />
$dbh = MyDBH::getInstance();</p>
<p>// get advertisement<br />
$dbh = MyDBH::getInstance(&#8216;AdvertisementDbConnection&#8217;);</p>
<p>While crude, this shows a basic example..  You could improve this in many, many different ways.  Up to you how to do this.</p>
<p>Also, I&#8217;d like to point out that multiple user&#8217;s on a page does not affect the singleton since PHP creates a new thread per user that accesses your page.  In other words, the logic that checks for &#8220;current state&#8221; to display a page, and will still use everything you would normally expect.</p>
<p>Note: I didn&#8217;t actually test the above so feel free to make improvements where needed!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on New Toys and a New Mind by Milica</title>
		<link>http://phpadvocate.com/blog/2012/02/new-toys-and-a-new-mind/comment-page-1/#comment-2340</link>
		<dc:creator>Milica</dc:creator>
		<pubDate>Mon, 30 Apr 2012 09:00:55 +0000</pubDate>
		<guid isPermaLink="false">http://phpadvocate.com/blog/?p=381#comment-2340</guid>
		<description>In the last few years we have seen our customer base shift aoslmt exclusively from RDBMSs (MySQL, to a lesser degree PostgreSQL, and a slow but steady increase in Oracle) to numerous NoSQL solutions.  (Full disclosure – I am an Architect in the Professional Services group at RightScale.)  The customer use cases for these NoSQL implementations have expanded rapidly as well.  Initial deployments focused on social gaming environments, but NoSQL solutions have become more and more prevalent in classic web applications and even in some enterprise installations.  You mention that you are going to investigate MongoDB first, and from the data I have seen this would appear to be good place to start.  We get more requests for MongoDB solutions than any other NoSQL option at this point.  The other ones we see (in order of decreasing demand) are:  Membase, Redis, and Riak, with surprisingly few requests for Cassandra, which initially got quite a bit of attention.</description>
		<content:encoded><![CDATA[<p>In the last few years we have seen our customer base shift aoslmt exclusively from RDBMSs (MySQL, to a lesser degree PostgreSQL, and a slow but steady increase in Oracle) to numerous NoSQL solutions.  (Full disclosure – I am an Architect in the Professional Services group at RightScale.)  The customer use cases for these NoSQL implementations have expanded rapidly as well.  Initial deployments focused on social gaming environments, but NoSQL solutions have become more and more prevalent in classic web applications and even in some enterprise installations.  You mention that you are going to investigate MongoDB first, and from the data I have seen this would appear to be good place to start.  We get more requests for MongoDB solutions than any other NoSQL option at this point.  The other ones we see (in order of decreasing demand) are:  Membase, Redis, and Riak, with surprisingly few requests for Cassandra, which initially got quite a bit of attention.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Served from: phpadvocate.com @ 2012-05-20 10:03:56 by W3 Total Cache -->
