<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>So Many Tools, So Little Time</title>
	
	<link>http://www.somanytoolssolittletime.com</link>
	<description>Innovating through the Web's Model T Era</description>
	<pubDate>Thu, 18 Dec 2008 15:44:32 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/SoManyToolsSoLittleTime" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>PHP Extensions: Creating Constants</title>
		<link>http://feedproxy.google.com/~r/SoManyToolsSoLittleTime/~3/b81YNKdgnok/</link>
		<comments>http://www.somanytoolssolittletime.com/php-extensions-creating-constants/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 15:44:32 +0000</pubDate>
		<dc:creator>BlakeS</dc:creator>
		
		<category><![CDATA[C]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[extension]]></category>

		<guid isPermaLink="false">http://www.somanytoolssolittletime.com/?p=48</guid>
		<description><![CDATA[When creating extensions, it is possible to provide the end-programmer with new constants. Such constants may be then used as parameters to extension functions or to compare against return values. The following table shows the macros that are available:


Macro
Description


REGISTER_LONG_CONSTANT(name, value, flags)REGISTER_MAIN_LONG_CONSTANT(name, value, flags)
Registers a new constant of type long.


REGISTER_DOUBLE_CONSTANT(name, value, flags)REGISTER_MAIN_DOUBLE_CONSTANT(name, value, flags)
Registers a new [...]]]></description>
			<content:encoded><![CDATA[<p>When creating extensions, it is possible to provide the end-programmer with new constants. Such constants may be then used as parameters to extension functions or to compare against return values. The following table shows the macros that are available:</p>
<table cellpadding="4" cellspacing="2">
<tr>
<th valign="top">Macro</th>
<th valign="top">Description</th>
</tr>
<tr>
<td valign="top">REGISTER_LONG_CONSTANT(name, value, flags)<br />REGISTER_MAIN_LONG_CONSTANT(name, value, flags)</td>
<td valign="top">Registers a new constant of type long.</td>
</tr>
<tr>
<td valign="top">REGISTER_DOUBLE_CONSTANT(name, value, flags)<br />REGISTER_MAIN_DOUBLE_CONSTANT(name, value, flags)</td>
<td valign="top">Registers a new constant of type double.</td>
</tr>
<tr>
<td valign="top">REGISTER_STRING_CONSTANT(name, value, flags)<br />REGISTER_MAIN_STRING_CONSTANT(name, value, flags)</td>
<td valign="top">Registers a new constant of type string. The specified string must reside in Zend&#8217;s internal memory.</td>
</tr>
<tr>
<td valign="top">REGISTER_STRINGL_CONSTANT(name, value, length, flags)<br /> REGISTER_MAIN_STRINGL_CONSTANT(name, value, length, flags)</td>
<td valign="top">Registers a new constant of type string. The string length is explicitly set to length. The specified string must reside in Zend&#8217;s internal memory.</td>
</tr>
</table>
<p><em>Table 9: Macros for Creating Constants</em></p>
<p>There are two types of macros – REGISTER_*_CONSTANT and REGISTER_MAIN_*_CONSTANT. The former type creates constants bound to the extension module. These constants are dumped from the symbol table as soon as the module that registered the constant is unloaded from memory. The latter type creates constants that persist in the symbol table independently of the module.</p>
<p>Each of the macros above accepts a name and value (and a length for the STRINGL versions) and a set of flags. The flags available for use are:</p>
<ul>
<li>CONST_CS – This constant’s name is to be treated as case sensitive</li>
<li>CONST_PERSISTENT – This constant is persistent and won’t be forgotten when the current process carrying this constant is shut down</li>
</ul>
<p>A simple usage example is shown below:</p>

<div id="wp_codebox"><table width="100%" ><tr id="p482"><td width="1%" class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p48code2"><pre class="c"><span style="color: #666666; font-style: italic;">// register a new constant of type &quot;long&quot;</span>
REGISTER_LONG_CONSTANT<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;MY_CONSTANT&quot;</span>, <span style="color: #cc66cc;">1234</span>, CONST_CS | CONST_PERSISTENT<span style="color: #009900;">&#41;</span>;</pre></td></tr></table></div>


<p><a href="http://feedads.g.doubleclick.net/~a/iYmf3kzdWQ7W1XEoNoKyvFHXyFw/0/da"><img src="http://feedads.g.doubleclick.net/~a/iYmf3kzdWQ7W1XEoNoKyvFHXyFw/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/iYmf3kzdWQ7W1XEoNoKyvFHXyFw/1/da"><img src="http://feedads.g.doubleclick.net/~a/iYmf3kzdWQ7W1XEoNoKyvFHXyFw/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/SoManyToolsSoLittleTime/~4/b81YNKdgnok" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.somanytoolssolittletime.com/php-extensions-creating-constants/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.somanytoolssolittletime.com/php-extensions-creating-constants/</feedburner:origLink></item>
		<item>
		<title>Twhirl on Ubuntu</title>
		<link>http://feedproxy.google.com/~r/SoManyToolsSoLittleTime/~3/wFZtRdNYuVw/</link>
		<comments>http://www.somanytoolssolittletime.com/twhirl-on-ubuntu/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 16:44:29 +0000</pubDate>
		<dc:creator>BlakeS</dc:creator>
		
		<category><![CDATA[tools]]></category>

		<category><![CDATA[twhirl]]></category>

		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.somanytoolssolittletime.com/?p=37</guid>
		<description><![CDATA[For the past three or four days, I&#8217;ve been completely disconnected from the rest of the world because I couldn&#8217;t get Twhirl 0.8.7 to work on my Ubuntu 8.04 computer. I tried several methods to use the updated AIR file, but had no success. I didn&#8217;t realize when I started that not only did I [...]]]></description>
			<content:encoded><![CDATA[<p>For the past three or four days, I&#8217;ve been completely disconnected from the rest of the world because I couldn&#8217;t get Twhirl 0.8.7 to work on my Ubuntu 8.04 computer. I tried several methods to use the updated AIR file, but had no success. I didn&#8217;t realize when I started that not only did I need to upgrade Twhirl, but I also need to update to the latest Adobe Air for Ubuntu.</p>
<p>Here are the steps I used to finally get it working:</p>
<ol>
<li>Uninstall Adobe Air alpha</li>
<li>Install Adobe Air beta</li>
<li>Install Twhirl 0.8.7</li>
</ol>
<p>Seems obvious enough, right? Well, unfortunately I couldn&#8217;t find an obvious way to uninstall Adobe Air. I looked online, tried to use &#8211;help on the command line for the Adobe Air alpha binary, and did a quick Google. Being in a hurry (because who isn&#8217;t in a hurry to reconnect on Twitter?), I just started trying random commands. Magically, it worked. Here&#8217;s what I did:</p>
<pre>
sudo ./adobeair_linux_a1_033108.bin -uninstall
sudo ./adobeair_linux_b1_091508.bin
</pre>
<p>Then double-clicking the AIR file for Twhirl 0.8.7 worked like a charm. The only remaining caveat is to make sure you use the Twhirl 0.8.7 version that was released for Adobe Air 1.1 (<a href="http://www.twhirl.org/files/twhirl-0.8.7-air11.air">http://www.twhirl.org/files/twhirl-0.8.7-air11.air</a>) and not the general release version targeting Adobe Air 1.5.</p>
<p>The Adobe Air beta for Linux can be found here: <a href="http://labs.adobe.com/downloads/air_linux.html">http://labs.adobe.com/downloads/air_linux.html</a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/2jvhivkbPSKbz-F20Vl9V7pcfIY/0/da"><img src="http://feedads.g.doubleclick.net/~a/2jvhivkbPSKbz-F20Vl9V7pcfIY/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/2jvhivkbPSKbz-F20Vl9V7pcfIY/1/da"><img src="http://feedads.g.doubleclick.net/~a/2jvhivkbPSKbz-F20Vl9V7pcfIY/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/SoManyToolsSoLittleTime/~4/wFZtRdNYuVw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.somanytoolssolittletime.com/twhirl-on-ubuntu/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.somanytoolssolittletime.com/twhirl-on-ubuntu/</feedburner:origLink></item>
		<item>
		<title>PHP Extensions: Implementing the Extension</title>
		<link>http://feedproxy.google.com/~r/SoManyToolsSoLittleTime/~3/5NwAsC4NQnI/</link>
		<comments>http://www.somanytoolssolittletime.com/php-extensions-implementing-the-extension/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 03:58:01 +0000</pubDate>
		<dc:creator>BlakeS</dc:creator>
		
		<category><![CDATA[C]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[extension]]></category>

		<guid isPermaLink="false">http://www.somanytoolssolittletime.com/?p=30</guid>
		<description><![CDATA[So far, we haven’t examined the source or header files that were created by the ext_skel script. Now it’s time to dive in and make them useful. The header file is a very standard PHP extension header  file and requires no modification for this particular extension. The header file will be revisited in the [...]]]></description>
			<content:encoded><![CDATA[<p>So far, we haven’t examined the source or header files that were created by the ext_skel script. Now it’s time to dive in and make them useful. The header file is a very standard PHP extension header  file and requires no modification for this particular extension. The header file will be revisited in the full example later in this document.</p>
<p>The implementation file, first_test.c, must be edited to provide the desired functionality. To begin, locate the implementation of the calcpi function. Initially, the implementation looks like the following:</p>

<div id="wp_codebox"><table width="100%" ><tr id="p308"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p30code8"><pre class="c"><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#123;</span> proto <span style="color: #993333;">double</span> calcpi<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> iterations<span style="color: #009900;">&#41;</span>
    Calculate Pi <span style="color: #339933;">*/</span>
PHP_FUNCTION<span style="color: #009900;">&#40;</span>calcpi<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
     <span style="color: #993333;">int</span> argc <span style="color: #339933;">=</span> ZEND_NUM_ARGS<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
     <span style="color: #993333;">long</span> iterations;
&nbsp;
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>zend_parse_parameters<span style="color: #009900;">&#40;</span>argc TSRMLS_CC, <span style="color: #ff0000;">&quot;l&quot;</span>, <span style="color: #339933;">&amp;</span>iterations<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> FAILURE<span style="color: #009900;">&#41;</span>
          <span style="color: #b1b100;">return</span>;
&nbsp;
     php_error<span style="color: #009900;">&#40;</span>E_WARNING, <span style="color: #ff0000;">&quot;calcpi: not yet implemented&quot;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
<span style="color: #808080; font-style: italic;">/* }}} */</span></pre></td></tr></table></div>

<p><em>Code Fragment 4: Unedited implementation of the calcpi() function.</em></p>
<p>Lines 1, 2 and 13 are comments that provide some human readable breaks and documentation within the source. Line 3 is the function prototype, simplified by a C macro. Lines 5 and 6 declare some required local variables and line 11 is the line that provides the warning message indicating that the function is not yet implemented. The most valuable line that was automatically generated is line 8. This single line is the function that ensures that the parameters passed from the PHP script are consistent with the function prototype and then populates the local C variables appropriately. This function will be discussed in greater detail later.</p>
<p>To make this function actually do what we want, we must provide a real implementation and remove the extraneous warning. Using a simplistic PI calculation algorithm, the function becomes:</p>

<div id="wp_codebox"><table width="100%" ><tr id="p309"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre></td><td class="code" id="p30code9"><pre class="c"> <span style="color: #808080; font-style: italic;">/* {{{ proto double calcpi(int iterations)
    Calculate Pi */</span>
 PHP_FUNCTION<span style="color: #009900;">&#40;</span>calcpi<span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
     <span style="color: #993333;">int</span> argc <span style="color: #339933;">=</span> ZEND_NUM_ARGS<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
     <span style="color: #993333;">long</span> iterations;
     <span style="color: #993333;">int</span> index, hits;
     <span style="color: #993333;">double</span> randx, randy, distance, value;
&nbsp;
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>zend_parse_parameters<span style="color: #009900;">&#40;</span>argc TSRMLS_CC, <span style="color: #ff0000;">&quot;l&quot;</span>, <span style="color: #339933;">&amp;</span>iterations<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> FAILURE<span style="color: #009900;">&#41;</span>
          <span style="color: #b1b100;">return</span>;
&nbsp;
     hits <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span>;
     <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span> index <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span>; index &lt; iterations; index<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#123;</span>
       randx <span style="color: #339933;">=</span> rand<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
       randy <span style="color: #339933;">=</span> rand<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
       randx <span style="color: #339933;">/=</span> RAND_MAX;
       randy <span style="color: #339933;">/=</span> RAND_MAX;
       distance <span style="color: #339933;">=</span> sqrt<span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span> randx <span style="color: #339933;">*</span> randx <span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>randy <span style="color: #339933;">*</span> randy <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>;
&nbsp;
       <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> distance &lt;<span style="color: #339933;">=</span> <span style="color: #cc66cc;">1.0</span> <span style="color: #009900;">&#41;</span>
       <span style="color: #009900;">&#123;</span>
          hits<span style="color: #339933;">++</span>;
       <span style="color: #009900;">&#125;</span>
       value <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">double</span><span style="color: #009900;">&#41;</span> hits <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">double</span><span style="color: #009900;">&#41;</span> index <span style="color: #009900;">&#41;</span>;
       value <span style="color: #339933;">*=</span> <span style="color: #cc66cc;">4.0</span>;
     <span style="color: #009900;">&#125;</span>
&nbsp;
     value <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">double</span><span style="color: #009900;">&#41;</span> hits <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">double</span><span style="color: #009900;">&#41;</span> iterations <span style="color: #009900;">&#41;</span>;
     value <span style="color: #339933;">*=</span> <span style="color: #cc66cc;">4.0</span>;
     RETVAL_DOUBLE<span style="color: #009900;">&#40;</span> value <span style="color: #009900;">&#41;</span>;
 <span style="color: #009900;">&#125;</span>
 <span style="color: #808080; font-style: italic;">/* }}} */</span></pre></td></tr></table></div>

<p><em>Code Fragment 5: Full implementation of the calcpi() function.</em><br />
As can be seen from the above code, the warning message has been removed and a simple PI<br />
calculation algorithm has been added. The most significant change from the extension perspective is<br />
line 35, which assigns the return value and indicates its type as DOUBLE.</p>
<p>Now calling the function:</p>
<pre>
echo '<? print( calcpi( 10000 ) . "\n" ); ?>' | ./sapi/cli/php
</pre>
<p>Returns the following (or similar, based on the calculated value):</p>
<pre>
3.15
</pre>
<p>The implementation for the reverse function is below. Note that none of the implementations for this test extension are to be considered models for efficient C programming.</p>

<div id="wp_codebox"><table width="100%" ><tr id="p3010"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code" id="p30code10"><pre class="c"> <span style="color: #808080; font-style: italic;">/* {{{ proto string reverse(string input)
    Reverse the input string */</span>
 PHP_FUNCTION<span style="color: #009900;">&#40;</span>reverse<span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
     <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>input <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">NULL</span>;
     <span style="color: #993333;">int</span> argc <span style="color: #339933;">=</span> ZEND_NUM_ARGS<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
     <span style="color: #993333;">int</span> input_len;
     <span style="color: #993333;">char</span><span style="color: #339933;">*</span> workstr;
     <span style="color: #993333;">int</span> index;
&nbsp;
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>zend_parse_parameters<span style="color: #009900;">&#40;</span>argc TSRMLS_CC, <span style="color: #ff0000;">&quot;s&quot;</span>, <span style="color: #339933;">&amp;</span>input, <span style="color: #339933;">&amp;</span>input_len<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> FAILURE<span style="color: #009900;">&#41;</span>
          <span style="color: #b1b100;">return</span>;
&nbsp;
     workstr <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> emalloc<span style="color: #009900;">&#40;</span>input_len <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>;
     memset<span style="color: #009900;">&#40;</span> workstr, <span style="color: #cc66cc;">0</span>, input_len <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span>;
     <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span> index <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span>; index &lt; input_len; index<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#123;</span>
       workstr<span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> input<span style="color: #009900;">&#91;</span>input_len <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span> index <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span>;
     <span style="color: #009900;">&#125;</span>
&nbsp;
    RETVAL_STRING<span style="color: #009900;">&#40;</span> workstr, <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span>;
&nbsp;
     efree<span style="color: #009900;">&#40;</span> workstr <span style="color: #009900;">&#41;</span>;
 <span style="color: #009900;">&#125;</span>
 <span style="color: #808080; font-style: italic;">/* }}} */</span></pre></td></tr></table></div>

<p><em>Code Fragment 6: Implementation of the reverse() function.</em></p>
<p>This function demonstrates two things. First, this function demonstrates using the emalloc and efree memory management routines in place of the standard C malloc/free functions. These memory management routines are preferred when developing PHP extensions as they allow the Zend engine to manage the entire memory pool which allows the engine to determine when a block is in use and automatically free unused blocks and blocks with lost references, preventing memory leaks. There are several more memory management routines available for your use, all of which will be discussed later.</p>
<p>The second concept demonstrated in the above example is how to return a string to PHP. The RETVAL_STRING macro accepts two parameters, the string itself (character pointer) and a Boolean flag indicating whether or not to duplicate the string using estrdup. In the above example, I allocate the memory for a working buffer, create the reversed string and then set the return value using the flag to duplicate the string. Lastly, I free the working buffer. Alternately, I could have simply allocated the working buffer and returned it directly without duplication, but I personally feel it is better to free memory I allocate for internal use and let the Zend engine deal with freeing its own internal memory allocation that results from using the RETVAL_STRING macro as I did above. That said, if I were absolutely interested in performance, I would eliminate the additional memory allocation and buffer copying and simply note my reasoning in the code.</p>
<p>The implementation of the uniquechars function is below.</p>

<div id="wp_codebox"><table width="100%" ><tr id="p3011"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
</pre></td><td class="code" id="p30code11"><pre class="c"><span style="color: #808080; font-style: italic;">/* {{{ proto array uniquechars(string input [, bool case_sensitive])
   Return the unique characters in the input string */</span>
PHP_FUNCTION<span style="color: #009900;">&#40;</span>uniquechars<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
     <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>input <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">NULL</span>;
     <span style="color: #993333;">int</span> argc <span style="color: #339933;">=</span> ZEND_NUM_ARGS<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
     <span style="color: #993333;">int</span> input_len;
     zend_bool case_sensitive;
     <span style="color: #993333;">char</span><span style="color: #339933;">*</span> workbuf;
     <span style="color: #993333;">int</span> index, work_index;
&nbsp;
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>zend_parse_parameters<span style="color: #009900;">&#40;</span>argc TSRMLS_CC, <span style="color: #ff0000;">&quot;s|b&quot;</span>, <span style="color: #339933;">&amp;</span>input, <span style="color: #339933;">&amp;</span>input_len, <span style="color: #339933;">&amp;</span>case_sensitive<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> FAILURE<span style="color: #009900;">&#41;</span>
         <span style="color: #b1b100;">return</span>;
&nbsp;
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> argc <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#123;</span>
       case_sensitive <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span>;
     <span style="color: #009900;">&#125;</span>
     work_index <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span>;
     workbuf <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> emalloc<span style="color: #009900;">&#40;</span> input_len <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span>;
     memset<span style="color: #009900;">&#40;</span> workbuf, <span style="color: #cc66cc;">0</span>, input_len <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span>;
     <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span> index <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span>; index &lt; input_len; index<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#123;</span>
       <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> case_sensitive <span style="color: #009900;">&#41;</span>
       <span style="color: #009900;">&#123;</span>
         <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>strchr<span style="color: #009900;">&#40;</span> workbuf, input<span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#123;</span>
            workbuf<span style="color: #009900;">&#91;</span>work_index<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> input<span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span>;
            work_index<span style="color: #339933;">++</span>;
         <span style="color: #009900;">&#125;</span>
       <span style="color: #009900;">&#125;</span>
       <span style="color: #b1b100;">else</span>
       <span style="color: #009900;">&#123;</span>
         <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>strchr<span style="color: #009900;">&#40;</span> workbuf, tolower<span style="color: #009900;">&#40;</span> input<span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#123;</span>
              workbuf<span style="color: #009900;">&#91;</span>work_index<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> tolower<span style="color: #009900;">&#40;</span> input<span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span>;
              work_index<span style="color: #339933;">++</span>;
           <span style="color: #009900;">&#125;</span>
         <span style="color: #009900;">&#125;</span>
       <span style="color: #009900;">&#125;</span>
&nbsp;
       array_init<span style="color: #009900;">&#40;</span> return_value <span style="color: #009900;">&#41;</span>;
       <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span> index <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span>; index &lt; input_len; index<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span>
       <span style="color: #009900;">&#123;</span>
         <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> workbuf<span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\0</span>'</span> <span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#123;</span>
           add_next_index_stringl<span style="color: #009900;">&#40;</span> return_value, <span style="color: #339933;">&amp;</span>workbuf<span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span>;
         <span style="color: #009900;">&#125;</span>
       <span style="color: #009900;">&#125;</span>
&nbsp;
      efree<span style="color: #009900;">&#40;</span> workbuf <span style="color: #009900;">&#41;</span>;
 <span style="color: #009900;">&#125;</span>
 <span style="color: #808080; font-style: italic;">/* }}} */</span></pre></td></tr></table></div>

<p><em>Code Fragment 7: Implementation of the uniquechars() function.</em></p>
<p>The above function works by first creating a standard C character array containing all of the unique characters in lines 21 through 42. It sets the case_sensitive flag to the default (true) in lines 15 through 18 if the parameter is not passed at all. The really interesting code, though, is in lines 44 through 50 where the PHP array variable is created and populated.</p>
<p>Line 44 initializes the return value as an array. In the previous two examples, the return_value  variable was used opaquely in the RETVAL_XXX functions, but it is important to note that every function that is prototyped using the PHP_FUNCTION macro has a standard return variable called return_value. It is easiest to manipulate this value using the RETVAL_XXX or RETURN_XXX macros, but those macros do not provide array functionality.</p>
<p>Once the array variable is initialized, items are added to the array (in this example) using the add_next_index_stringl function. This function takes four parameters:</p>
<ol>
<li>The array variable itself</li>
<li>A character pointer representing the string to add</li>
<li>The length of the string being added</li>
<li>Whether to duplicate the string being added</li>
</ol>
<p>There are many array manipulation functions available, all of which are discussed in depth later in this document.</p>
<p>Now that the new extension is fully implemented, it becomes possible to test it in PHP. The following is a sample PHP script and the output generated by the script.</p>

<div id="wp_codebox"><table width="100%" ><tr id="p3012"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code" id="p30code12"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
   <span style="color: #990000;">print</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Calculating PI using 10 iterations: '</span> <span style="color: #339933;">.</span> calcpi<span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">10</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: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #990000;">print</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Calculating PI using 100 iterations: '</span> <span style="color: #339933;">.</span> calcpi<span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">100</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: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #990000;">print</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Calculating PI using 1,000 iterations: '</span> <span style="color: #339933;">.</span> calcpi<span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">1000</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: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #990000;">print</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Calculating PI using 10,000 iterations: '</span> <span style="color: #339933;">.</span> calcpi<span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">10000</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: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #990000;">print</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Calculating PI using 100,000 iterations: '</span> <span style="color: #339933;">.</span> calcpi<span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">100000</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: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #990000;">print</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #990000;">print</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Reverse of &quot;Zend Engine&quot; is &quot;'</span> <span style="color: #339933;">.</span> reverse<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Zend Engine'</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #990000;">print</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #990000;">print</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'The unique characters in &quot;Zend Engine&quot; (case sensitive) are: '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> uniquechars<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Zend Engine'</span> <span style="color: #009900;">&#41;</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: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #990000;">print</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'The unique characters in &quot;Zend Engine&quot; (case insensitive) are: '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> uniquechars<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Zend Engine'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</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: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #990000;">print</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><em>Code Fragment 8: PHP script for testing the first_test extension.</em></p>
<pre>
Calculating  PI  using 10 iterations: 3.2
Calculating  PI  using 100 iterations: 3.2
Calculating  PI  using 1,000 iterations: 3.248
Calculating  PI  using 10,000 iterations: 3.1356
Calculating  PI using 100,000 iterations: 3.1358

Reverse of "Zend Engine" is "enignE dneZ"

The unique characters in "Zend Engine" (case sensitive) are: Z,e,n,d, ,E,g,i
The unique characters in "Zend Engine" (case insensitive) are: z,e,n,d, ,g,i
</pre>
<p><em>Results/Output 1: Output of the test PHP script.</em></p>

<p><a href="http://feedads.g.doubleclick.net/~a/9uOwpvPP_sZ32RsbXF1QptqXL48/0/da"><img src="http://feedads.g.doubleclick.net/~a/9uOwpvPP_sZ32RsbXF1QptqXL48/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/9uOwpvPP_sZ32RsbXF1QptqXL48/1/da"><img src="http://feedads.g.doubleclick.net/~a/9uOwpvPP_sZ32RsbXF1QptqXL48/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/SoManyToolsSoLittleTime/~4/5NwAsC4NQnI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.somanytoolssolittletime.com/php-extensions-implementing-the-extension/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.somanytoolssolittletime.com/php-extensions-implementing-the-extension/</feedburner:origLink></item>
		<item>
		<title>PHP Extensions: Building the Shell</title>
		<link>http://feedproxy.google.com/~r/SoManyToolsSoLittleTime/~3/f6E1ak2xTao/</link>
		<comments>http://www.somanytoolssolittletime.com/php-extensions-building-the-shell/#comments</comments>
		<pubDate>Mon, 15 Dec 2008 03:29:19 +0000</pubDate>
		<dc:creator>BlakeS</dc:creator>
		
		<category><![CDATA[C]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[extension]]></category>

		<guid isPermaLink="false">http://www.somanytoolssolittletime.com/?p=26</guid>
		<description><![CDATA[Navigate to the PHP installation directory, then to theext directory. For example:

  cd /path/to/php-4.x.x/ext

Run the ext_skel script in that directory with no parameters. This is the script that will create the initial files for a new PHP extension. Its parameters are shown in the table below.


&#8211;extname=module
module is the name of your extension


&#8211;proto=file
file contains prototypes [...]]]></description>
			<content:encoded><![CDATA[<p>Navigate to the PHP installation directory, then to theext directory. For example:</p>
<pre>
  cd /path/to/php-4.x.x/ext
</pre>
<p>Run the <em>ext_skel</em> script in that directory with no parameters. This is the script that will create the initial files for a new PHP extension. Its parameters are shown in the table below.</p>
<table>
<tr>
<td>&#8211;extname=module</td>
<td>module is the name of your extension</td>
</tr>
<tr>
<td>&#8211;proto=file</td>
<td>file contains prototypes of functions to create</td>
</tr>
<tr>
<td>&#8211;stubs=file</td>
<td>Leave out also all module specific stuff and write just function stubs with function value declarations and passed argument handling, and function entries and definitions at the end of the file, for copying and pasting into an already existing module.</td>
</tr>
<tr>
<td>&#8211;xml</td>
<td>generate xml documentation to be added  to phpdoc-cvs</td>
</tr>
<tr>
<td>&#8211;skel=dir</td>
<td>path to the skeleton directory</td>
</tr>
<tr>
<td>&#8211;full-xml</td>
<td>generate xml documentation for a self-contained extension (not yet implemented)</td>
</tr>
<tr>
<td>&#8211;no-help</td>
<td>By default, ext_skel creates both comments in the source code and a test function to help first time module writers to get started and testing configuring and compiling their module. This option turns off all such things which may just annoy experienced PHP module coders. Especially useful with the &#8211;stubs parameter.</td>
</tr>
</table>
<p><em>Table 1: Parameters to the ext_skel script.</em></p>
<blockquote><p>NOTE: I suggest you read the README.EXT_SKEL file in the main PHP install path for details about the script.</p></blockquote>
<p>For our first extension, we will be creating some simple functions:</p>
<p><strong>double calcpi( int iterations )</strong><br />
This function returns an approximation of pi. The algorithm is a simplistic random-number method of calculating pi which is neither efficient nor particularly accurate – but it is fun.</p>
<p><strong>string reverse( string input )</strong><br />
This function returns the reverse version of a string. For example “Test String” becomes  “gnirtS tseT”.</p>
<p><strong>array uniquechars( string input, [bool  case_sensitive] )</strong><br />
Returns an array of all the unique characters in the input string. For example “Test String” returns an array containing the elements ‘T’,  ‘e’, ‘s’, ‘t’, ‘S’, ‘r’, ‘i’, ‘n’ and ‘g’. The case_sensitive parameter which is optional and will be implicitly true sets a flag which  affects whether the search for characters should be case sensitive. If case_sensitive is false, the previous example will return ‘t’, ‘e’, ‘s’, ‘r’, ‘i&#8217;, ‘n’ and ‘g’ – not including the uppercase/lowercase versions of the characters.</p>
<p>None of the above functions are particularly useful, but as examples of creating PHP extensions, they<br />
provide coverage of many of the features that will be used in a more complete extension.</p>
<p>First, create a text file containing the function prototypes. This file should contain one function prototype per line. For the example functions, the file should contain the following three lines (the last<br />
line may wrap in this view, but should not wrap in the actual file you create):</p>
<pre>
double calcpi( int iterations) Calculate Pi
string reverse( string input ) Reverse the input string
array uniquechars( string input [, bool case_sensitive] ) Return the unique characters in the input string
</pre>
<p><em>Code Fragment 1: Prototype file for first_test.</em></p>
<p>Call this file first_test.proto. The ext_skel script will read this file and parse it to build the skeleton C code for the extension. It is not necessary to build a prototype file, but doing so will greatly reduce the amount of actual C coding required to continue and will decrease the risk of incorrectly prototyping the C functions as required to work within the PHP framework.</p>
<p>Each line of the prototype file contains information about a function that will be visible within PHP. The<br />
format of each line is:</p>
<pre>
[function return type] function name (parameter list ) optional comment
</pre>
<p>The function return type is optional and has no effect on the generated skeleton code except in the internal documentation. The parameter list is a comma-separated list consisting of a type and a parameter name. Parameters may be optionally enclosed in square brackets signifying an optional parameter in the PHP context.</p>
<p>With the prototype file created, it is time to run the <em>ext_skel</em> script. Execute the script using:</p>
<pre>
cd /path/to/php/ext
./ext_skel --extname=first_test --proto=first_test.proto
</pre>
<p>Assuming you have the correct write permissions for your system, the script will run and report a list of instructions required to now build and install the new extension. The steps are:</p>
<pre>
cd ..
vi ext/first_test/config.m4
./buildconf
./configure --[with|enable]-first_test
make
./php -f ext/first_test/first_test.php
vi ext/first_test/first_test.c
make
</pre>
<p>I suggest following these steps almost verbatim to ensure that the extension properly builds and integrates into PHP. Before doing so, however, it is interesting to see the files that have been created in the /path/to/php/ext/first_test directory. The files are:</p>
<table>
<tr>
<td>config.m4</td>
<td>This file is used by the buildconf script later to integrate the new extension into the PHP configure script.</td>
</tr>
<tr>
<td>CREDITS</td>
<td>An essentially empty text file for you to credit yourself for your great work.</td>
</tr>
<tr>
<td>EXPERIMENTAL</td>
<td>An empty text file.</td>
</tr>
<tr>
<td>first_test.c</td>
<td>The implementation of the new extension.</td>
</tr>
<tr>
<td>first_test.php</td>
<td>A PHP test script for the new extension.</td>
</tr>
<tr>
<td>php_first_test.h</td>
<td>The header file of the new extension.</td>
</tr>
<tr>
<td>tests</td>
<td>A directory containing at least one PHP test file for use with the automated build testing command make test.</td>
</tr>
</table>
<p><em>Table 2: Files generated by the ext_skel script.</em></p>

<p><a href="http://feedads.g.doubleclick.net/~a/DHR31QO6MVadb-Ra3kMs66WO02c/0/da"><img src="http://feedads.g.doubleclick.net/~a/DHR31QO6MVadb-Ra3kMs66WO02c/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/DHR31QO6MVadb-Ra3kMs66WO02c/1/da"><img src="http://feedads.g.doubleclick.net/~a/DHR31QO6MVadb-Ra3kMs66WO02c/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/SoManyToolsSoLittleTime/~4/f6E1ak2xTao" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.somanytoolssolittletime.com/php-extensions-building-the-shell/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.somanytoolssolittletime.com/php-extensions-building-the-shell/</feedburner:origLink></item>
		<item>
		<title>Tiny jQuery method to restripe a table</title>
		<link>http://feedproxy.google.com/~r/SoManyToolsSoLittleTime/~3/-AeEFEZBkic/</link>
		<comments>http://www.somanytoolssolittletime.com/tiny-jquery-method-to-restripe-a-table/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 17:31:17 +0000</pubDate>
		<dc:creator>BlakeS</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.somanytoolssolittletime.com/?p=39</guid>
		<description><![CDATA[I know that the HTML table is the bane of human existence and all of that, but assuming you&#8217;re using a table to present tabular data (and not for layout, you animated-gif lover), you probably use CSS classes to stripe alternating rows of your table for easier reading.
Creating a table with simple row stripes in [...]]]></description>
			<content:encoded><![CDATA[<p>I know that the HTML table is the bane of human existence and all of that, but assuming you&#8217;re using a table to present tabular data (and not for layout, you animated-gif lover), you probably use CSS classes to stripe alternating rows of your table for easier reading.</p>
<p>Creating a table with simple row stripes in PHP or any other back-end programming language is very simple and requires no front-end Javascript, but if you provide front-end methods for sorting or changing the data in the table, a JS restripe function may be handy.</p>
<p>Here&#8217;s a really simple example of a Javascript restripe function based on jQuery:</p>

<div id="wp_codebox"><table width="100%" ><tr id="p3914"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p39code14"><pre class="javascript">    <span style="color: #003366; font-weight: bold;">function</span> restripe<span style="color: #009900;">&#40;</span>table_id<span style="color: #339933;">,</span> alt_row_class<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
      jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span> <span style="color: #339933;">+</span> table_id <span style="color: #339933;">+</span> <span style="color: #3366CC;">' tr'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">removeClass</span><span style="color: #009900;">&#40;</span>alt_row_class<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>       
&nbsp;
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">++</span> <span style="color: #339933;">%</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">addClass</span><span style="color: #009900;">&#40;</span>alt_row_class<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The function takes two arguments. The first is the id of the table and the second is the CSS class name for the alternate row. This function very simply iterates over each row in the table and first removes the special alternate row class name, then adds it back for every other row.</p>
<p>Obviously this is not a general-purpose solution, but as a starting point, it provides all of the fundamentals from which more generalized versions can be adapted.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/VCiTp9EioGII91oseW47fkEcrew/0/da"><img src="http://feedads.g.doubleclick.net/~a/VCiTp9EioGII91oseW47fkEcrew/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/VCiTp9EioGII91oseW47fkEcrew/1/da"><img src="http://feedads.g.doubleclick.net/~a/VCiTp9EioGII91oseW47fkEcrew/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/SoManyToolsSoLittleTime/~4/-AeEFEZBkic" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.somanytoolssolittletime.com/tiny-jquery-method-to-restripe-a-table/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.somanytoolssolittletime.com/tiny-jquery-method-to-restripe-a-table/</feedburner:origLink></item>
		<item>
		<title>Creating Your Own PHP Extension: Motivation</title>
		<link>http://feedproxy.google.com/~r/SoManyToolsSoLittleTime/~3/CSnpQ6O4Ieo/</link>
		<comments>http://www.somanytoolssolittletime.com/creating-your-own-php-extension-motivation/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 03:10:34 +0000</pubDate>
		<dc:creator>BlakeS</dc:creator>
		
		<category><![CDATA[C]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[extension]]></category>

		<guid isPermaLink="false">http://www.somanytoolssolittletime.com/?p=23</guid>
		<description><![CDATA[Most PHP developers will not need to develop their own custom extension. PHP is a rich programming environment which is constantly updated through a strong open source development community. However, there are times when developing a custom extension may be necessary. Additionally, understanding the extension mechanism in PHP can provide a broader general understanding of [...]]]></description>
			<content:encoded><![CDATA[<p>Most PHP developers will not need to develop their own custom extension. PHP is a rich programming environment which is constantly updated through a strong open source development community. However, there are times when developing a custom extension may be necessary. Additionally, understanding the extension mechanism in PHP can provide a broader general understanding of PHP itself.</p>
<p>I have written two custom extensions with practical benefits in the very recent past. The first was written to map some proprietary C-based financial code into PHP for an example Intranet-based web site. The second was an implementation of a TNEF mail attachment decoder for a web-based email project.</p>
<p>Because of the nature of this document, it is assumed that the reader already has an understanding of PHP development, has built PHP from source and has a C programming background. You should also be familiar with PHP and its relationship to the Zend engine. Much of this document assumes you understand the relationship and so I often do not differentiate between the two in this text. This is an advanced topic not typical to general PHP programming.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/5z_p43E2TcYI2vMLAkxKj_qm7M4/0/da"><img src="http://feedads.g.doubleclick.net/~a/5z_p43E2TcYI2vMLAkxKj_qm7M4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/5z_p43E2TcYI2vMLAkxKj_qm7M4/1/da"><img src="http://feedads.g.doubleclick.net/~a/5z_p43E2TcYI2vMLAkxKj_qm7M4/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/SoManyToolsSoLittleTime/~4/CSnpQ6O4Ieo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.somanytoolssolittletime.com/creating-your-own-php-extension-motivation/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.somanytoolssolittletime.com/creating-your-own-php-extension-motivation/</feedburner:origLink></item>
		<item>
		<title>Procedural DB Access vs. PEAR::DB</title>
		<link>http://feedproxy.google.com/~r/SoManyToolsSoLittleTime/~3/iiFagxcXwgc/</link>
		<comments>http://www.somanytoolssolittletime.com/procedural-db-access-vs-peardb/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 01:03:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[pear]]></category>

		<guid isPermaLink="false">http://www.somanytoolssolittletime.com/?p=19</guid>
		<description><![CDATA[This section shows the similarities and the differences between using procedural database access and PEAR::DB. The example is deliberately simple, showing how to establish a database connection, retrieve a small recordset and close the connection.
The example uses MySQL as the database backend, but could conceivably be any PHP-supported database.
For the examples, a simple four-table database [...]]]></description>
			<content:encoded><![CDATA[<p>This section shows the similarities and the differences between using procedural database access and PEAR::DB. The example is deliberately simple, showing how to establish a database connection, retrieve a small recordset and close the connection.</p>
<p>The example uses MySQL as the database backend, but could conceivably be any PHP-supported database.</p>
<p>For the examples, a simple four-table database will be used to illustrate a small employee and department data set. The four tables are Employees, Paychecks, EmployeesToDepartments, and Departments. The MySQL queries to create and populate the tables are shown below.</p>

<div id="wp_codebox"><table width="100%" ><tr id="p1917"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
</pre></td><td class="code" id="p19code17"><pre class="sql"><span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># Table structure for table `Departments`</span>
<span style="color: #808080; font-style: italic;">#</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`Departments`</span> <span style="color: #66cc66;">&#40;</span>
<span style="color: #ff0000;">`id`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">default</span> <span style="color: #ff0000;">'0'</span><span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">`name`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">default</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">,</span>
<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> TYPE<span style="color: #66cc66;">=</span>MyISAM;
&nbsp;
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># Dumping data for table `Departments`</span>
<span style="color: #808080; font-style: italic;">#</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`Departments`</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Web Development'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`Departments`</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'QA'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># Table structure for table `Employees`</span>
<span style="color: #808080; font-style: italic;">#</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`Employees`</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">`id`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">default</span> <span style="color: #ff0000;">'0'</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`last_name`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">default</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`first_name`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">default</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`phone_ext`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">default</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`mgr_id`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">default</span> <span style="color: #ff0000;">'0'</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`dept_id`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">default</span> <span style="color: #ff0000;">'0'</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #ff0000;">`mgr_id`</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`mgr_id`</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #ff0000;">`dept_id`</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`dept_id`</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> TYPE<span style="color: #66cc66;">=</span>InnoDB;
&nbsp;
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># Dumping data for table `Employees`</span>
<span style="color: #808080; font-style: italic;">#</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`Employees`</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Schwendiman'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Blake'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'204'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`Employees`</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Cox'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Jeffrey'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'225'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`Employees`</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'McNulty'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Kate'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'214'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># Table structure for table `Paychecks`</span>
<span style="color: #808080; font-style: italic;">#</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`Paychecks`</span> <span style="color: #66cc66;">&#40;</span>
   <span style="color: #ff0000;">`id`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">auto_increment</span><span style="color: #66cc66;">,</span>
   <span style="color: #ff0000;">`employee_id`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">default</span> <span style="color: #ff0000;">'0'</span><span style="color: #66cc66;">,</span>
   <span style="color: #ff0000;">`check_date`</span> date <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">default</span> <span style="color: #ff0000;">'0000-00-00'</span><span style="color: #66cc66;">,</span>
   <span style="color: #ff0000;">`check_number`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">default</span> <span style="color: #ff0000;">'0'</span><span style="color: #66cc66;">,</span>
   <span style="color: #ff0000;">`gross_pay`</span> float <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">default</span> <span style="color: #ff0000;">'0'</span><span style="color: #66cc66;">,</span>
   <span style="color: #ff0000;">`benefits_withheld`</span> float <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">default</span> <span style="color: #ff0000;">'0'</span><span style="color: #66cc66;">,</span>
   <span style="color: #ff0000;">`taxes_withheld`</span> float <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">default</span> <span style="color: #ff0000;">'0'</span><span style="color: #66cc66;">,</span>
   <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> TYPE<span style="color: #66cc66;">=</span>MyISAM <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span> ;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`EmployeesToDepartments`</span> <span style="color: #66cc66;">&#40;</span>
   <span style="color: #ff0000;">`emp_id`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">default</span> <span style="color: #ff0000;">'0'</span><span style="color: #66cc66;">,</span>
   <span style="color: #ff0000;">`dept_id`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">default</span> <span style="color: #ff0000;">'0'</span><span style="color: #66cc66;">,</span>
   <span style="color: #ff0000;">`date_xferred`</span> date <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">default</span> <span style="color: #ff0000;">'0000-00-00'</span><span style="color: #66cc66;">,</span>
   <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`emp_id`</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">`dept_id`</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> TYPE<span style="color: #66cc66;">=</span>MyISAM;</pre></td></tr></table></div>

<p><em>Code Listing 1: MySQL Statements to Create Sample Database</em></p>
<p>The Employees table contains a field called dept_id representing the current department in which the employee works. The EmployeesToDepartments table is an intermediate table to effect an m-to-n relationship between Employees and Departments representing historical information about which employees have ever worked in a department. The real purpose of the EmployeesToDepartments table, though, is for examples in which a multiple-field key is needed.</p>
<p>The sample code will use the SQL query shown in Code Listing 2 below to retrieve data about employees, their department and their manager. The query is deliberately more complex than the most basic SELECT statement to provide more value to the example, but the details of the SQL statement will not be covered in this document.</p>

<div id="wp_codebox"><table width="100%" ><tr id="p1918"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p19code18"><pre class="sql"><span style="color: #993333; font-weight: bold;">SELECT</span> Employees<span style="color: #66cc66;">.</span>last_name <span style="color: #993333; font-weight: bold;">as</span> emp_last_name<span style="color: #66cc66;">,</span>
Employees<span style="color: #66cc66;">.</span>first_name <span style="color: #993333; font-weight: bold;">as</span> emp_first_name<span style="color: #66cc66;">,</span>
Employees<span style="color: #66cc66;">.</span>phone_ext <span style="color: #993333; font-weight: bold;">as</span> emp_phone_ext<span style="color: #66cc66;">,</span>
Departments<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">as</span> dept_name<span style="color: #66cc66;">,</span>
Employees_1<span style="color: #66cc66;">.</span>last_name <span style="color: #993333; font-weight: bold;">as</span> mgr_last_name<span style="color: #66cc66;">,</span>
Employees_1<span style="color: #66cc66;">.</span>first_name <span style="color: #993333; font-weight: bold;">as</span> mgr_first_name<span style="color: #66cc66;">,</span>
Employees_1<span style="color: #66cc66;">.</span>phone_ext <span style="color: #993333; font-weight: bold;">as</span> mgr_phone_ext <span style="color: #993333; font-weight: bold;">FROM</span>
<span style="color: #66cc66;">&#40;</span>Departments <span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> Employees <span style="color: #993333; font-weight: bold;">ON</span> Departments<span style="color: #66cc66;">.</span>id
<span style="color: #66cc66;">=</span> Employees<span style="color: #66cc66;">.</span>dept_id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">JOIN</span> Employees <span style="color: #993333; font-weight: bold;">AS</span>
Employees_1 <span style="color: #993333; font-weight: bold;">ON</span> Employees<span style="color: #66cc66;">.</span>mgr_id <span style="color: #66cc66;">=</span> Employees_1<span style="color: #66cc66;">.</span>id</pre></td></tr></table></div>

<p><em>Code Listing 2: SQL Query for Sample Employee Database</em></p>
<p>Both the procedural example and the PEAR::DB example will retrieve the data and create an HTML table containing the results.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/Ld11CS-A7qbYZ2jttjSO0O67Q8c/0/da"><img src="http://feedads.g.doubleclick.net/~a/Ld11CS-A7qbYZ2jttjSO0O67Q8c/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Ld11CS-A7qbYZ2jttjSO0O67Q8c/1/da"><img src="http://feedads.g.doubleclick.net/~a/Ld11CS-A7qbYZ2jttjSO0O67Q8c/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/SoManyToolsSoLittleTime/~4/iiFagxcXwgc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.somanytoolssolittletime.com/procedural-db-access-vs-peardb/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.somanytoolssolittletime.com/procedural-db-access-vs-peardb/</feedburner:origLink></item>
		<item>
		<title>Installing PEAR::DB</title>
		<link>http://feedproxy.google.com/~r/SoManyToolsSoLittleTime/~3/M5T4fjrLmvk/</link>
		<comments>http://www.somanytoolssolittletime.com/installing-peardb/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 00:52:12 +0000</pubDate>
		<dc:creator>BlakeS</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.somanytoolssolittletime.com/?p=16</guid>
		<description><![CDATA[If you do not have the DB package installed, using
the following command to install DB:

  pear install DB

If you do not have the most current version of DB or
if you need to check for an upgrade and install it, use:

  pear upgrade DB

Note that the above will cause an upgrade to be
installed if [...]]]></description>
			<content:encoded><![CDATA[<p>If you do not have the DB package installed, using<br />
the following command to install DB:</p>
<pre>
  pear install DB
</pre>
<p>If you do not have the most current version of DB or<br />
if you need to check for an upgrade and install it, use:</p>
<pre>
  pear upgrade DB
</pre>
<p>Note that the above will cause an upgrade to be<br />
installed if one exists. If you simply wish to check for<br />
upgrades, use the pear list-all or pear list-upgrades<br />
commands.</p>
<p>For the purposes of this document, it will be assumed<br />
that the version of PEAR::DB is 1.5.0RC2.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/hjnx-H23kIrjAzsNlH9dk5_N1IE/0/da"><img src="http://feedads.g.doubleclick.net/~a/hjnx-H23kIrjAzsNlH9dk5_N1IE/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/hjnx-H23kIrjAzsNlH9dk5_N1IE/1/da"><img src="http://feedads.g.doubleclick.net/~a/hjnx-H23kIrjAzsNlH9dk5_N1IE/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/SoManyToolsSoLittleTime/~4/M5T4fjrLmvk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.somanytoolssolittletime.com/installing-peardb/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.somanytoolssolittletime.com/installing-peardb/</feedburner:origLink></item>
		<item>
		<title>Installing PEAR</title>
		<link>http://feedproxy.google.com/~r/SoManyToolsSoLittleTime/~3/gp2zm49iNpc/</link>
		<comments>http://www.somanytoolssolittletime.com/installing-pear/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 00:47:00 +0000</pubDate>
		<dc:creator>BlakeS</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[pear]]></category>

		<guid isPermaLink="false">http://www.somanytoolssolittletime.com/?p=14</guid>
		<description><![CDATA[Depending on your PHP version and your computing
platform, there may be some steps needed to install
and configure PEAR.
If you are running a version of PHP prior to version
4.3, you will likely need to manually install the PEAR
package manager. Later versions of PHP (4.3 and
higher) come with the PEAR package manager or the
package manager is built [...]]]></description>
			<content:encoded><![CDATA[<p>Depending on your PHP version and your computing<br />
platform, there may be some steps needed to install<br />
and configure PEAR.</p>
<p>If you are running a version of PHP prior to version<br />
4.3, you will likely need to manually install the PEAR<br />
package manager. Later versions of PHP (4.3 and<br />
higher) come with the PEAR package manager or the<br />
package manager is built be default. If you added the<br />
&#8211;without-pear flag to your configuration of PHP,<br />
you will also need to get the PEAR package manager.<br />
For Unix, Linux and BSD you can obtain the PEAR<br />
package manager using the command line:</p>
<pre>
  lynx –source http://go-pear.org/ | php
</pre>
<p>The above command line requires that you have lynx<br />
installed (it may be called links on some Linux<br />
distributions). It is also assumed that you have your<br />
PHP binary built and installed.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/-U3aTrwrA0T7hFic9L387Kww3TU/0/da"><img src="http://feedads.g.doubleclick.net/~a/-U3aTrwrA0T7hFic9L387Kww3TU/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/-U3aTrwrA0T7hFic9L387Kww3TU/1/da"><img src="http://feedads.g.doubleclick.net/~a/-U3aTrwrA0T7hFic9L387Kww3TU/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/SoManyToolsSoLittleTime/~4/gp2zm49iNpc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.somanytoolssolittletime.com/installing-pear/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.somanytoolssolittletime.com/installing-pear/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic Page Served (once) in 0.829 seconds --><!-- Cached page served in 0.00008 seconds -->
