<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.1.2" -->
<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/"
	>

<channel>
	<title>Webmaster-Talk.com Blog</title>
	<link>http://www.webmaster-talk.com/blog</link>
	<description></description>
	<pubDate>Tue, 29 May 2007 18:21:20 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.1.2</generator>
	<language>en</language>
			<item>
		<title>A Webmaster-Talk Blog Update</title>
		<link>http://www.webmaster-talk.com/blog/30/a-webmaster-talk-blog-update</link>
		<comments>http://www.webmaster-talk.com/blog/30/a-webmaster-talk-blog-update#comments</comments>
		<pubDate>Tue, 29 May 2007 17:28:27 +0000</pubDate>
		<dc:creator>Tim Schroeder</dc:creator>
		
		<category><![CDATA[Other]]></category>

		<guid isPermaLink="false">http://www.webmaster-talk.com/blog/30/a-webmaster-talk-blog-update</guid>
		<description><![CDATA[Hey guys and gals. Sorry for the lack of updates to this blog. I guess the moral of the story is to not start something if you can&#8217;t finish it! Other projects took priority over the WT blog but I do hope to get things sorted out shortly.
I originally signed up a few Webmaster-Talk members [...]]]></description>
			<content:encoded><![CDATA[<p>Hey guys and gals. Sorry for the lack of updates to this blog. I guess the moral of the story is to not start something if you can&#8217;t finish it! Other projects took priority over the WT blog but I do hope to get things sorted out shortly.</p>
<p>I originally signed up a few Webmaster-Talk members to help contribute articles but didn&#8217;t finish adding their profile pages etc so they understandably have not been submitting more articles.</p>
<p>I&#8217;m trying to think about what approach to take with this blog. Should I basically just focus on webmaster industry news? Should I just review webmaster related tools? Or should I continue with a mix of several webmaster related topics?</p>
<p>I may decide to just keep one (paid) guest blogger per category and then add additional posts of my own.</p>
<p>Anyway, I&#8217;ll keep you updated here and let you know what I decide to do with the blog. Meanwhile, you might be interested in reading my new <a href="http://www.emonetized.com">eMonetized blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webmaster-talk.com/blog/30/a-webmaster-talk-blog-update/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A Couple Of Benefits Of Using Digg</title>
		<link>http://www.webmaster-talk.com/blog/26/a-couple-of-benefits-of-using-digg</link>
		<comments>http://www.webmaster-talk.com/blog/26/a-couple-of-benefits-of-using-digg#comments</comments>
		<pubDate>Mon, 26 Mar 2007 15:03:17 +0000</pubDate>
		<dc:creator>Webspace</dc:creator>
		
		<category><![CDATA[Other]]></category>

		<guid isPermaLink="false">http://www.webmaster-talk.com/blog/26/a-couple-of-benefits-of-using-digg</guid>
		<description><![CDATA[Many of us use Digg as part of our overall social media optimization effort. Digg is a great way to share your content and get your content beyond the confines of your site. Sharing articles on Digg will help you get traffic to your website. I started seeing visitors to my website from Digg within [...]]]></description>
			<content:encoded><![CDATA[<p>Many of us use Digg as part of our overall social media optimization effort. Digg is a great way to share your content and get your content beyond the confines of your site. Sharing articles on Digg will help you get traffic to your website. I started seeing visitors to my website from Digg within the first day of submitting articles to the site. Furthermore every article I submitted received some readership. One of the great benefits of using Digg is the traffic. I&#8217;ll post a bit of how to information for using Digg when I have developed some SMM techniques for Digg.</p>
<p>The other great use for Digg is conquering writers block. If you can&#8217;t think of anything to write about just browse that latest diggs and for some ideas. When I visit Digg I find articles that I can at least make some intelligent feedback about. Note also that finding blog articles on Digg and tracking back to them is a great way to get traffic and quality backlinks to your website. By providing useful feedback you are promoting your own material at the same time. That&#8217;s why social media is so great.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webmaster-talk.com/blog/26/a-couple-of-benefits-of-using-digg/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHP / MySQL Connection Class</title>
		<link>http://www.webmaster-talk.com/blog/17/php-mysql-connection-class</link>
		<comments>http://www.webmaster-talk.com/blog/17/php-mysql-connection-class#comments</comments>
		<pubDate>Wed, 28 Feb 2007 01:53:52 +0000</pubDate>
		<dc:creator>mgraphic</dc:creator>
		
		<category><![CDATA[Coding]]></category>

		<category><![CDATA[Other]]></category>

		<guid isPermaLink="false">http://www.webmaster-talk.com/blog/17/php-mysql-connection-class</guid>
		<description><![CDATA[The PHP scripting language is a great tool for new people who build websites and learning programming syntax. Most people who use PHP only skim the surface of what the language can do and don’t learn how to use PHP in more of a way to help their code become easier to accomplish backend tasks.
PHP [...]]]></description>
			<content:encoded><![CDATA[<p>The PHP scripting language is a great tool for new people who build websites and learning programming syntax. Most people who use PHP only skim the surface of what the language can do and don’t learn how to use PHP in more of a way to help their code become easier to accomplish backend tasks.</p>
<p>PHP newbie’s usually use it to display output, and find themselves needing to keep it complex and inefficient by pasting code over and over each time they perform similar duties. For example, those who want to connect to a MySQL database to pull or write data will keep adding a block of code to connect to the database each time they try to perform a task. This can become tiresome and really confuse the main function of what they are trying to accomplish.</p>
<p>The power in programming comes from building other functions and classes (OOP, Object Oriented Programming) to do the tedious grunt work for you, so your main body scripts can just focus on the task at hand. If you find yourself doing a lot of copy and paste that should be more automated, reevaluate your code, and keep those types of tasks nested in a function.</p>
<p>For this example, we will build a class script that will handle MySQL queries in an easy and simple way.</p>
<p><strong>The Class Script:</strong><br />
<code>count_queries = 0;<br />
      $this-&gt;total_query_time = 0;<br />
      $this-&gt;connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD, DB_DATABASE);<br />
      if (!$this-&gt;db_isconnected) $this-&gt;set_error(&#8217;0&#8242;, &#8216;mysqlClass Error: MySQL DB Not Connected&#8217;);<br />
    } </p>
<p>    private function connect($db_server, $db_username, $db_password, $db_database) { </p>
<p>      $this-&gt;database = $db_database;<br />
      $this-&gt;link = @mysql_connect($db_server, $db_username, $db_password, false); </p>
<p>      if ($this-&gt;link) { </p>
<p>        if (@mysql_select_db($db_database, $this-&gt;link)) {<br />
          $this-&gt;db_isconnected = true;<br />
          return true;<br />
        } else {<br />
          $this-&gt;set_error(mysql_errno(),mysql_error(), $zp_real);<br />
          return false;<br />
        } </p>
<p>      } else { </p>
<p>        $this-&gt;set_error(mysql_errno(),mysql_error());<br />
        return false;<br />
      }<br />
    } </p>
<p>    private function set_error($err_num, $err_text) { </p>
<p>      echo $err_num . &#8216; &#8216; . $err_text;<br />
      die();<br />
    } </p>
<p>    public function Execute($sql, $limit = false) { </p>
<p>      if ($limit) $sql = $sql . &#8216; LIMIT &#8216; . $limit;<br />
      $time_start = explode(&#8217; &#8216;, microtime());<br />
      $obj = new mysqlClassResult;<br />
      $db_resource = @mysql_query($sql, $this-&gt;link);<br />
      if (!$db_resource) $this-&gt;set_error(@mysql_errno($this-&gt;link),@mysql_error($this-&gt;link));<br />
      $obj-&gt;resource = $db_resource;<br />
      $obj-&gt;cursor = 0;<br />
      if ($obj-&gt;RecordCount() &gt; 0) { </p>
<p>        $obj-&gt;EOF = false;<br />
        $result_array = @mysql_fetch_array($db_resource);<br />
        if ($result_array) { </p>
<p>          while (list($key, $value) = each($result_array)) { </p>
<p>            if (!ereg(&#8217;^[0-9]&#8217;, $key)) $obj-&gt;fields[$key] = $value;<br />
          }<br />
          $obj-&gt;EOF = false; </p>
<p>        } else { </p>
<p>          $obj-&gt;EOF = true;<br />
        } </p>
<p>      } else { </p>
<p>        $obj-&gt;EOF = true;<br />
      } </p>
<p>      $time_end = explode (&#8217; &#8216;, microtime());<br />
      $query_time = $time_end[1]+$time_end[0]-$time_start[1]-$time_start[0];<br />
      $this-&gt;total_query_time += $query_time;<br />
      $this-&gt;count_queries++;<br />
      return($obj);<br />
    } </p>
<p>    public function InsertID() {<br />
      return @mysql_insert_id($this-&gt;link);<br />
    } </p>
<p>    public function QueryCount() {<br />
      return $this-&gt;count_queries;<br />
    } </p>
<p>    public function QueryTime() {<br />
      return $this-&gt;total_query_time;<br />
    }<br />
  } </p>
<p>  class mysqlClassResult { </p>
<p>    public function MoveNext() { </p>
<p>      $this-&gt;cursor++;<br />
      $result_array = @mysql_fetch_array($this-&gt;resource);<br />
      if (!$result_array) {<br />
        $this-&gt;EOF = true;<br />
      } else {<br />
        while (list($key, $value) = each($result_array)) {<br />
          if (!ereg(&#8217;^[0-9]&#8217;, $key)) {<br />
            $this-&gt;fields[$key] = $value;<br />
          }<br />
        }<br />
      }<br />
    } </p>
<p>    public function RecordCount() { </p>
<p>      return @mysql_num_rows($this-&gt;resource);<br />
    }<br />
  } </p>
<p>?&gt;</code><br />
Now we need to assign the values to connect to the database. We can use the <a href="http://www.php.net/manual/function.define.php"><strong>define()</strong></a> function in an included configuration file. What makes <strong>define()</strong> work nice in this case, is that defined constants are auto global (they can be accessed in any linked function).</p>
<p><strong>The Configuration Script:</strong><br />
<code>&lt;?php</p>
<p>  define(&#8217;DB_SERVER&#8217;, &#8216;localhost&#8217;);<br />
  define(&#8217;DB_SERVER_USERNAME&#8217;, &#8221;);<br />
  define(&#8217;DB_SERVER_PASSWORD&#8217;, &#8221;);<br />
  define(&#8217;DB_DATABASE&#8217;, &#8216;clcag&#8217;);</p>
<p>?&gt;</code></p>
<p>Now once we include the configuration and class script files in our main script file, we can now create a new instance of the class object.</p>
<p>
<code>$db = &amp;new mysqlClass();</code></p>
<p>Now if we want to fetch some data from the database, we just use our class object to assign the values to a new variable.</p>
<p>
<code>$test = $db-&gt;Execute('SELECT * FROM table_name');</code></p>
<p>Now to iterate through the returned rows, we just reference the fields by field names. By evaluating if the object var EOF is false, we can determine when the last row is returned. After each iteration, we move the pointer to the next row.</p>
<p>
<code>while(!$test-&gt;EOF){<br />
  print_r($test);<br />
  $test-&gt;MoveNext();<br />
}</code></p>
<p>We can easily count how many rows were returned by calling a custom function.</p>
<p>
<code>echo $test-&gt;RecordCount();</code></p>
<p>We can insert a new row, and then find the last ID inserted in the auto-increment field.</p>
<p>
<code>$db-&gt;Execute('INSERT INTO table_name (field1, field2, field3) VALUES("a", "b", "c")'); </p>
<p>Last Inserted ID: InsertID(); ?&gt;</code></p>
<p>At the end of our script, we can display the total number of queries and total time in seconds it all took.</p>
<p>
<code>QueryCount(); ?&gt; Queries in QueryTime(); ?&gt; second(s)</code></p>
<p></p>
<p>This code is a customized version of the Query Factory class script originally written by the developers of Zen-Cart</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webmaster-talk.com/blog/17/php-mysql-connection-class/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
