<?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>eligeske &#187; MySQL</title>
	<atom:link href="http://eligeske.com/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://eligeske.com</link>
	<description>My day to day journey through the world wide web.</description>
	<lastBuildDate>Tue, 15 Jun 2010 20:39:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP MySQL functions</title>
		<link>http://eligeske.com/mysql/php-mysql-functions/</link>
		<comments>http://eligeske.com/mysql/php-mysql-functions/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 16:27:07 +0000</pubDate>
		<dc:creator>eligeske</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://eligeske.com/?p=78</guid>
		<description><![CDATA[<img src="http://eligeske.com/wp-content/uploads/2009/10/blog_mysqlAndPhp.png" alt="jQuery-Star-Rating" title="jQuery-Star-Rating" width="150" height="150" class="alignnone size-full wp-image-73" /> PHP makes grabbing and inserting data into a MySQL database a breeze.  There are many, many, ways into doing this but here is a couple of the base ways to connect, insert, query, and close connections. Also a little help with comparison and selection SQL Statements. ]]></description>
			<content:encoded><![CDATA[<p>Connecting to MySQL is pretty simple. There are several different ways of doing it through PHP like MySQLi and PDO.  The way I usually do it is creating a mysql class that contains the connect, close, select, insert, and all the other functions readily needed for using PHP and MySQL.  Unfortunately some clients that I work with don’t always use PHP 5 or higher.. <img src='http://eligeske.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />     So here is the way to connect just using functions so that it will work with earlier versions of PHP.</p>
<p>You can assign the database connection properties as variables, contants, or hard coded. Today I am going to pass variables into the function.  You could also get much more detailed with it and make error handling if connection fails, but again… not today.</p>
<p>Also below is all the necessary PHP MySQL function. Check em. Good for Reference when not using a framework.</p>
<h3>MySQL CONNECT</h3>
<div class="wp-synhighlighter-inner"><pre class="php" style="font-family:arial;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_connect"><span style="color: #990000;">mysql_connect</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;DB_HOST&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;DB_USER&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;DB_PASSWORD&quot;</span><span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/mysql_error"><span style="color: #990000;">mysql_error</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div>
<h3>MySQL CLOSE</h3>
<div class="wp-synhighlighter-inner"><pre class="php" style="font-family:arial;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<a href="http://www.php.net/mysql_close"><span style="color: #990000;">mysql_close</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div>
<h3>MySQL QUERIES</h3>
<div class="wp-synhighlighter-inner"><pre class="php" style="font-family:arial;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// INSERT</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO table(field1, field2) VALUES('value1', 'value2' ) &quot;</span><span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/mysql_error"><span style="color: #990000;">mysql_error</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// SELECT</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO table(field1, field2) VALUES('value1', 'value2' ) &quot;</span><span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/mysql_error"><span style="color: #990000;">mysql_error</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// WHERE</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM table WHERE field1='value1'&quot;</span><span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/mysql_error"><span style="color: #990000;">mysql_error</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// ORDER BY</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM table ORDER BY fieldName&quot;</span><span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/mysql_error"><span style="color: #990000;">mysql_error</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// GROUP BY with ORDER BY (NOTE: GROUP BY must come before ORDER BY)</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM table GROUP BY fieldName ORDER BY  fieldName&quot;</span><span style="color: #009900;">&#41;</span> or  <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/mysql_error"><span style="color: #990000;">mysql_error</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// LIMIT</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM `your_table` LIMIT 0, 10&quot;</span><span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/mysql_error"><span style="color: #990000;">mysql_error</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// WHERE CONDITIONALS ..more</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM table WHERE field1='value1' OR field2='value2'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM table WHERE field1='value1' &amp;&amp; field2='value2'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// COMPARISONS</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM table WHERE field1 LIKE value%&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM table WHERE field1 NOT LIKE value%&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM table WHERE field1 LIKE value_&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM table WHERE field1 LIKE value__&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM table WHERE field1 LIKE value%&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// SUB QUERY</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * table1 WHERE table2_id IN(SELECT table2_id FROM table2 WHERE data = data )&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div>
<h3>MySQL CONDITIONALS</h3>
<table class="tableBorder1px" style="1px solid #ccc;" border="0">
<tbody>
<tr>
<td width="110">=</td>
<td width="240">equals</td>
</tr>
<tr>
<td>&lt;</td>
<td>less than</td>
</tr>
<tr>
<td>&gt;</td>
<td>greater than</td>
</tr>
<tr>
<td>&lt;=</td>
<td>less than or equal to</td>
</tr>
<tr>
<td>&gt;=</td>
<td>greater than or equal to</td>
</tr>
<tr>
<td>!=</td>
<td>not equal to</td>
</tr>
<tr>
<td>IS NOT NULL</td>
<td>has any value</td>
</tr>
<tr>
<td>IS NULL</td>
<td>has no value at all</td>
</tr>
<tr>
<td>BETWEEN</td>
<td>within a specified range</td>
</tr>
<tr>
<td>NOT BETWEEN</td>
<td>outside a specified range</td>
</tr>
<tr>
<td>OR</td>
<td>one of two equations are true</td>
</tr>
<tr>
<td>||</td>
<td>same as OR</td>
</tr>
<tr>
<td>AND</td>
<td>both equations are true</td>
</tr>
<tr>
<td>&amp;&amp;</td>
<td>same as AND</td>
</tr>
<tr>
<td>NOT</td>
<td>both equations are false</td>
</tr>
<tr>
<td>!</td>
<td>same as NOT</td>
</tr>
</tbody>
</table>
<h3>MySQL COMPARISONS</h3>
<table class="tableBorder1px" style="width: 300px;" border="0">
<tbody>
<tr>
<td width="110">LIKE</td>
<td width="240">Simple pattern matching</td>
</tr>
<tr>
<td>NOT LIKE</td>
<td>Negation of simple pattern matching</td>
</tr>
<tr>
<td colspan="2">
<table class="tableBorder1px" style="margin-left: 10px; width: 340px;" border="0">
<tbody>
<tr>
<td width="50">%</td>
<td>Matches any number of characters, even zero characters</td>
</tr>
<tr>
<td>_</td>
<td>Matches exactly one character</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>STRCMP()</td>
<td>Compare two strings</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://eligeske.com/mysql/php-mysql-functions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
