<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Quinterox &#187; SQL</title>
	<atom:link href="http://www.quinterox.com/content/category/code/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.quinterox.com/content</link>
	<description>Cesar Quinteros</description>
	<lastBuildDate>Sun, 20 Jun 2010 04:51:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Connecting to a MySQL database</title>
		<link>http://www.quinterox.com/content/code/connecting-to-a-mysql-database/</link>
		<comments>http://www.quinterox.com/content/code/connecting-to-a-mysql-database/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 04:59:19 +0000</pubDate>
		<dc:creator>Cesar Quinteros</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[connecting]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.quinterox.com/content/?p=477</guid>
		<description><![CDATA[Simple steps to connect to and extract data from a MySQL database.]]></description>
			<content:encoded><![CDATA[<p>Below are the steps to connect to and extract data from a MySQL database.</p>
<h3>Connecting to the database</h3>
<p>Step 1. Create and configure some connection variables.</p>
<pre>
$mysql_server = "mysql.yourserver.com";
$mysql_user = "admin";
$mysql_pwd= "password";
$mysql_db= "mydatabase";
</pre>
<p><br class="clear" /><br />
Step 2. Create connection.</p>
<pre>
$mysql_connection =
mysql_connect($mysql_server, $mysql_user, $mysql_pwd);
</pre>
<p><br class="clear" /><br />
Step 3. Select your database.</p>
<pre>
mysql_select_db($mysql_db) or die("Unable to select a database.");
</pre>
<p><br class="clear" /><br />
Step 4. Create your SQL string.</p>
<pre>
$mysql_sql = "SELECT * FROM mytable";
</pre>
<p><br class="clear" /><br />
Step 5. Combine your connection string and your SQL to return data.</p>
<pre>
$mysql_result = mysql_query($mysql_sql, $mysql_connection);
</pre>
<p><br class="clear" /></p>
<h3>Printing the data</h3>
<p>Step 6. Loop through the results and write it to the page. This output&#8217;s format is not pretty since it is meant to be simple.</p>
<pre>
while($data_row = mysql_fetch_row($mysql_result)) {
    foreach($data_row as $data_field) {
        print $data_field;
    }
    print "&lt;br /&gt;";
}
</pre>
<p><br class="clear" /><br />
Step 7. Close the connection string.</p>
<pre>
mysql_close($mysql_connection);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.quinterox.com/content/code/connecting-to-a-mysql-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
