<?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:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>DevZone</title>
	
	<link>http://devzone.zend.com</link>
	<description>Advancing the art of PHP</description>
	<lastBuildDate>Tue, 21 Feb 2012 18:24:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/PHPDevZone" /><feedburner:info uri="phpdevzone" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>PHP 101 (part 8): Databases and Other Animals – Part 1</title>
		<link>http://feedproxy.google.com/~r/PHPDevZone/~3/c7tzcmuIxew/</link>
		<comments>http://devzone.zend.com/12/php-101-part-8-databases-and-other-animals_part-1/#comments</comments>
		<pubDate>Tue, 21 Feb 2012 18:24:52 +0000</pubDate>
		<dc:creator>Vikram Vaswani</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[All Skill Levels]]></category>
		<category><![CDATA[PHP101]]></category>
		<category><![CDATA[PHP5]]></category>

		<guid isPermaLink="false">http://devzone.calevans.com//?p=12</guid>
		<description><![CDATA[p. One of the most compelling things PHP has going for it is its support for a variety of database management systems, including MySQL, PostgreSQL, Oracle and Microsoft Access. By virtue of this support, PHP developers can create sophisticated data-driven Web applications at a fraction of the time and cost required by competing alternatives. And nowhere is this more clear than in PHP's longtime support of MySQL, the very fast, very reliable and very feature-rich open-source RDBMS.]]></description>
			<content:encoded><![CDATA[<p><a href='#Heading1'>Mix and Match</a><br />
<a href='#Heading2'>Building Blocks</a><br />
<a href='#Heading3'>Animal Magnetism</a><br />
<a href='#Heading4'>Hello Database!</a><br />
<a href='#Heading5'>Different Strokes&#8230;</a><br />
<a href='#Heading6'>&#8230;for Different Folks</a><br />
<a href='http://devzone.zend.com/13/'>PHP 101 (part 8): Databases and Other Animals &#8211; Part 2</a></p>
<hr />
<a name='Heading1'></a><br />
<h2 align='left'>Mix and Match</h2>
<p>
One of the most compelling things PHP has going for it is its<br />
support for a variety of database management systems, including MySQL,<br />
PostgreSQL, Oracle and Microsoft Access. By virtue of this support, PHP<br />
developers can create sophisticated data-driven Web applications at a<br />
fraction of the time and cost required by competing alternatives. And<br />
nowhere is this more clear than in PHP&#8217;s longtime support of MySQL, the<br />
very fast, very reliable and very feature-rich open-source RDBMS.
</p>
<p>
By using PHP and MySQL together, developers can benefit from huge<br />
savings on the licensing costs of commercial alternatives, and also<br />
leverage off the tremendous amount of thought PHP and MySQL developers<br />
have put into making sure that the two packages work together<br />
seamlessly and smoothly. And since both PHP and MySQL are open-source<br />
projects, when you use the two of them together you know<br />
you&#8217;re getting the most up-to-date technology  available. And that&#8217;s<br />
always a good thought to go to bed with.
</p>
<p>
OK. Enough of the marketing talk. Let&#8217;s get down to business.
</p>
<p>
In this issue of PHP 101, I&#8217;m going to show you how to use PHP to<br />
extract data from a database, and use that data to dynamically build a<br />
Web page. In order to try out the examples in this tutorial, you&#8217;ll<br />
need a working MySQL installation, which you can obtain from the MySQL<br />
Web site at <a href = "http://www.mysql.com/" target = "_blank">http://www.mysql.com/</a>.<br />
If you have some knowledge of SQL<br />
(Structured Query Language, the language used to interact with a<br />
database server) you&#8217;ll find it helpful, but it&#8217;s not essential.
</p>
<p><a name='Heading2'></a><br />
<h2 align='left'>Building Blocks</h2>
<p>
In order to use MySQL and PHP together, your PHP build must include<br />
support for MySQL. On UNIX, this is accomplished by adding the<br />
<code>--with-mysql</code> option to the <code>configure</code> script<br />
when building PHP on UNIX, and pointing PHP to the MySQL client<br />
libraries. On Windows, the MySQL client libraries are built in to<br />
PHP 4 and activated by default. In PHP 5, pre-built .dll files<br />
are included with the Windows distribution. Read more about this at</p>
<p><a href="http://www.php.net/manual/en/ref.mysql.php" target = "_blank">http://www.php.net/manual/en/ref.mysql.php</a>.
</p>
<p>
Unix users should note that PHP 4 ships with a set of MySQL<br />
client libraries, which are activated by default; however, PHP<br />
5 no longer bundles these libraries due to licensing issues, so you<br />
need to obtain, install and activate them yourself. They&#8217;re included<br />
with the MySQL distribution, and are installed automatically when you<br />
install MySQL. To activate the MySQL extension, <code>ext/mysql</code>,<br />
add the <code>--with-mysql</code> option to PHP&#8217;s <code>configure</code><br />
script. For more information on this change, read<br />
<a href="http://www.php.net/manual/en/faq.databases.php#faq.databases.mysql.php5" target = "_blank">http://www.php.net/manual/en/faq.databases.php#faq.databases.mysql.php5</a>.
</p>
<p>And finally (as if all that wasn&#8217;t quite confusing enough) PHP 5 also<br />
comes with a <b>new</b> MySQL extension, called <code>ext/mysqli</code><br />
(MySQL Improved). You can use this new extension to access the new<br />
features in MySQL 4.1.2 or better, and to gain the benefits of improved<br />
speed and security. To activate this extension on UNIX, add the<br />
<code>--with-mysqli</code> option to PHP&#8217;s <code>configure</code> script,<br />
and point PHP to the <code>mysql_config</code> program that comes with<br />
MySQL 4.1 and above. For Windows users, a pre-built version of<br />
<code>ext/mysqli</code> is included in the win32 PHP distribution. Read<br />
more about this at <a href="http://www.php.net/manual/en/ref.mysqli.php" target = "_blank">http://www.php.net/manual/en/ref.mysqli.php</a>.</p>
<p>
To figure out which extension you need, use the following rule of thumb:</p>
<ul>
<li>If you need the new features in MySQL 4.1.2 or better, or if you&#8217;re<br />
using an older version of MySQL but still want to benefit from the<br />
speed/security improvements in the new extension, use <code>ext/mysqli</code>.</li>
<li>If you don&#8217;t fall into either of the categories above, or don&#8217;t know what I&#8217;m<br />
talking about, use regular <code>ext/mysql</code>.</li>
</ul>
<p>
In case you were wondering, this  tutorial covers both <code>ext/mysql</code></p>
<p>and <code>ext/mysqli</code>, so you actually get two for the price of<br />
one. Keep reading, and let me introduce you to MySQL.
</p>
<p><a name='Heading3'></a><br />
<h2 align='left'>Animal Magnetism</h2>
<p>
Every MySQL database is composed of one or more <i>tables</i>. These<br />
tables, which structure data into rows and columns, are what lend<br />
organization to the data.
</p>
<p>
Here&#8217;s an example of what a typical table looks like:</p>
<pre>
+----+-----------+----------+
| id | country   | animal   |
+----+-----------+----------+
|  1 | America   | eagle    |
|  2 | China     | dragon   |
|  3 | England   | lion     |
|  4 | India     | tiger    |
|  5 | Australia | kangaroo |
|  6 | Norway    | elk      |
+----+-----------+----------+
</pre>
<p>As you can see, a table divides data into rows, with a new entry (or</p>
<p><i>record</i>) on every row. The data in each row is further broken<br />
down into cells (or <i>fields</i>), each of which contains a value for<br />
a particular attribute of the data. For example, if you consider the<br />
record for the country &#8220;India&#8221;, you&#8217;ll see that the record is clearly<br />
divided into separate fields for record number, country name and<br />
national animal.
</p>
<p>
The rows within a table are not arranged in any particular order -<br />
they can be sorted alphabetically, by number, by name, or by any<br />
other criteria you choose to specify. It is therefore necessary to have<br />
some method of identifying a specific record in a table. In the example<br />
above, each record is identified by a unique number; this unique field<br />
is referred to as the <i>primary key</i> for that table.
</p>
<p>
You use the Structured Query Language, SQL, to interact with the MySQL<br />
server and tell it to create a table, mark a field as primary, insert<br />
records, edit records, retrieve records&#8230; basically, anything that<br />
involves manipulating the data or the database. To see how this works,<br />
examine the following SQL, which creates the table above:
</p>
<p>
<code class="tutorialExample"><span style="color: #000000"><br />
CREATE DATABASE testdb;</p>
<p>CREATE TABLE `symbols` (<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;`id` int(11) NOT NULL auto_increment,<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;`country` varchar(255) NOT NULL default '',<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;`animal` varchar(255) NOT NULL default '',<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;PRIMARY KEY&nbsp;&nbsp;(`id`)<br />
<br />) TYPE=MyISAM;</p>
<p>INSERT INTO `symbols` VALUES (1, 'America', 'eagle');<br />
<br />INSERT INTO `symbols` VALUES (2, 'China', 'dragon');<br />
<br />INSERT INTO `symbols` VALUES (3, 'England', 'lion');<br />
<br />INSERT INTO `symbols` VALUES (4, 'India', 'tiger');<br />
<br />INSERT INTO `symbols` VALUES (5, 'Australia', 'kangaroo');<br />
<br />INSERT INTO `symbols` VALUES (6, 'Norway', 'elk');<br />
<br /></span><br />
</code></p>
<p>
You can enter these commands either interactively or<br />
non-interactively through the MySQL commandline client program,<br />
which you run by navigating to the <code>mysql/bin</code><br />
directory from your shell or DOS box and typing &#8211; with no<br />
<code>;</code> because this is a shell command &#8211; either<br />
<code>mysql</code>, or <code>mysql db_name</code> if you want<br />
to choose an existing database to work with. Read<br />
<a href="http://dev.mysql.com/doc/mysql/en/mysql.html" target = "_blank">http://dev.mysql.com/doc/mysql/en/mysql.html</a> for more information<br />
on how to use the MySQL commandline client, and the tutorial at</p>
<p><a href="http://www.melonfire.com/community/columns/trog/article.php?id=39" target = "_blank">http://www.melonfire.com/community/columns/trog/article.php?id=39</a><br />
to understand what each of the SQL commands above does. SQL is a<br />
lot like spoken English, so it won&#8217;t take you very long to pick it<br />
up. Just don&#8217;t try to turn those backticks into single quotation marks.
</p>
<p>
Once the data has been imported, run a quick <code>SELECT</code><br />
query to check that everything is working as it should be:</p>
<pre>
mysql> SELECT * FROM `symbols`;
+----+-----------+----------+
| id | country   | animal   |
+----+-----------+----------+
|  1 | America   | eagle    |
|  2 | China     | dragon   |
|  3 | England   | lion     |
|  4 | India     | tiger    |
|  5 | Australia | kangaroo |
|  6 | Norway    | elk      |
+----+-----------+----------+
6 rows in set (0.06 sec)
</pre>
<p>In English, the query above means &#8220;show me all the records from the<br />
table named <code>symbols</code>&#8220;. If you saw the same output as above,<br />
you&#8217;re good to go!
</p>
<p><a name='Heading4'></a><br />
<h2 align='left'>Hello Database!</h2>
<p>
Now, let&#8217;s use PHP to do exactly the same thing.  You could use PHP<br />
to set up the database from the start, but as ours already exists<br />
we&#8217;ll simply fire a <code>SELECT</code> query at the database<br />
&#8216;testdb&#8217;, and display the results in an HTML page:
</p>
<p>
<code class="tutorialExample"><span style="color: #000000"><br />
&lt;html&gt;<br />
<br />&lt;head&gt;<br />
<br />&lt;basefont face="Arial"&gt;<br />
<br />&lt;/head&gt;<br />
<br />&lt;body&gt;</p>
<p><span style="color: #0000BB">&lt;?php</p>
<p></span><span style="color: #FF8000">// set database server access variables:<br />
<br /></span><span style="color: #0000BB">$host </span><span style="color: #007700">= </span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">;<br />
<br /></span><span style="color: #0000BB">$user </span><span style="color: #007700">= </span><span style="color: #DD0000">"test"</span><span style="color: #007700">;<br />
<br /></span><span style="color: #0000BB">$pass </span><span style="color: #007700">= </span><span style="color: #DD0000">"test"</span><span style="color: #007700">;<br />
<br /></span><span style="color: #0000BB">$db </span><span style="color: #007700">= </span><span style="color: #DD0000">"testdb"</span><span style="color: #007700">;</p>
<p></span><span style="color: #FF8000">// open connection<br />
<br /></span><span style="color: #0000BB">$connection </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$host</span><span style="color: #007700">, </span><span style="color: #0000BB">$user</span><span style="color: #007700">, </span><span style="color: #0000BB">$pass</span><span style="color: #007700">) or die (</span><span style="color: #DD0000">"Unable to connect!"</span><span style="color: #007700">);</p>
<p></span><span style="color: #FF8000">// select database<br />
<br /></span><span style="color: #0000BB">mysql_select_db</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">) or die (</span><span style="color: #DD0000">"Unable to select database!"</span><span style="color: #007700">);</p>
<p></span><span style="color: #FF8000">// create query<br />
<br /></span><span style="color: #0000BB">$query </span><span style="color: #007700">= </span><span style="color: #DD0000">"SELECT * FROM symbols"</span><span style="color: #007700">;</p>
<p></span><span style="color: #FF8000">// execute query<br />
<br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">) or die (</span><span style="color: #DD0000">"Error in query: $query. "</span><span style="color: #007700">.</span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">());</p>
<p></span><span style="color: #FF8000">// see if any rows were returned<br />
<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">mysql_num_rows</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">) &gt; </span><span style="color: #0000BB">0</span><span style="color: #007700">) {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">// yes<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;// print them one after another<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo </span><span style="color: #DD0000">"&lt;table cellpadding=10 border=1&gt;"</span><span style="color: #007700">;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;while(</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_fetch_row</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">)) {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;tr&gt;"</span><span style="color: #007700">;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;td&gt;"</span><span style="color: #007700">.</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">].</span><span style="color: #DD0000">"&lt;/td&gt;"</span><span style="color: #007700">;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;td&gt;" </span><span style="color: #007700">. </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">].</span><span style="color: #DD0000">"&lt;/td&gt;"</span><span style="color: #007700">;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;td&gt;"</span><span style="color: #007700">.</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">2</span><span style="color: #007700">].</span><span style="color: #DD0000">"&lt;/td&gt;"</span><span style="color: #007700">;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;/tr&gt;"</span><span style="color: #007700">;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;/table&gt;"</span><span style="color: #007700">;<br />
<br />}<br />
<br />else {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">// no<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;// print status message<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo </span><span style="color: #DD0000">"No rows found!"</span><span style="color: #007700">;</p>
<p>}</p>
<p></span><span style="color: #FF8000">// free result set memory<br />
<br /></span><span style="color: #0000BB">mysql_free_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);</p>
<p></span><span style="color: #FF8000">// close connection<br />
<br /></span><span style="color: #0000BB">mysql_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$connection</span><span style="color: #007700">);</p>
<p></span><span style="color: #0000BB">?&gt;<br />
<br /></span></p>
<p>&lt;/body&gt;<br />
<br />&lt;/html&gt;</span><br />
</code>
</p>
<p>
Here&#8217;s what the result looks like:
</p>
<p>
<img src = '/images/articles/vikram8_1.gif' alt = 'Hello Database!'>
</p>
<p>
As you can see, using PHP to get data from a database involves<br />
several steps, each of which is actually a pre-defined PHP function.<br />
Let&#8217;s dissect each step:
</p>
<ol>
<li>The first thing to do is specify some important information needed<br />
to establish a connection to the database server. This information<br />
includes the server name, the username and password required to gain<br />
access to it, and the name of the database to query. These values are<br />
all set up in regular PHP variables.</p>
<p>
<code class="tutorialExample"><span style="color: #000000"><br />
<span style="color: #0000BB">&lt;?php</p>
<p>$host </span><span style="color: #007700">= </span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">;<br />
<br /></span><span style="color: #0000BB">$user </span><span style="color: #007700">= </span><span style="color: #DD0000">"test"</span><span style="color: #007700">;<br />
<br /></span><span style="color: #0000BB">$pass </span><span style="color: #007700">= </span><span style="color: #DD0000">"test"</span><span style="color: #007700">;<br />
<br /></span><span style="color: #0000BB">$db </span><span style="color: #007700">= </span><span style="color: #DD0000">"testdb"</span><span style="color: #007700">;</p>
<p></span><span style="color: #0000BB">?&gt;</span><br />
</span><br />
</code>
</p>
<li>To begin communication with a MySQL database server, you need to<br />
open a connection to that server. All communication between PHP and<br />
the database server takes place through this connection.</p>
<p>
In order to initialize this connection, PHP offers the<br />
<code>mysql_connect()</code> function:
</p>
<p>
<code class="tutorialExample"><span style="color: #000000"><br />
<span style="color: #0000BB">&lt;?php</p>
<p>$connection </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$server</span><span style="color: #007700">, </span><span style="color: #0000BB">$user</span><span style="color: #007700">, </span><span style="color: #0000BB">$pass</span><span style="color: #007700">);</p>
<p></span><span style="color: #0000BB">?&gt;</span><br />
</span><br />
</code>
</p>
<p>All the parameters in <code>mysql_connect()</code>are optional, but there<br />
are three you will generally need to use anywhere beyond your own machine:<br />
the database server name,  username and password. If the database server<br />
and the Web server are running on the same physical machine, you can use<br />
<code>localhost</code> as the database server name  this is in fact the<br />
default value supplied by PHP.
</p>
<p>
<code>mysql_connect()</code> returns a &#8220;link identifier&#8221;, which is stored<br />
in the variable <code>$connection</code>. This identifier is used when<br />
communicating with the database.
</p>
<li>Once you have a connection to the database, you must select<br />
a database for use with the <code>mysql_select_db()</code> function:</p>
<p>
<code class="tutorialExample"><span style="color: #000000"><br />
<span style="color: #0000BB">&lt;?php</p>
<p>mysql_select_db</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">) or die (</span><span style="color: #DD0000">"Unable to select database!"</span><span style="color: #007700">);</p>
<p></span><span style="color: #0000BB">?&gt;</span><br />
</span><br />
</code>
</p>
<p>This function must be passed the name of the database to be used for<br />
all subsequent queries. An optional second argument here is the link<br />
identifier; if no identifier is specified, the last opened link is<br />
assumed. If you have two or more database connections open<br />
simultaneously, it&#8217;s a good idea to specify the link identifier as the<br />
second argument to <code>mysql_select_db()</code> &#8211; and indeed to all other<br />
mysql_* functions in the script, so that PHP doesn&#8217;t get confused about<br />
which connection to use where.
</p>
<li>The next step is to create the query and execute it. This<br />
is accomplished with the <code>mysql_query()</code> function.</p>
<p>
<code class="tutorialExample"><span style="color: #000000"><br />
<span style="color: #0000BB">&lt;?php</p>
<p>$query </span><span style="color: #007700">= </span><span style="color: #DD0000">"SELECT * FROM symbols"</span><span style="color: #007700">;</p>
<p></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">) or die (</span><span style="color: #DD0000">"Error in query: $query. "</span><span style="color: #007700">.</span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">());</p>
<p></span><span style="color: #0000BB">?&gt;</span><br />
</span><br />
</code>
</p>
<p>This function also needs two parameters: the query string and the<br />
link identifier for the connection. Again, if no link identifier is<br />
specified, the last opened link is used. Depending on whether or not<br />
the query was successful, the function returns true or false; a failure<br />
can be caught via the <code>...or die()</code> clause of the statement,<br />
and the <code>mysql_error()</code> function can be used to display the<br />
corresponding error message.
</p>
<li>If <code>mysql_query()</code> is successful, the result set returned<br />
by the query is stored in the variable <code>$result</code>. This result set may<br />
contain one or more rows or columns of data, depending on your query. You can<br />
retrieve specific subsets of the result set with different PHP functions,<br />
including the one used here &#8211; the <code>mysql_fetch_row()</code> function -<br />
which fetches a single row of data as an array called <code>$row</code>. Fields<br />
in that row can then be accessed using standard PHP array notation.</p>
<p>
Each time you call <code>mysql_fetch_row()</code>, the next record in the result<br />
set is returned. This makes <code>mysql_fetch_row()</code> very suitable for<br />
use in a <code>while()</code> or <code>for()</code> loop.
</p>
<p>
<code class="tutorialExample"><span style="color: #000000"><br />
<span style="color: #0000BB">&lt;?php</p>
<p></span><span style="color: #007700">if (</span><span style="color: #0000BB">mysql_num_rows</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">) &gt; </span><span style="color: #0000BB">0</span><span style="color: #007700">) {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;while(</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_fetch_row</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">)) {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;td&gt;"</span><span style="color: #007700">.</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">].</span><span style="color: #DD0000">"&lt;/td&gt;"</span><span style="color: #007700">;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;td&gt;"</span><span style="color: #007700">.</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">].</span><span style="color: #DD0000">"&lt;/td&gt;"</span><span style="color: #007700">;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;td&gt;"</span><span style="color: #007700">.</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">2</span><span style="color: #007700">].</span><span style="color: #DD0000">"&lt;/td&gt;"</span><span style="color: #007700">;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />}</p>
<p></span><span style="color: #0000BB">?&gt;</span><br />
</span><br />
</code>
</p>
<p>
Notice that the call to <code>mysql_fetch_row()</code> is wrapped in a<br />
conditional test, which first checks to see if any rows were returned<br />
at all. This information is provided by the <code>mysql_num_rows()</code><br />
function, which contains the number of rows returned by the query. Obviously,<br />
you can only use this function with queries that return data, like<br />
<code>SELECT</code> or <code>SHOW</code>.It is not appropriate for use with</p>
<p><code>INSERT</code>, <code>UPDATE</code>, <code>DELETE</code> or similar queries.
</p>
<p>
There are several other alternatives to <code>mysql_fetch_row()</code>,<br />
which will be explained a little later.
</p>
<li>Finally, since each result set returned after a query<br />
occupies memory, it&#8217;s a good idea to use the <code>mysql_free_result()</code><br />
function to free up the used memory. After the result set is freed, if no<br />
further queries are to be run, you can close the connection to the MySQL<br />
server with <code>mysql_close()</code>.</p>
<p>
<code class="tutorialExample"><span style="color: #000000"><br />
<span style="color: #0000BB">&lt;?php</p>
<p>mysql_free_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br />
<br /></span><span style="color: #0000BB">mysql_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$connection</span><span style="color: #007700">);</p>
<p></span><span style="color: #0000BB">?&gt;</span><br />
</span><br />
</code></p>
</ol>
<p><a name='Heading5'></a><br />
<h2 align='left'>Different Strokes&#8230;</h2>
<p>
You can also use PHP&#8217;s <code>mysql_fetch_row()</code> and <code>list()</code><br />
functions to obtain a simple array of values, and then assign these values to<br />
different variables &#8211; a variation of the technique in the previous section.<br />
Take a look (only the <code>while()</code> loop changes):
</p>
<p><code class="tutorialExample"><span style="color: #000000"><br />
&lt;html&gt;<br />
<br />&lt;head&gt;<br />
<br />&lt;basefont face="Arial"&gt;<br />
<br />&lt;/head&gt;<br />
<br />&lt;body&gt;</p>
<p><span style="color: #0000BB">&lt;?php</p>
<p></span><span style="color: #FF8000">// set server access variables<br />
<br /></span><span style="color: #0000BB">$host </span><span style="color: #007700">= </span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">;</p>
<p></span><span style="color: #0000BB">$user </span><span style="color: #007700">= </span><span style="color: #DD0000">"test"</span><span style="color: #007700">;<br />
<br /></span><span style="color: #0000BB">$pass </span><span style="color: #007700">= </span><span style="color: #DD0000">"test"</span><span style="color: #007700">;<br />
<br /></span><span style="color: #0000BB">$db </span><span style="color: #007700">= </span><span style="color: #DD0000">"testdb"</span><span style="color: #007700">;</p>
<p></span><span style="color: #FF8000">// open connection<br />
<br /></span><span style="color: #0000BB">$connection </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$host</span><span style="color: #007700">, </span><span style="color: #0000BB">$user</span><span style="color: #007700">, </span><span style="color: #0000BB">$pass</span><span style="color: #007700">) or die (</span><span style="color: #DD0000">"Unable to connect!"</span><span style="color: #007700">);</p>
<p></span><span style="color: #FF8000">// select database<br />
<br /></span><span style="color: #0000BB">mysql_select_db</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">) or die (</span><span style="color: #DD0000">"Unable to select database!"</span><span style="color: #007700">);</p>
<p></span><span style="color: #FF8000">// create query<br />
<br /></span><span style="color: #0000BB">$query </span><span style="color: #007700">= </span><span style="color: #DD0000">"SELECT * FROM symbols"</span><span style="color: #007700">;</p>
<p></span><span style="color: #FF8000">// execute query<br />
<br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">) or die (</span><span style="color: #DD0000">"Error in query: $query. "</span><span style="color: #007700">.</span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">());</p>
<p></span><span style="color: #FF8000">// see if any rows were returned<br />
<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">mysql_num_rows</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">) &gt; </span><span style="color: #0000BB">0</span><span style="color: #007700">) {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">// yes<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// print them one after another<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo </span><span style="color: #DD0000">"&lt;table cellpadding=10 border=1&gt;"</span><span style="color: #007700">;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while(list(</span><span style="color: #0000BB">$id</span><span style="color: #007700">, </span><span style="color: #0000BB">$country</span><span style="color: #007700">, </span><span style="color: #0000BB">$animal</span><span style="color: #007700">)&nbsp;&nbsp;= </span><span style="color: #0000BB">mysql_fetch_row</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">)) {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;tr&gt;"</span><span style="color: #007700">;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;td&gt;$id&lt;/td&gt;"</span><span style="color: #007700">;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;td&gt;$country&lt;/td&gt;"</span><span style="color: #007700">;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;td&gt;$animal&lt;/td&gt;"</span><span style="color: #007700">;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;/tr&gt;"</span><span style="color: #007700">;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;/table&gt;"</span><span style="color: #007700">;<br />
<br />}<br />
<br />else {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">// no<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// print status message<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo </span><span style="color: #DD0000">"No rows found!"</span><span style="color: #007700">;</p>
<p>}</p>
<p></span><span style="color: #FF8000">// free result set memory<br />
<br /></span><span style="color: #0000BB">mysql_free_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);</p>
<p></span><span style="color: #FF8000">// close connection<br />
<br /></span><span style="color: #0000BB">mysql_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$connection</span><span style="color: #007700">);</p>
<p></span><span style="color: #0000BB">?&gt;<br />
<br /></span></p>
<p>&lt;/body&gt;<br />
<br />&lt;/html&gt;</span><br />
</code>
</p>
<p>
In this case, the <code>list()</code> function is used to assign different<br />
elements of the result set to PHP variables, which are then used when<br />
rendering the page.
</p>
<p>
You can use PHP&#8217;s <code>mysql_fetch_assoc()</code> function to represent each<br />
row as an associative array of field-value pairs &#8211; a minor variation of the<br />
technique used above:</p>
<p>
<code class="tutorialExample"><span style="color: #000000"><br />
&lt;html&gt;<br />
<br />&lt;head&gt;<br />
<br />&lt;basefont face="Arial"&gt;<br />
<br />&lt;/head&gt;<br />
<br />&lt;body&gt;</p>
<p><span style="color: #0000BB">&lt;?php</p>
<p></span><span style="color: #FF8000">// set server access variables</p>
<p></span><span style="color: #0000BB">$host </span><span style="color: #007700">= </span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">;<br />
<br /></span><span style="color: #0000BB">$user </span><span style="color: #007700">= </span><span style="color: #DD0000">"test"</span><span style="color: #007700">;<br />
<br /></span><span style="color: #0000BB">$pass </span><span style="color: #007700">= </span><span style="color: #DD0000">"test"</span><span style="color: #007700">;<br />
<br /></span><span style="color: #0000BB">$db </span><span style="color: #007700">= </span><span style="color: #DD0000">"testdb"</span><span style="color: #007700">;</p>
<p></span><span style="color: #FF8000">// open connection<br />
<br /></span><span style="color: #0000BB">$connection </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$host</span><span style="color: #007700">, </span><span style="color: #0000BB">$user</span><span style="color: #007700">, </span><span style="color: #0000BB">$pass</span><span style="color: #007700">) or die (</span><span style="color: #DD0000">"Unable to connect!"</span><span style="color: #007700">);</p>
<p></span><span style="color: #FF8000">// select database<br />
<br /></span><span style="color: #0000BB">mysql_select_db</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">) or die (</span><span style="color: #DD0000">"Unable to select database!"</span><span style="color: #007700">);</p>
<p></span><span style="color: #FF8000">// create query<br />
<br /></span><span style="color: #0000BB">$query </span><span style="color: #007700">= </span><span style="color: #DD0000">"SELECT * FROM symbols"</span><span style="color: #007700">;</p>
<p></span><span style="color: #FF8000">// execute query<br />
<br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">) or die (</span><span style="color: #DD0000">"Error in query: $query. "</span><span style="color: #007700">.</span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">());</p>
<p></span><span style="color: #FF8000">// see if any rows were returned<br />
<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">mysql_num_rows</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">) &gt; </span><span style="color: #0000BB">0</span><span style="color: #007700">) {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">// yes<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;// print them one after another<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo </span><span style="color: #DD0000">"&lt;table cellpadding=10 border=1&gt;"</span><span style="color: #007700">;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;while(</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_fetch_assoc</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">)) {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;tr&gt;"</span><span style="color: #007700">;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;td&gt;"</span><span style="color: #007700">.</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'id'</span><span style="color: #007700">].</span><span style="color: #DD0000">"&lt;/td&gt;"</span><span style="color: #007700">;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;td&gt;"</span><span style="color: #007700">.</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'country'</span><span style="color: #007700">].</span><span style="color: #DD0000">"&lt;/td&gt;"</span><span style="color: #007700">;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;td&gt;"</span><span style="color: #007700">.</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'animal'</span><span style="color: #007700">].</span><span style="color: #DD0000">"&lt;/td&gt;"</span><span style="color: #007700">;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;/tr&gt;"</span><span style="color: #007700">;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;/table&gt;"</span><span style="color: #007700">;<br />
<br />}<br />
<br />else {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">// no<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;// print status message<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo </span><span style="color: #DD0000">"No rows found!"</span><span style="color: #007700">;</p>
<p>}</p>
<p></span><span style="color: #FF8000">// free result set memory<br />
<br /></span><span style="color: #0000BB">mysql_free_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);</p>
<p></span><span style="color: #FF8000">// close connection<br />
<br /></span><span style="color: #0000BB">mysql_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$connection</span><span style="color: #007700">);</p>
<p></span><span style="color: #0000BB">?&gt;<br />
<br /></span></p>
<p>&lt;/body&gt;<br />
<br />&lt;/html&gt;</span><br />
</code>
</p>
<p>
Notice that in this case, field values are accessed using the field<br />
name instead of the index.
</p>
<p>
Of all the alternatives, however, the function I like the most is<br />
the <code>mysql_fetch_object()</code> function, which returns each<br />
row as an object (remember them from <a href="php101-7.php">Part Seven</a>?) with properties<br />
corresponding to the field names:
</p>
<p>
<code class="tutorialExample"><span style="color: #000000"><br />
&lt;html&gt;<br />
<br />&lt;head&gt;<br />
<br />&lt;basefont face="Arial"&gt;<br />
<br />&lt;/head&gt;<br />
<br />&lt;body&gt;</p>
<p><span style="color: #0000BB">&lt;?php</p>
<p></span><span style="color: #FF8000">// set server access variables<br />
<br /></span><span style="color: #0000BB">$host </span><span style="color: #007700">= </span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">;</p>
<p></span><span style="color: #0000BB">$user </span><span style="color: #007700">= </span><span style="color: #DD0000">"test"</span><span style="color: #007700">;<br />
<br /></span><span style="color: #0000BB">$pass </span><span style="color: #007700">= </span><span style="color: #DD0000">"test"</span><span style="color: #007700">;<br />
<br /></span><span style="color: #0000BB">$db </span><span style="color: #007700">= </span><span style="color: #DD0000">"testdb"</span><span style="color: #007700">;</p>
<p></span><span style="color: #FF8000">// open connection<br />
<br /></span><span style="color: #0000BB">$connection </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$host</span><span style="color: #007700">, </span><span style="color: #0000BB">$user</span><span style="color: #007700">, </span><span style="color: #0000BB">$pass</span><span style="color: #007700">) or die (</span><span style="color: #DD0000">"Unable to connect!"</span><span style="color: #007700">);</p>
<p></span><span style="color: #FF8000">// select database<br />
<br /></span><span style="color: #0000BB">mysql_select_db</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">) or die (</span><span style="color: #DD0000">"Unable to select database!"</span><span style="color: #007700">);</p>
<p></span><span style="color: #FF8000">// create query<br />
<br /></span><span style="color: #0000BB">$query </span><span style="color: #007700">= </span><span style="color: #DD0000">"SELECT * FROM symbols"</span><span style="color: #007700">;</p>
<p></span><span style="color: #FF8000">// execute query<br />
<br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">) or die (</span><span style="color: #DD0000">"Error in query: $query. "</span><span style="color: #007700">.</span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">());</p>
<p></span><span style="color: #FF8000">// see if any rows were returned<br />
<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">mysql_num_rows</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">) &gt; </span><span style="color: #0000BB">0</span><span style="color: #007700">) {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">// yes<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;// print them one after another<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo </span><span style="color: #DD0000">"&lt;table cellpadding=10 border=1&gt;"</span><span style="color: #007700">;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;while(</span><span style="color: #0000BB">$row&nbsp;&nbsp;</span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_fetch_object</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">)) {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;tr&gt;"</span><span style="color: #007700">;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;td&gt;"</span><span style="color: #007700">.</span><span style="color: #0000BB">$row</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">id</span><span style="color: #007700">.</span><span style="color: #DD0000">"&lt;/td&gt;"</span><span style="color: #007700">;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;td&gt;"</span><span style="color: #007700">.</span><span style="color: #0000BB">$row</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">country</span><span style="color: #007700">.</span><span style="color: #DD0000">"&lt;/td&gt;"</span><span style="color: #007700">;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;td&gt;"</span><span style="color: #007700">.</span><span style="color: #0000BB">$row</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">animal</span><span style="color: #007700">.</span><span style="color: #DD0000">"&lt;/td&gt;"</span><span style="color: #007700">;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;/tr&gt;"</span><span style="color: #007700">;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;/table&gt;"</span><span style="color: #007700">;<br />
<br />}<br />
<br />else {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">// no<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;// print status message<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo </span><span style="color: #DD0000">"No rows found!"</span><span style="color: #007700">;</p>
<p>}</p>
<p></span><span style="color: #FF8000">// free result set memory<br />
<br /></span><span style="color: #0000BB">mysql_free_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);</p>
<p></span><span style="color: #FF8000">// close connection<br />
<br /></span><span style="color: #0000BB">mysql_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$connection</span><span style="color: #007700">);</p>
<p></span><span style="color: #0000BB">?&gt;<br />
<br /></span></p>
<p>&lt;/body&gt;<br />
<br />&lt;/html&gt;</span><br />
</code>
</p>
<p>
Here, each <code>$row</code> object is created with properties<br />
corresponding to the field names in that row. Row values can<br />
thus be accessed using standard <code>object-&gt;property</code><br />
notation.
</p>
<p>If you&#8217;re the type that likes to have your cake and eat it too, you<br />
will probably enjoy the <code>mysql_fetch_array()</code> function, which<br />
returns both an associative array and a numerically-indexed array, a<br />
combination of the <code>mysql_fetch_row()</code> and<br />
<code>mysql_fetch_assoc()</code> functions. Read about it at<br />
<a href="http://www.php.net/manual/en/function.mysql-fetch-array.php" target = "_blank">http://www.php.net/manual/en/function.mysql-fetch-array.php</a>.
</p>
<p><a name='Heading6'></a><br />
<h2 align='left'>&#8230;for Different Folks</h2>
<p>
If you&#8217;re using PHP 5, you can do the same thing using the new</p>
<p><code>ext/mysqli</code> extension, which offers a number of new features. This<br />
extension can be used in two ways: procedural (using functions), and<br />
object-oriented (using class methods and properties). Consider the next<br />
script, which uses <code>ext/mysqli</code> in a procedural manner:
</p>
<p>
<code class="tutorialExample"><span style="color: #000000"><br />
&lt;html&gt;<br />
<br />&lt;head&gt;<br />
<br />&lt;basefont face="Arial"&gt;<br />
<br />&lt;/head&gt;</p>
<p>&lt;body&gt;</p>
<p><span style="color: #0000BB">&lt;?php</p>
<p></span><span style="color: #FF8000">// set server access variables<br />
<br /></span><span style="color: #0000BB">$host </span><span style="color: #007700">= </span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">;<br />
<br /></span><span style="color: #0000BB">$user </span><span style="color: #007700">= </span><span style="color: #DD0000">"test"</span><span style="color: #007700">;<br />
<br /></span><span style="color: #0000BB">$pass </span><span style="color: #007700">= </span><span style="color: #DD0000">"test"</span><span style="color: #007700">;</p>
<p></span><span style="color: #0000BB">$db </span><span style="color: #007700">= </span><span style="color: #DD0000">"testdb"</span><span style="color: #007700">;</p>
<p></span><span style="color: #FF8000">// open connection<br />
<br /></span><span style="color: #0000BB">$connection </span><span style="color: #007700">= </span><span style="color: #0000BB"><a target="_blank" href="/manual/function.mysqli-connect.php">mysqli_connect</a></span><span style="color: #007700">(</span><span style="color: #0000BB">$host</span><span style="color: #007700">, </span><span style="color: #0000BB">$user</span><span style="color: #007700">, </span><span style="color: #0000BB">$pass</span><span style="color: #007700">, </span><span style="color: #0000BB">$db</span><span style="color: #007700">) or die (</span><span style="color: #DD0000">"Unable to connect!"</span><span style="color: #007700">);</p>
<p></span><span style="color: #FF8000">// create query<br />
<br /></span><span style="color: #0000BB">$query </span><span style="color: #007700">= </span><span style="color: #DD0000">"SELECT * FROM symbols"</span><span style="color: #007700">;</p>
<p></span><span style="color: #FF8000">// execute query<br />
<br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB"><a target="_blank" href="/manual/function.mysqli-query.php">mysqli_query</a></span><span style="color: #007700">(</span><span style="color: #0000BB">$connection</span><span style="color: #007700">, </span><span style="color: #0000BB">$query</span><span style="color: #007700">) or die (</span><span style="color: #DD0000">"Error in query: $query. "</span><span style="color: #007700">.</span><span style="color: #0000BB"><a target="_blank" href="/manual/function.mysqli-error.php">mysqli_error</a></span><span style="color: #007700">());</p>
<p></span><span style="color: #FF8000">// see if any rows were returned<br />
<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB"><a target="_blank" href="/manual/function.mysqli-num-rows.php">mysqli_num_rows</a></span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">) &gt; </span><span style="color: #0000BB">0</span><span style="color: #007700">) {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">// yes<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;// print them one after another<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo </span><span style="color: #DD0000">"&lt;table cellpadding=10 border=1&gt;"</span><span style="color: #007700">;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;while(</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB"><a target="_blank" href="/manual/function.mysqli-fetch-row.php">mysqli_fetch_row</a></span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">)) {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;tr&gt;"</span><span style="color: #007700">;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;td&gt;"</span><span style="color: #007700">.</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">].</span><span style="color: #DD0000">"&lt;/td&gt;"</span><span style="color: #007700">;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;td&gt;"</span><span style="color: #007700">.</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">].</span><span style="color: #DD0000">"&lt;/td&gt;"</span><span style="color: #007700">;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;td&gt;"</span><span style="color: #007700">.</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">2</span><span style="color: #007700">].</span><span style="color: #DD0000">"&lt;/td&gt;"</span><span style="color: #007700">;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;/tr&gt;"</span><span style="color: #007700">;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;/table&gt;"</span><span style="color: #007700">;<br />
<br />}<br />
<br />else {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">// no<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;// print status message<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo </span><span style="color: #DD0000">"No rows found!"</span><span style="color: #007700">;</p>
<p>}</p>
<p></span><span style="color: #FF8000">// free result set memory<br />
<br /></span><span style="color: #0000BB"><a target="_blank" href="/manual/function.mysqli-free-result.php">mysqli_free_result</a></span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);</p>
<p></span><span style="color: #FF8000">// close connection<br />
<br /></span><span style="color: #0000BB"><a target="_blank" href="/manual/function.mysqli-close.php">mysqli_close</a></span><span style="color: #007700">(</span><span style="color: #0000BB">$connection</span><span style="color: #007700">);</p>
<p></span><span style="color: #0000BB">?&gt;<br />
<br /></span></p>
<p>&lt;/body&gt;<br />
<br />&lt;/html&gt;<br />
<br /></span><br />
</code>
</p>
<p>
As you can see, this looks a lot like the code written for<br />
<code>ext/mysql</code>. The only real difference &#8211; at least to the naked eye<br />
- is the fact that function names now begin with mysqli_* instead of mysql_*.<br />
Of course, there are a whole bunch of differences under the hood:<br />
<code>ext/mysqli</code> is faster, more secure and more powerful than regular<br />
<code>ext/mysql</code>, and also includes support for prepared statements,<br />
bound result sets, multiple simultaneous queries, transactions and a whole<br />
bunch of other cool stuff.
</p>
<p>
You can also use <code>ext/mysqli</code> in an object-oriented way,<br />
where each task &#8211; connecting, querying, fetching &#8211; is actually a method<br />
of the <code>mysqli()</code> object:
</p>
<p>
<code class="tutorialExample"><span style="color: #000000"><br />
&lt;html&gt;<br />
<br />&lt;head&gt;<br />
<br />&lt;basefont face="Arial"&gt;</p>
<p>&lt;/head&gt;<br />
<br />&lt;body&gt;</p>
<p><span style="color: #0000BB">&lt;?php</p>
<p></span><span style="color: #FF8000">// set server access variables<br />
<br /></span><span style="color: #0000BB">$host </span><span style="color: #007700">= </span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">;<br />
<br /></span><span style="color: #0000BB">$user </span><span style="color: #007700">= </span><span style="color: #DD0000">"test"</span><span style="color: #007700">;<br />
<br /></span><span style="color: #0000BB">$pass </span><span style="color: #007700">= </span><span style="color: #DD0000">"test"</span><span style="color: #007700">;</p>
<p></span><span style="color: #0000BB">$db </span><span style="color: #007700">= </span><span style="color: #DD0000">"testdb"</span><span style="color: #007700">;</p>
<p></span><span style="color: #FF8000">// create mysqli object<br />
<br />// open connection<br />
<br /></span><span style="color: #0000BB">$mysqli </span><span style="color: #007700">= new </span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #0000BB">$host</span><span style="color: #007700">, </span><span style="color: #0000BB">$user</span><span style="color: #007700">, </span><span style="color: #0000BB">$pass</span><span style="color: #007700">, </span><span style="color: #0000BB">$db</span><span style="color: #007700">);</p>
<p></span><span style="color: #FF8000">// check for connection errors<br />
<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">mysqli_connect_errno</span><span style="color: #007700">()) {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;die(</span><span style="color: #DD0000">"Unable to connect!"</span><span style="color: #007700">);<br />
<br />}</p>
<p></span><span style="color: #FF8000">// create query<br />
<br /></span><span style="color: #0000BB">$query </span><span style="color: #007700">= </span><span style="color: #DD0000">"SELECT * FROM symbols"</span><span style="color: #007700">;</p>
<p></span><span style="color: #FF8000">// execute query</p>
<p></span><span style="color: #007700">if (</span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">)) {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">// see if any rows were returned<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">if (</span><span style="color: #0000BB">$result</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">num_rows </span><span style="color: #007700">&gt; </span><span style="color: #0000BB">0</span><span style="color: #007700">) {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">// yes<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// print them one after another<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo </span><span style="color: #DD0000">"&lt;table cellpadding=10 border=1&gt;"</span><span style="color: #007700">;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while(</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">$result</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch_array</span><span style="color: #007700">()) {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;tr&gt;"</span><span style="color: #007700">;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;td&gt;"</span><span style="color: #007700">.</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">].</span><span style="color: #DD0000">"&lt;/td&gt;"</span><span style="color: #007700">;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;td&gt;"</span><span style="color: #007700">.</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">].</span><span style="color: #DD0000">"&lt;/td&gt;"</span><span style="color: #007700">;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;td&gt;"</span><span style="color: #007700">.</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">2</span><span style="color: #007700">].</span><span style="color: #DD0000">"&lt;/td&gt;"</span><span style="color: #007700">;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;/tr&gt;"</span><span style="color: #007700">;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </span><span style="color: #DD0000">"&lt;/table&gt;"</span><span style="color: #007700">;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;else {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">// no<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// print status message<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo </span><span style="color: #DD0000">"No rows found!"</span><span style="color: #007700">;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">// free result set memory<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$result</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">close</span><span style="color: #007700">();</p>
<p>}<br />
<br />else {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">// print error message<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo </span><span style="color: #DD0000">"Error in query: $query. "</span><span style="color: #007700">.</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">error</span><span style="color: #007700">;<br />
<br />}<br />
<br /></span><span style="color: #FF8000">// close connection<br />
<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">close</span><span style="color: #007700">();</p>
<p></span><span style="color: #0000BB">?&gt;<br />
<br /></span><br />
<br />&lt;/body&gt;<br />
<br />&lt;/html&gt;<br />
<br /></span><br />
</code>
</p>
<p>
Here, the <code>new</code> keyword is used to instantiate an object of class<br />
<code>mysqli</code>, and pass the object constructor connection information<br />
(including the database name). The resulting object, stored in the variable</p>
<p><code>$mysqli</code>, then exposes methods and properties to perform the<br />
tasks of querying, fetching and processing rows, and handling errors.
</p>
<p>
If you look closely at the two scripts above, you&#8217;ll notice the numerous<br />
similarities between the function and method names, and the structure of<br />
the script. Of the two, though, the object-oriented method is recommended,<br />
especially in light of the new object model in PHP 5.
</p>
<p>
A couple of other important differences to keep in mind:</p>
<ul>
<li>With <code>ext/mysqli</code>, you can include the database name in the<br />
arguments passed to the <code>mysqli_connect()</code> function or to the<br />
<code>mysqli()</code>constructor.</li>
<li>When calling <code>mysqli_query()</code> or the <code>mysqli</code><br />
object&#8217;s <code>query()</code> method, the link identifier is mandatory,<br />
not optional.</li>
</ul>
<p><a href='http://devzone.zend.com/node/view/id/642'>PHP 101 (part 8): Databases and Other Animals &#8211; Part 2</a></p>
<hr />
<p align='center'>
<i>Copyright Melonfire, 2004 (<a href="http://www.melonfire.com" target='_blank'>http://www.melonfire.com</a>).<br />
All rights reserved.</i></p>
<img src="http://feeds.feedburner.com/~r/PHPDevZone/~4/c7tzcmuIxew" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://devzone.zend.com/12/php-101-part-8-databases-and-other-animals_part-1/feed/</wfw:commentRss>
		<slash:comments>37</slash:comments>
		<feedburner:origLink>http://devzone.zend.com/12/php-101-part-8-databases-and-other-animals_part-1/</feedburner:origLink></item>
		<item>
		<title>Interview with Matthew Weier O’Phinney</title>
		<link>http://feedproxy.google.com/~r/PHPDevZone/~3/7jNgWaAKAb4/</link>
		<comments>http://devzone.zend.com/2106/interview-with-matthew-weier-ophinney/#comments</comments>
		<pubDate>Tue, 21 Feb 2012 15:59:32 +0000</pubDate>
		<dc:creator>Cal Evans (Editor-in-Chief)</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[matthew weier o'phinney]]></category>
		<category><![CDATA[podcast]]></category>
		<category><![CDATA[voices of the elephpant]]></category>

		<guid isPermaLink="false">http://devzone.zend.com/?p=2106</guid>
		<description><![CDATA[I had the great privilege to interview Matthew Weier O'Phinney for my podcast, Voices of the ElePHPant. Click on in and I'll share the details.]]></description>
			<content:encoded><![CDATA[<p>Meanwhile, in another part of the Internet, I had the great privileged of sitting down with Matthew Weier O&#8217;Phinney Chief Architect (Supreme Allied Commander) of Zend Framework and recording an episode of &#8220;<a href="http://voicesoftheelephpant.com" target="_blank">Voices of the ElePHPant</a>&#8221; podcast. In this interview &#8211; as with all Voices of the ElePHPant interviews &#8211; I ask Matthew 3 questions:</p>
<ol>
<li>Since <a href="http://framework.zend.com" target="_blank">Zend Framework</a> is the opposite of the ideals behind the <a href="http://funkatron.com/posts/the-microphp-manifesto.html" target="_blank">Micro PHP Manifesto</a>, what are your thoughts on it?</li>
<li>Zend Framework v2 is close but not done &#8211; should a new project go with v1 or v2?</li>
<li>What is the current state of Zend Framework 2?</li>
</ol>
<p>If you are using Zend Framework or thinking about using it, invest the 20-30 minutes it takes to listen to this interview to get hints as to where things are going. </p>
<p>Give it a listen and leave us a comment. The best way to have your voice heard is get involved in the conversation.  </p>
<img src="http://feeds.feedburner.com/~r/PHPDevZone/~4/7jNgWaAKAb4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://devzone.zend.com/2106/interview-with-matthew-weier-ophinney/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://devzone.zend.com/2106/interview-with-matthew-weier-ophinney/</feedburner:origLink></item>
		<item>
		<title>Andi Gutmans talks of Apps and APIs</title>
		<link>http://feedproxy.google.com/~r/PHPDevZone/~3/-8lga3c98K0/</link>
		<comments>http://devzone.zend.com/2097/andi_gutmans_talks_of_apps_and_apis/#comments</comments>
		<pubDate>Fri, 17 Feb 2012 16:23:02 +0000</pubDate>
		<dc:creator>Cal Evans (Editor-in-Chief)</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[andi gutmans]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[app development]]></category>
		<category><![CDATA[interesting]]></category>

		<guid isPermaLink="false">http://devzone.zend.com/?p=2097</guid>
		<description><![CDATA[The always insightful and devilishly handsome Andi Gutmans recently wrote a very interesting gust blog post for VentureBeat.com. PHP developers should read it but team managers and directors must read it. Click on in, I'll give you the tl;dr and the link to read it once you realize what you missed. ]]></description>
			<content:encoded><![CDATA[<p>Zend co-founder and CEO Andi Gutmans recently wrote an article that was published on VentureBeat.com titled &#8220;<a href="http://venturebeat.com/2012/02/14/app-economy/" target="_blank">How to speak the language of the app economy</a>&#8220;. It is an insightful piece about how things are changing for web developers in general and specifically for PHP developers.</p>
<blockquote><p>
Traditional application development platforms, processes and best practices are being replaced or revitalized with new alternatives that echo what Facebook CEO Mark Zuckerberg terms “The Hacker Way”: rapid, iterative development and continuous integration, building high quality services over time by prototyping, quickly releasing, and fine-tuning through iterations rather than trying to get everything right all at once.
</p></blockquote>
<p>The article is an interesting read for developers but an important read for managers and Directors. If you don&#8217;t understand the concepts that Andi is talking about today, and point your team in their direction tomorrow, you may not have a next year. Grab it, stick it on your tablet or phone and ponder it over lunch or a Latte. Once you know how you feel about it, leave a comment.</p>
<img src="http://feeds.feedburner.com/~r/PHPDevZone/~4/-8lga3c98K0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://devzone.zend.com/2097/andi_gutmans_talks_of_apps_and_apis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://devzone.zend.com/2097/andi_gutmans_talks_of_apps_and_apis/</feedburner:origLink></item>
		<item>
		<title>Spring Conference Roundup</title>
		<link>http://feedproxy.google.com/~r/PHPDevZone/~3/IYDOcAL4EPM/</link>
		<comments>http://devzone.zend.com/2075/spring-conference-roundup/#comments</comments>
		<pubDate>Tue, 14 Feb 2012 05:00:53 +0000</pubDate>
		<dc:creator>Cal Evans (Editor-in-Chief)</dc:creator>
				<category><![CDATA[Events]]></category>

		<guid isPermaLink="false">http://devzone.zend.com/?p=2075</guid>
		<description><![CDATA[Conference season is in full swing, have you made plans to attend one or more this year? Click on in and we'll give you the low down on the ones we know about between now and summer.]]></description>
			<content:encoded><![CDATA[<p>Spring is right around the corner &#8211; or in full bloom, depending on where you are your options for conferences range from awesome to merely great. Here are the ones I have found that are taking place in the first half of the year. They are listed in date order.</p>
<h3><a href="http://www.phpconference.co.uk/" target="_blank">phpUK</a> &#8211; February 24 &#8211; 25, 2012 </h3>
<h4>London &#8211; UK</h4>
<p>PHP London are pleased to announce their 7th annual UK PHP conference, building on the success of previous events by expanding to a double-day event, to accommodate the continual growth of the PHP community and PHP development industry.<br />
<strong>Note:</strong> Come early, they are hosting a special meeting of the phpUK User Group on <a href="http://www.phplondon.org/wiki/February_23rd_2012" target="_blank">Thursday evening, the 23rd</a>.</p>
<h3><a href="http://confoo.ca/en" target="_blank">ConFoo</a> &#8211; February 29 &#8211; March 2, 2012</h3>
<h4>Montréal, Quebec &#8211; CA</h4>
<p>PHP Québec, Montréal-Python, Montreal.rb, Montreal Jug, W3Qc, OWASP Montréal, Android Montreal, are proud to announce the third edition of the ConFoo Conference. From February 29th to March 2nd, 2012, international experts in Java, .Net, PHP, Python and Ruby will present solutions for developers and project managers the prestigious Hilton Bonaventure Hotel, located downtown Montréal.</p>
<h3><a href="http://daycamp4developers.com" target="_blank">Day Camp 4 Developers</a> &#8211; March 3, 2012</h2>
<h4>Online</h4>
<p>[<strong>Disclosure:</strong> I run Day Camp 4 Developers]<br />
Whether you are a freelancer, a moonlighter or a dedicated member of a team, your business skills come into play every day. Day Camp 4 Developers #4: Business 101 will help you hone those skills. Our 6 speakers will present from their real-life experiences as they help you sharpen your existing skills as well and learn new ones. DC4D is an online conference. You participate on your computer or tablet from wherever you are.</p>
<h3><a href="http://whiskyweb.co.uk/" target="_blank">Whisky Web</a> &#8211; April 13 &#8211; 14, 2012</h3>
<h4>Edinburgh &#8211; SF</h4>
<p>The inaugural Whisky Web conference kicks off in Edinburgh on the 13th and 14th of April 2012. A web conference created for the web community, by the web community; Whisky Web will have something to offer everyone who works with the web, be they a designer, a developer or something in between. This is an amazing opportunity to get your geek on in Scotland&#8217;s inspiring capital.</p>
<h3><a href="http://tek12.phparch.com" target="_blank">php|tek</a> &#8211; May 22 &#8211; 25, 2012</h3>
<h4>Chicago, IL &#8211; US</h4>
<p>[<strong>Disclosure:</strong> I host php|tek]<br />
For the sixth year in a row, php|tek is coming to Chicago, come join us! Three days of great sessions, interesting talks and fun networking opportunities. This year&#8217;s theme is &#8220;PHP and Friends&#8221;. Join us as we gather a group of great speakers to show you the tools and technologies PHP developers need to understand in the coming year.</p>
<h3><a href="http://www.phpconference.nl/" target="_blank">Dutch PHP Conference</a> &#8211; June 7-9, 2012</h3>
<h4>Amsterdam &#8211; NL</h4>
<p>We&#8217;re back! And we are glad to announce that we’ll be organising another edition of the Dutch PHP Conference, which will be held in Amsterdam from 7th to 9th June 2012. Thursday 7th will be the tutorial day and June 8th and 9th will be the main conference days. Ticket sales will start on February 15th.</p>
<h3><a href="http://lonestarphp.com/" target="_blank">Lone Star PHP</a> &#8211; June 29 &#8211; 30, 2012 </h3>
<h4>Dallas, TX &#8211; US</h4>
<p>&nbsp;</p>
<h3><a href="http://zendcon.com" target="_blank">ZendCon</a></h3>
<p>Of course, this fall is <a href="http://zendcon.com" target="_blank">ZendCon</a> so save room in your schedule for us. </p>
<h3>GO!</h3>
<p>With so many great conferences to choose from you should be able to find something to fit your schedule and budget. The best way to grow as a developer is to surround yourself with other developers; conferences are the best place to meet those new friends. Sign up for a conference and start learning something new.</p>
<img src="http://feeds.feedburner.com/~r/PHPDevZone/~4/IYDOcAL4EPM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://devzone.zend.com/2075/spring-conference-roundup/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://devzone.zend.com/2075/spring-conference-roundup/</feedburner:origLink></item>
		<item>
		<title>Mayflower releases Zend Framework Application.ini cheatsheet</title>
		<link>http://feedproxy.google.com/~r/PHPDevZone/~3/EQy7psU1uYI/</link>
		<comments>http://devzone.zend.com/2071/mayflower-releases-zend-framework-application-ini-cheatsheet/#comments</comments>
		<pubDate>Thu, 09 Feb 2012 16:15:06 +0000</pubDate>
		<dc:creator>Cal Evans (Editor-in-Chief)</dc:creator>
				<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[application.ini]]></category>
		<category><![CDATA[mayflower]]></category>

		<guid isPermaLink="false">http://devzone.zend.com/?p=2071</guid>
		<description><![CDATA[Those wacky coders over at mayflower.de have released the most comprehensive exampe of a Zend Framework Application.ini that we've ever seen. Click on in, we'll share.]]></description>
			<content:encoded><![CDATA[<p>The Germans have done it again. Florian Eibec, over at Mayflower.de recently posted on their blog that they have taken the time to create a comprehensive guide to Zend Framework&#8217;s Application.ini. In the blog post titled &#8220;<a href="http://blog.mayflower.de/archives/828-Zend-Framework-application.ini-Cheat-Sheet.html" target="_blank">Zend Framework application.ini Cheat-Sheet</a>&#8221; they had this to say.</p>
<blockquote><p>One problem persists [with Zend Framework's Application.ini] although: the documentation. All the parameters for components like View, Session, Database etc. are documented either with the bootstrap resource, the component itself or both. Some of them are even completely undocumented and have to be extracted from the framework source code. Unfortunately there is no reference of all possibilities of the application.ini. To make my life – and that of other Zend Framework developers – a little bit easier, I created such a reference in form of an application.ini file with all possible options, grouped by resource and with some links and explanations.</p></blockquote>
<p>The resulting application.ini can be found on gitup at the <a href="https://github.com/feibeck/application.ini" target="_blank">feibeck/application.ini</a>. Be careful though, it is so complete and beautifully laid out, you may be tempted to print it out and frame it for office art rather than use it and start hacking it up.</p>
<p>As seen on <a href="http://phpdeveloper.org/news/17501" target="_blank">phpdeveloper.org</a>.</p>
<img src="http://feeds.feedburner.com/~r/PHPDevZone/~4/EQy7psU1uYI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://devzone.zend.com/2071/mayflower-releases-zend-framework-application-ini-cheatsheet/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://devzone.zend.com/2071/mayflower-releases-zend-framework-application-ini-cheatsheet/</feedburner:origLink></item>
		<item>
		<title>Using Doctrine 2 in Zend Framework 2</title>
		<link>http://feedproxy.google.com/~r/PHPDevZone/~3/8DT5Hh6Fcik/</link>
		<comments>http://devzone.zend.com/2066/using-doctrine-2-in-zend-framework-2/#comments</comments>
		<pubDate>Mon, 06 Feb 2012 16:37:20 +0000</pubDate>
		<dc:creator>Cal Evans (Editor-in-Chief)</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[doctrine 2]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://devzone.zend.com/?p=2066</guid>
		<description><![CDATA[Over on his blog, Jason Grimes has written a great tutorial on how to integrate  Doctrine 2 into Zend Framework 2. His work is based on Rob Allen's tutorial and is a great next step. Click on in and grab the URL.]]></description>
			<content:encoded><![CDATA[<p>Over on his blog, Jason Grimes has written a very good tutorial titled &#8220;<a href="http://www.jasongrimes.org/2012/01/using-doctrine-2-in-zend-framework-2/" target="_blank">Using Doctrine 2 in Zend Framework 2</a>&#8220;. He bases his work on <a href="http://akrabat.com/getting-started-with-zend-framework-2/" target="_blank">Rob Allen&#8217;s Zend Framework 2 tutorial</a> and shows you how to take that and then add Doctrine 2 into the mix.</p>
<blockquote><p>After working through that [Rob Allen's] tutorial, the next thing I wanted to do was figure out how to get the Doctrine 2 ORM up and running.<br />
<br />
This article shows how to set up and use Doctrine 2 in Zend Framework 2, by extending Rob’s Getting Started tutorial to use Doctrine instead of Zend_Db.
</p></blockquote>
<p>Jame&#8217;s tutorial is long on the how but short on the why. If you are just looking for the steps to take, this is a great piece. If however, you are wondering <strong>why</strong> you take each step and what the ramifications are, well, you&#8217;ll be left a little lost. </p>
<img src="http://feeds.feedburner.com/~r/PHPDevZone/~4/8DT5Hh6Fcik" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://devzone.zend.com/2066/using-doctrine-2-in-zend-framework-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://devzone.zend.com/2066/using-doctrine-2-in-zend-framework-2/</feedburner:origLink></item>
		<item>
		<title>Press Release Roundup – Zend Server on OSX and phpcloud.com</title>
		<link>http://feedproxy.google.com/~r/PHPDevZone/~3/dZSHJD3OJpw/</link>
		<comments>http://devzone.zend.com/2063/press-release-roundup-zend-server-on-osx-and-phpcloud-com/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 14:37:20 +0000</pubDate>
		<dc:creator>Cal Evans (Editor-in-Chief)</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[phpcloud.com]]></category>
		<category><![CDATA[Zend Server]]></category>

		<guid isPermaLink="false">http://devzone.zend.com/?p=2063</guid>
		<description><![CDATA[Here at Zend we get a lot of good press for our products. We don't want to turn DevZone into just a feed for those that write cool things about us, but some of these are helpful if you are considering using our products. So instead of flooding your feed with individual articles about how great the products are, occasionally we'll post a roundup.  That way they won't get in your way, but there are here when you need them.
]]></description>
			<content:encoded><![CDATA[<p>Here at Zend we get a lot of good press for our products. We don&#8217;t want to turn DevZone into just a feed for those that write cool things about us, but some of these are helpful if you are considering using our products. So instead of flooding your feed with individual articles about how great the products are, occasionally we&#8217;ll post a roundup.  That way they won&#8217;t get in your way, but there are here when you need them.</p>
<h2>Zend Server on OSX</h2>
<p>This is one of the most requested features of Zend Server and now that it is available, people are talking about it. </p>
<h3>Dr. Dobbs</h3>
<p>Dr. Dobbs covered Zend Server on OSX in the tools section of their blog recently with an article titled &#8220;<a href="http://drdobbs.com/tools/232500263" target="_blank">Zend Server 5.6 Now Supports Mac OS X</a>&#8220;. In that article posted on January 22, 2012, they had this to say.</p>
<blockquote><p>
The 5.6 version release ships with a fully integrated PHP stack including the latest PHP runtime and the Zend Framework, plus monitoring and diagnostics. There are code acceleration and performance optimization technologies such as the Job Queue function, as well as full page caching and data caching to help developers improve application response times and reduce server load.
</p></blockquote>
<h3>ServerWatch</h3>
<p>Over at ServerWatch.com Vangie Beal wrote a nice post titled &#8220;<a href="http://www.serverwatch.com/server-news/new-zend-server-release-supports-mac-os-x-platform-developers.html" target="_blank">New Zend Server Release Supports Mac OS X Platform Developers</a>&#8220;. Here is what Beal had to say.</p>
<blockquote><p>
For the growing numbers of IT organizations using PHP and bringing Macs into the development environment, Zend said its 5.6 release offers important advantages for both app performance and quality, and productive collaboration on the web and in the cloud.
</p></blockquote>
<p>Both articles are short reads but interesting if you are considering introducing Zend Server on OSX into your development team.</p>
<h2>phpcloud.com</h2>
<p>The newest member of the Zend product lineup, phpcloud.com, got a little love as well. InfoWorld.com recently posted a nice review of it titled &#8220;<a href="http://www.infoworld.com/d/cloud-computing/first-look-zends-php-developer-cloud-183766?page=0,0" target="_blank">First look: Zend&#8217;s PHP developer cloud</a>&#8220;. Author Rick Grehan takes a nice, in-depth look at phpcloud.com and has this to say about it.</p>
<blockquote><p>
When you consider the cloud, you typically imagine a realm of deployed, production applications. Zend Developer Cloud (ZDC) adds a twist: ZDC creates a place in the cloud where PHP-based applications can be developed for the cloud. No more developing locally, then deploying into the cloud &#8212; ZDC pushes both into the ether.
</p></blockquote>
<p>This article is a bit longer than the other two but a great read none the less.</p>
<img src="http://feeds.feedburner.com/~r/PHPDevZone/~4/dZSHJD3OJpw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://devzone.zend.com/2063/press-release-roundup-zend-server-on-osx-and-phpcloud-com/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://devzone.zend.com/2063/press-release-roundup-zend-server-on-osx-and-phpcloud-com/</feedburner:origLink></item>
		<item>
		<title>Using ClamAV with Zend Framework</title>
		<link>http://feedproxy.google.com/~r/PHPDevZone/~3/dyJ3nMnlhaM/</link>
		<comments>http://devzone.zend.com/2057/using-clamav-with-zend-framework/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 14:50:08 +0000</pubDate>
		<dc:creator>Cal Evans (Editor-in-Chief)</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[clamAV]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[zend validate]]></category>

		<guid isPermaLink="false">http://devzone.zend.com/?p=2057</guid>
		<description><![CDATA[Want to check your file uploads with ClamAV? We've got a link to a tutorial to show you how.]]></description>
			<content:encoded><![CDATA[<p>Scanning file uploads for viruses is a time honored tradition. We all know why it&#8217;s a good idea but sometimes it&#8217;s not easy to do. If you use Zend Framework, we&#8217;ve got good new for you. <a title="Posts by Matthew Setter" href="http://phpmaster.com/author/msetter/" rel="author">Matthew Setter</a> has put together a tutorial on how to build a validator to help you scan them automatically. Here&#8217;s a taste of what you&#8217;ll get from Matthew&#8217;s article titled &#8220;<a href="http://phpmaster.com/zf-clamav/" target="_blank">ClamAV as a Validation Filter in Zend Framework</a>&#8221;</p>
<blockquote><p>Ok, so you’re pretty comfortable with using the Zend Framework, specifically the use of Forms. Along with that, you have a good working knowledge of how to combine a host of <a href="http://framework.zend.com/manual/en/zend.validate.html">standard validators</a> such as <em>CreditCard</em>, <em>EmailAddress</em>, <em>Db_RecordExists</em>, and <em>Hex</em>, and <a href="http://framework.zend.com/manual/en/zend.filter.html">standard filters</a> such as <em>Compress/Decompress</em>, <em>BaseName</em>, <em>Encrypt</em>, and <em>RealPath</em>. But what do you do when a situation arises that’s outside the scope of the pre-packaged validators and filters?</p>
<p>Let’s say you want to guard against users uploading files that contain viruses, for example. You would have to write a custom validator that checks the uploads aren’t infected. Today I’ll show you how to do just that – how to write a new file validation filter for Zend Framework that uses <a href="http://www.clamav.net/lang/en/">ClamAV</a> to ensure uploaded files are virus-free.</p></blockquote>
<p>It&#8217;s not a beginner level tutorial but it is well written and a great explanation of how to built a custom validator.</p>
<img src="http://feeds.feedburner.com/~r/PHPDevZone/~4/dyJ3nMnlhaM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://devzone.zend.com/2057/using-clamav-with-zend-framework/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://devzone.zend.com/2057/using-clamav-with-zend-framework/</feedburner:origLink></item>
		<item>
		<title>Zend Developer Pulse</title>
		<link>http://feedproxy.google.com/~r/PHPDevZone/~3/r_ir0O5gVkU/</link>
		<comments>http://devzone.zend.com/2049/zend-developer-pulse/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 15:48:36 +0000</pubDate>
		<dc:creator>Cal Evans (Editor-in-Chief)</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[music]]></category>
		<category><![CDATA[Press Release]]></category>
		<category><![CDATA[report]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://devzone.zend.com/?p=2049</guid>
		<description><![CDATA[There’s a new survey series worth checking out called the Zend Developer Pulse™. Zend is taking the pulse of developers regarding technology and career topics. Findings from the first survey, conducted online in Q4 2011, are available in a summary report. Zend received over 3,000 responses in 48 hours. Not bad. Take a peek at the report, and send your feedback to Zend.

]]></description>
			<content:encoded><![CDATA[<p>ZEND DEVELOPER PULSE<sup>™</sup><br />
<em>A new survey series that asks developers for their perspectives on technology and career prospects for 2012  </em><br />
The goal of this new survey series is to capture and share developer perspectives with people in and outside the developer community who may be curious, interested or passionate about PHP. Here are a few highlights from the survey findings.</p>
<h2>Survey Highlights</h2>
<p><strong>Tech Investment and Developer Focus Areas for 2012</strong></p>
<p>Key areas of technology investment are revealed by the types of projects that developers expect to tackle as well as their priorities for career and skills development in the new year.</p>
<p>Key project focus areas:</p>
<ul>
<li>66 percent of developers will be engaged in mobile app development projects</li>
<li>For each of these four key technology areas — APIs, cloud, social media integration, and big data/analytics — between 40-50 percent of developers said they will have projects underway in 2012</li>
</ul>
<p>Career and skills development priorities:</p>
<ul>
<li>Next-generation UI development scored high both in the large enterprise and overall (75 percent)</li>
<li>67 percent of all developers surveyed are looking to hone their app development skills on mobile platforms, and 46 percent in cloud computing environments</li>
<li>As one might expect, among corporate developers at companies over 100 employees, another priority is gaining expertise with Big Data/analytics (44 percent)</li>
</ul>
<p>&nbsp;</p>
<h2>Cloud Opportunities on the Rise</h2>
<ul>
<li>More than 60 percent intend to use some form of public cloud in their development projects. Inside the <a href="http://www.zend.com/topics/zend-developer-pulse-survey-report-0112-EN.pdf">Zend Developer Pulse<sup>™</sup> Survey Report</a>, you can find out which public clouds developers are working in now</li>
<li>As far as skills are concerned, 46 percent of all developers surveyed are looking to hone their skills in cloud computing. This result is consistent with the high level of interest that Zend is seeing at <a href="http://www.phpcloud.com/">phpcloud.com</a>, where developers are actively building apps for the cloud, in the cloud, in the free <a href="http://www.phpcloud.com/develop">Zend Developer Cloud</a> sandbox.</li>
</ul>
<p>&nbsp;</p>
<p><strong>State of Languages</strong></p>
<p>The new norm among developers is use of multiple languages, and rising use of dynamic open source languages, and the Zend Developer Pulse<sup>™</sup> survey echoes this trend.</p>
<ul>
<li>Four languages, PHP, C, Java and Javascript dominated survey results, with a number of other languages trailing far behind</li>
<li>Developers reported using 1-2 additional languages on a regular basis; as high as 33 percent of enterprise developers report using both PHP and Java</li>
<li>Two-thirds of all developers surveyed spend more than 50 percent of their time with PHP, using PHP as their core language; this includes an uptake of PHP in the enterprise</li>
</ul>
<p><strong> </strong></p>
<p><strong>Increasing Demand for PHP Skills</strong></p>
<p>From an employment perspective, more than half of developers surveyed see increasing demand for PHP skills in 2011-12. Inside the report, you can find out how this aligns with the findings of leading online job search companies, what developers are saying about language use today, and what other skills they’re looking to add to their bag of tricks.</p>
<p><strong> </strong></p>
<p><strong>Just for Fun</strong></p>
<p>It turns out that 86% of developers surveyed prefer to listen to music while coding, so Zend asked about their music preferences.  To get 2012 off to a good start, developers shared their New Year’s resolutions, also captured in the report.</p>
<p>Developers are invited to contribute suggestions and questions they’d like to see addressed in future Zend Developer Pulse<sup>™</sup> survey reports. It’s as easy as sending an email to <a href="mailto:developerpulse@zend.com"><strong>developerpulse@zend.com</strong></a><strong>.</strong></p>
<p><strong> </strong></p>
<img src="http://feeds.feedburner.com/~r/PHPDevZone/~4/r_ir0O5gVkU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://devzone.zend.com/2049/zend-developer-pulse/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://devzone.zend.com/2049/zend-developer-pulse/</feedburner:origLink></item>
		<item>
		<title>phpcloud.com Quickstart guide</title>
		<link>http://feedproxy.google.com/~r/PHPDevZone/~3/eqaoR-52NZ8/</link>
		<comments>http://devzone.zend.com/2031/phpcloud-com-quickstart-guide/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 15:52:17 +0000</pubDate>
		<dc:creator>Cal Evans (Editor-in-Chief)</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[container]]></category>
		<category><![CDATA[phpcloud]]></category>

		<guid isPermaLink="false">http://devzone.zend.com/?p=2031</guid>
		<description><![CDATA[Got your beta invite to phpcloud.com but not sure where to start. Read on, we'll take a look at the concepts involved and the staps to take to not only get up and running quickly but to be productive in this interesting tool.]]></description>
			<content:encoded><![CDATA[<p>So, you&#8217;ve gotten your invite to <a href="http://phpcloud.com" target="_blank">phpcloud.com</a> and you are ready to fire it up and start building cool things. The question is always &#8220;Where to start?&#8221; Give me 5 minutes, and I&#8217;ll explain a few things.</p>
<p><a href="http://devzone.zend.com/wp-content/uploads/2011/12/Get-started-now-button.png"><img src="http://devzone.zend.com/wp-content/uploads/2011/12/Get-started-now-button.png" alt="" title="Get-started-now-button" width="197" height="104" class="alignleft size-full wp-image-2032" /></a> When you log into phpcloud.com for the first time, you are presented with a screen that has a big blue button, &#8220;Start Now&#8221;. Clicking this button is the first step. WAIT! Before you click it, let&#8217;s cover a few things.</p>
<p>First, what you are about to create is a &#8220;Container&#8221;.  Containers can contain multiple applications and all share a database. Containers can be cloned by taking a snapshot. In some cases, you will want to run a single application in a single container. Other times &#8211; as long as you are careful to avoid database table name collisions &#8211; it&#8217;s fine to run multiple applications inside a single container. If it&#8217;s easier, think of a container as a server instance. Whatever you would normally do on a single server, do that with your container.</p>
<p>You are going to have to name your container and the thing you need to know is that the container namespace is global. (Someone already has &#8220;test, I checked) As with everything, if you are just playing around, your container name doesn&#8217;t really matter since no one else will see it. However, if you are setting up your development environment for work, useful names are better than Loony Tunes Character names. </p>
<p>Once you understand what a container is and what you are going to call it, go ahead and click the big blue button. Fill out the form &#8211; don&#8217;t use password as the actual password &#8211; and click the &#8220;create Container&#8221; button. phpcloud.com will tell you if your password is weak, normal or strong but it won&#8217;t prevent you from using a weak password. </p>
<p>Since this is a fly-by, we&#8217;ll skip discussing how to setup an SMTP server but if your application is going to send mail using the mail() function in PHP, you will need to configure one at some point.</p>
<p>Now we play the <a href="http://www.youtube.com/watch?v=t4Oh7U_L6hs" target="_blank">waiting game</a>. Fortunately for us, it usually takes about 30 seconds to create a new container. While you are waiting, go ahead and download your access key in the proper format. This is your only way to access the code and database in your new container. Because this is a cloud container and not a specific server, you can&#8217;t just ssh in and see your code. You can however, create ssh tunnels so you can use your favorite IDE or MySQL tool. There&#8217;s a good <a href="https://my.phpcloud.com/help/ssh-tunnel-overview" target="_blank">tunneling overview</a> that will show you want you can and can&#8217;t do with an ssh tunnel. Of course you will also need your keys to deploy code either over sftp or git.</p>
<p>Containers are all well and good but they do nothing but contain things. To actually make something happen, we need to setup an application. As mentioned above in the discussion of containers, you can have as many applications in a container as you need. The only caveat is that they all share a common database.</p>
<p>When you created your container you automatically created the default application inside of your container. This default application is an empty PHP application ready for you to start pouring code into. If that is what you need, you can use the default application and not worry about adding applications. If your needs are different though, you can delete the default application and install a new one. phpcloud.com&#8217;s application installer lets you setup an empty PHP application, a Zend Framework (1 or 2) application, or one of five open source packages.</p>
<p>Once you have your application setup, you can setup git or sfpt access to start deploying code or you can create other applications inside your container. </p>
<p>That&#8217;s it, you are now up and running. If you installed WordPress, you can go to the admin page and log-in. If you created an empty application (Zend Framework or other) you can begin pouring code into it and making things work. There is a lot more that you can do with phpcloud.com; the point of this article was just to get you started.</p>
<img src="http://feeds.feedburner.com/~r/PHPDevZone/~4/eqaoR-52NZ8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://devzone.zend.com/2031/phpcloud-com-quickstart-guide/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://devzone.zend.com/2031/phpcloud-com-quickstart-guide/</feedburner:origLink></item>
	</channel>
</rss>

