<?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>PHP Tutorials By Kloplop321 &#187; PHPMyAdmin</title>
	<atom:link href="http://kloplop321.com/php-tutorials/index.php/tag/phpmyadmin/feed/" rel="self" type="application/rss+xml" />
	<link>http://kloplop321.com/php-tutorials</link>
	<description>PHP video tutorials, for everyone.</description>
	<lastBuildDate>Sun, 20 Mar 2011 19:03:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>PHP &amp; MySQL Tutorial 08: Mysql Login system concept</title>
		<link>http://kloplop321.com/php-tutorials/index.php/2010/03/12/php-mysql-tutorial-08-mysql-login-system-concept/</link>
		<comments>http://kloplop321.com/php-tutorials/index.php/2010/03/12/php-mysql-tutorial-08-mysql-login-system-concept/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 04:12:20 +0000</pubDate>
		<dc:creator>Kloplop321</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[PHPMyAdmin]]></category>
		<category><![CDATA[Select]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[sessions]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://kloplop321.com/php-tutorials/?p=190</guid>
		<description><![CDATA[This tutorial goes over the concept of a log in system with MySQL with sessions. (The sources are provided after the jump) One of my viewers sent me a message on youtube requesting this great example Dear kloplop321, I really want to make a php, mysql based game. I have an idea about how I [...]]]></description>
			<content:encoded><![CDATA[<p>This tutorial goes over the concept of a log in system with <a href="http://www.mysql.com/">MySQL</a> with <a href="http://en.wikipedia.org/wiki/Session_%28computer_science%29">sessions</a>. (The sources are provided after the jump)<br />
One of my viewers sent me a message on youtube requesting this great example</p>
<blockquote><p>Dear kloplop321,<br />
I really want to make a php, mysql based game. I have an idea about how I am going to do it. I would just really love some help with the SESSION login. There are tutorials on the internet but I find that they don&#8217;t show the full code or stuff like that. So if you would please create a tutorial on it I would apprecitate it. Thanks. </p></blockquote>
<p>This tutorial naturally has the <strong>sources provided</strong>. </p>
<p>The following videos(2) go over the concept of a login system in <a href="http://www.php.net/">PHP</a> while using sessions(to maintain the login status) and MySQL(a database that holds the information). I first go over how to make</p>
<ul>
<li>the login page</li>
<li>the table in the database</li>
<li>a user through <a href="http://www.phpmyadmin.net/home_page/index.php">PHPMyAdmin</a> <sub>[the next tutorial will likely go over registering users]</sub></li>
<li>code how to validate that user and if they are validated</li>
<li>if so, set the session information</li>
<li>if acceptable, they can go to a &#8220;members only&#8221; page <sub>[which only allows identified people in]</sub></li>
<li>a way to log out</li>
</ul>
<p>Again: this tutorial is pretty much a walk-through in concept of a mysql login system.<br />
<object type="application/x-shockwave-flash" style="width: 800px; height: 480px;" data="http://www.youtube.com/v/epo2qPGxZiE&amp;hl=en_US&amp;fs=1&amp;color1=0x006699&amp;color2=0x54abd6"><param name="movie" value="http://www.youtube.com/v/epo2qPGxZiE&amp;hl=en_US&amp;fs=1&amp;color1=0x006699&amp;color2=0x54abd6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param></object></p>
<p>Part 2 (the most important) and the sources after the jump.<br />
<span id="more-190"></span></p>
<p><object type="application/x-shockwave-flash" style="width:800px; height:480px;" data="http://www.youtube.com/v/ir12sxw8lMs&amp;hl=en_US&amp;fs=1&amp;color1=0x006699&amp;color2=0x54abd6"><param name="movie" value="http://www.youtube.com/v/ir12sxw8lMs&amp;hl=en_US&amp;fs=1&amp;color1=0x006699&amp;color2=0x54abd6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param></object></p>
<p>And now the sources.<br />
<strong>include.php</strong></p>
<p><code><span style="color: #000000"><br />
<span style="color: #0000BB">&lt;?php<br /><a href="http://php.net/manual/en/function.session-start.php">session_start</a></span><span style="color: #007700">();</span><span style="color: #FF8000">//start&nbsp;the&nbsp;session<br />//now&nbsp;to&nbsp;do&nbsp;the&nbsp;MySQL&nbsp;connection.<br /></span><span style="color: #0000BB">$link&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB"><a href="http://php.net/manual/en/function.mysql-connect.php">mysql_connect</a></span><span style="color: #007700">(</span><span style="color: #DD0000">'localhost'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'phpuser'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'phppass'</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$link</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;die(</span><span style="color: #DD0000">'Could&nbsp;not&nbsp;connect:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB"><a href="http://php.net/manual/en/function.mysql-error.php">mysql_error</a></span><span style="color: #007700">());<br />}<br /></span><span style="color: #FF8000">//WE&nbsp;NEED&nbsp;to&nbsp;select&nbsp;the&nbsp;database!<br /></span><span style="color: #0000BB"><a href="http://www.php.net/manual/en/function.maxdb-select-db.php">mysql_select_db</a></span><span style="color: #007700">(</span><span style="color: #DD0000">"tutorials_login"</span><span style="color: #007700">);</p>
<p></span><span style="color: #0000BB">?&gt;</span></p>
<p></span><br />
</code></p>
<p><strong>index.php</strong></p>
<p><code><span style="color: #000000"><br />
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700"><a href="http://www.php.net/manual/en/function.include.php">include</a>(</span><span style="color: #DD0000">"include.php"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//see&nbsp;if&nbsp;the&nbsp;person&nbsp;is&nbsp;trying&nbsp;to&nbsp;log&nbsp;in&nbsp;now..<br /></span><span style="color: #007700">if(<a href="http://www.php.net/manual/en/function.isset.php">isset</a>(</span><span style="color: #0000BB">$_REQUEST</span><span style="color: #007700">[</span><span style="color: #DD0000">'sub'</span><span style="color: #007700">])){<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$username&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB"><a href="http://www.php.net/manual/en/function.trim.php">trim</a></span><span style="color: #007700">(</span><span style="color: #0000BB">$_REQUEST</span><span style="color: #007700">[</span><span style="color: #DD0000">'username'</span><span style="color: #007700">]);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$password&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">trim</span><span style="color: #007700">(</span><span style="color: #0000BB">$_REQUEST</span><span style="color: #007700">[</span><span style="color: #DD0000">'password'</span><span style="color: #007700">]);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//make&nbsp;it&nbsp;safe&nbsp;to&nbsp;see&nbsp;if&nbsp;in&nbsp;the&nbsp;table<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$username&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB"><a href="http://www.php.net/manual/en/function.mysql-real-escape-string.php">mysql_real_escape_string</a></span><span style="color: #007700">(</span><span style="color: #0000BB">$username</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$password&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB"><a href="http://www.php.net/manual/en/function.md5.php">md5</a></span><span style="color: #007700">(</span><span style="color: #0000BB">$password</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//time&nbsp;to&nbsp;query<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$sql&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;*&nbsp;FROM&nbsp;`users`&nbsp;WHERE&nbsp;username&nbsp;=&nbsp;'</span><span style="color: #0000BB">$username</span><span style="color: #DD0000">'&nbsp;AND&nbsp;password&nbsp;=&nbsp;'</span><span style="color: #0000BB">$password</span><span style="color: #DD0000">'"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB"><a href="http://www.php.net/manual/en/function.mysql-query.php">mysql_query</a></span><span style="color: #007700">(</span><span style="color: #0000BB">$sql</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$exists&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$userid&nbsp;</span><span style="color: #007700">=&nbsp;-</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;while(</span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB"><a href="http://www.php.net/manual/en/function.mysql-fetch-array.php">mysql_fetch_array</a></span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">)){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$exists&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$userid&nbsp;</span><span style="color: #007700">=&nbsp;(int)</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;</span><span style="color: #FF8000">//get&nbsp;out&nbsp;of&nbsp;the&nbsp;while&nbsp;loop<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">}<br />&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span style="color: #0000BB">$exists</span><span style="color: #007700">){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$_SESSION</span><span style="color: #007700">[</span><span style="color: #DD0000">'isin'</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$_SESSION</span><span style="color: #007700">[</span><span style="color: #DD0000">'userid'</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">$userid</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}else{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"You&nbsp;got&nbsp;something&nbsp;wrong,&nbsp;try&nbsp;again&lt;br&nbsp;/&gt;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//echo&nbsp;$sql;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">}<br />}</span><span style="color: #FF8000">//chopsuey</p>
<p>//detect&nbsp;if&nbsp;logged&nbsp;in&nbsp;via&nbsp;variable&nbsp;in&nbsp;the&nbsp;session<br /></span><span style="color: #007700">if(</span><span style="color: #0000BB">$_SESSION</span><span style="color: #007700">[</span><span style="color: #DD0000">'isin'</span><span style="color: #007700">]&nbsp;==&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">){<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//we&nbsp;are&nbsp;logged&nbsp;in.<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"Hey&nbsp;there,&nbsp;you&nbsp;seem&nbsp;to&nbsp;be&nbsp;logged&nbsp;in,<br />&nbsp;&nbsp;&nbsp;&nbsp;Would&nbsp;you&nbsp;like&nbsp;to&nbsp;go&nbsp;to&nbsp;the&nbsp;&lt;a&nbsp;href=\"membersonly.php\"&gt;Members&nbsp;Only&lt;/a&gt;&nbsp;area?&lt;br&nbsp;/&gt;&nbsp;Or&nbsp;would&nbsp;you&nbsp;want&nbsp;to<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;a&nbsp;href=\"logout.php\"&gt;log&nbsp;out&lt;/a&gt;?"</span><span style="color: #007700">;<br />}else{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//show&nbsp;the&nbsp;login&nbsp;prompt<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">?&gt;<br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&lt;form&nbsp;action="?"&nbsp;method="post"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Username&nbsp;&lt;input&nbsp;type="text"&nbsp;name="username"&nbsp;/&gt;&lt;br&nbsp;/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Password&nbsp;&lt;input&nbsp;type="password"&nbsp;name="password"&nbsp;/&gt;&nbsp;&lt;br&nbsp;/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input&nbsp;type="submit"&nbsp;value="Log&nbsp;in"&nbsp;/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input&nbsp;type="hidden"&nbsp;name="sub"&nbsp;value="1"&nbsp;/&gt;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;/form&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?&gt;</span></p>
<p></span><br />
</code>logout.php</p>
<p><code><span style="color: #000000"><br />
<span style="color: #0000BB">&lt;?php<br />session_start</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">session_destroy</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">"location:&nbsp;index.php"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span><br />
</span><br />
</code></p>
<p><strong>membersonly.php</strong></p>
<p><code><span style="color: #000000"><br />
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">include(</span><span style="color: #DD0000">"include.php"</span><span style="color: #007700">);<br />if(</span><span style="color: #0000BB">$_SESSION</span><span style="color: #007700">[</span><span style="color: #DD0000">'isin'</span><span style="color: #007700">]&nbsp;==&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">){<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Hey&nbsp;there&nbsp;"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$sql&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;*&nbsp;FROM&nbsp;users&nbsp;WHERE&nbsp;id&nbsp;=&nbsp;"</span><span style="color: #007700">.</span><span style="color: #0000BB">$_SESSION</span><span style="color: #007700">[</span><span style="color: #DD0000">'userid'</span><span style="color: #007700">];<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$sql</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">null</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;while(</span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_fetch_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">)){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$info</span><span style="color: #007700">[</span><span style="color: #DD0000">'username'</span><span style="color: #007700">];</span><span style="color: #FF8000">//hey&nbsp;there&nbsp;pickles<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"&nbsp;Would&nbsp;you&nbsp;like&nbsp;to&nbsp;&lt;a&nbsp;href=\"index.php\"&gt;go&nbsp;back&lt;/a&gt;?&nbsp;"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />}else{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//you&nbsp;don't&nbsp;belong&nbsp;here,&nbsp;kick&nbsp;back&nbsp;to&nbsp;the&nbsp;index<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">"location:&nbsp;index.php"</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span></p>
<p></span><br />
</code></p>
<p>Also a tid bit of information: I did this in <a href="http://www.linux.org/">Linux</a>, and I recorded it in 1080p HD!</p>
]]></content:encoded>
			<wfw:commentRss>http://kloplop321.com/php-tutorials/index.php/2010/03/12/php-mysql-tutorial-08-mysql-login-system-concept/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>MySQL and PHPMyAdmin Introduction with PHP 07: A basic Guestbook</title>
		<link>http://kloplop321.com/php-tutorials/index.php/2010/02/15/mysql-and-phpmyadmin-introduction-with-php-07-a-basic-guestbook/</link>
		<comments>http://kloplop321.com/php-tutorials/index.php/2010/02/15/mysql-and-phpmyadmin-introduction-with-php-07-a-basic-guestbook/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 16:05:36 +0000</pubDate>
		<dc:creator>Kloplop321</dc:creator>
				<category><![CDATA[Insert]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[PHPMyAdmin]]></category>
		<category><![CDATA[Select]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[guestbook]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://kloplop321.com/php-tutorials/?p=183</guid>
		<description><![CDATA[This is pretty much a basic &#8220;How to&#8221; for making a very basic guestbook that uses a database instead of text. I go over everything from making the database to the table, the html form and actual posting. If you watch this video you will pretty much see the basic idea of what a guestbook [...]]]></description>
			<content:encoded><![CDATA[<p>This is pretty much a basic &#8220;How to&#8221; for making a very basic guestbook that uses a database instead of text. I go over everything from making the database to the table, the html form and actual posting.  If you watch this video you will pretty much see the basic idea of what a guestbook is, how they work, and how to make a basic one yourself.</p>
<p>This video has two parts, so to understand fully, please watch both.</p>
<p><object type="application/x-shockwave-flash" style="width: 800px; height: 480px;" data="http://www.youtube.com/v/JBGC1CUB13A&amp;hl=en_US&amp;fs=1&amp;color1=0x006699&amp;color2=0x54abd6"><param name="movie" value="http://www.youtube.com/v/JBGC1CUB13A&amp;hl=en_US&amp;fs=1&amp;color1=0x006699&amp;color2=0x54abd6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param></object><br />
Part 2 and the source after the jump<br />
<span id="more-183"></span></p>
<p><object type="application/x-shockwave-flash" style="width: 800px; height: 480px;" data="http://www.youtube.com/v/4wJRZK_6HKo&amp;hl=en_US&amp;fs=1&amp;color1=0x006699&amp;color2=0x54abd6"><param name="movie" value="http://www.youtube.com/v/4wJRZK_6HKo&amp;hl=en_US&amp;fs=1&amp;color1=0x006699&amp;color2=0x54abd6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param></object></p>
<pre><code><span class="webhtml1-specialphpmarker">&lt;?php
</span><span class="webhtml1-specialphpvariableprefix">$link</span><span class="webhtml1-phpwhitespace"> = </span><span class="webhtml1-phpfunction">mysql_connect</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-phpstring">'localhost'</span><span class="webhtml1-phpsymbol">, </span><span class="webhtml1-phpstring">'phpuser'</span><span class="webhtml1-phpsymbol">, </span><span class="webhtml1-phpstring">'phppass'</span><span class="webhtml1-phpsymbol">);
</span><span class="webhtml1-phpkeyword">if</span><span class="webhtml1-phpwhitespace"> (!</span><span class="webhtml1-specialphpvariableprefix">$link</span><span class="webhtml1-phpsymbol">) {
    </span><span class="webhtml1-phpkeyword">die</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-phpstring">'Not connected : '</span><span class="webhtml1-phpwhitespace"> . </span><span class="webhtml1-phpfunction">mysql_error</span><span class="webhtml1-phpsymbol">());
}</span><span class="webhtml1-phpkeyword">else</span><span class="webhtml1-phpsymbol">{
    </span><span class="webhtml1-phpcomment">//echo &quot;I am connected. &quot;;
</span><span class="webhtml1-phpsymbol">}

</span><span class="webhtml1-phpcomment">// make foo the current db
</span><span class="webhtml1-specialphpvariableprefix">$db_selected</span><span class="webhtml1-phpwhitespace"> = </span><span class="webhtml1-phpfunction">mysql_select_db</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-phpstring">'guestbook'</span><span class="webhtml1-phpsymbol">, </span><span class="webhtml1-specialphpvariableprefix">$link</span><span class="webhtml1-phpsymbol">);
</span><span class="webhtml1-phpkeyword">if</span><span class="webhtml1-phpwhitespace"> (!</span><span class="webhtml1-specialphpvariableprefix">$db_selected</span><span class="webhtml1-phpsymbol">) {
    </span><span class="webhtml1-phpkeyword">die</span><span class="webhtml1-phpwhitespace"> (</span><span class="webhtml1-phpstring">'Can</span><span class="webhtml1-phpstringspecial">\'</span><span class="webhtml1-phpstring">t use guestbook DB : '</span><span class="webhtml1-phpwhitespace"> . </span><span class="webhtml1-phpfunction">mysql_error</span><span class="webhtml1-phpsymbol">());
}
</span><span class="webhtml1-specialphpvariableprefix">$name</span><span class="webhtml1-phpwhitespace"> = </span><span class="webhtml1-phpfunction">trim</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-specialphpvariableprefix">$_REQUEST</span><span class="webhtml1-phpsymbol">[</span><span class="webhtml1-phpstring">'name'</span><span class="webhtml1-phpsymbol">]);
</span><span class="webhtml1-specialphpvariableprefix">$comment</span><span class="webhtml1-phpwhitespace"> = </span><span class="webhtml1-phpfunction">trim</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-specialphpvariableprefix">$_REQUEST</span><span class="webhtml1-phpsymbol">[</span><span class="webhtml1-phpstring">'comment'</span><span class="webhtml1-phpsymbol">]);
</span><span class="webhtml1-phpkeyword">if</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-phpfunction">strlen</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-specialphpvariableprefix">$name</span><span class="webhtml1-phpsymbol">)&gt; </span><span class="webhtml1-phpnumber">0</span><span class="webhtml1-phpsymbol">){
    </span><span class="webhtml1-phpkeyword">if</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-phpfunction">strlen</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-specialphpvariableprefix">$comment</span><span class="webhtml1-phpsymbol">)&gt; </span><span class="webhtml1-phpnumber">0</span><span class="webhtml1-phpsymbol">){
        </span><span class="webhtml1-specialphpvariableprefix">$name</span><span class="webhtml1-phpwhitespace"> = </span><span class="webhtml1-phpfunction">mysql_real_escape_string</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-specialphpvariableprefix">$name</span><span class="webhtml1-phpsymbol">);
        </span><span class="webhtml1-specialphpvariableprefix">$comment</span><span class="webhtml1-phpwhitespace"> = </span><span class="webhtml1-phpfunction">mysql_real_escape_string</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-specialphpvariableprefix">$comment</span><span class="webhtml1-phpsymbol">);

        </span><span class="webhtml1-specialphpvariableprefix">$sql</span><span class="webhtml1-phpwhitespace"> = </span><span class="webhtml1-phpstring">&quot;INSERT INTO `guestbook`.`entries` (
`ID` ,
`name` ,
`date` ,
`comment`
)
VALUES (
NULL , '</span><span class="webhtml1-phpstringspecial">$name</span><span class="webhtml1-phpstring">', UNIX_TIMESTAMP( ) , '</span><span class="webhtml1-phpstringspecial">$comment</span><span class="webhtml1-phpstring">'
);&quot;</span><span class="webhtml1-phpsymbol">;
</span><span class="webhtml1-phpfunction">mysql_query</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-specialphpvariableprefix">$sql</span><span class="webhtml1-phpsymbol">);
    }</span><span class="webhtml1-phpkeyword">else</span><span class="webhtml1-phpsymbol">{
        </span><span class="webhtml1-phpkeyword">echo</span><span class="webhtml1-phpwhitespace"> </span><span class="webhtml1-phpstring">&quot;You did not put in a comment.&quot;</span><span class="webhtml1-phpsymbol">;
    }
}</span><span class="webhtml1-phpkeyword">else</span><span class="webhtml1-phpsymbol">{
    </span><span class="webhtml1-phpkeyword">if</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-phpfunction">strlen</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-specialphpvariableprefix">$comment</span><span class="webhtml1-phpsymbol">)&gt; </span><span class="webhtml1-phpnumber">0</span><span class="webhtml1-phpsymbol">){
        </span><span class="webhtml1-phpkeyword">echo</span><span class="webhtml1-phpwhitespace"> </span><span class="webhtml1-phpstring">&quot;you got a comment, but not a name;&quot;</span><span class="webhtml1-phpsymbol">;
    }
}
</span><span class="webhtml1-specialphpvariableprefix">$sql</span><span class="webhtml1-phpwhitespace"> = </span><span class="webhtml1-phpstring">&quot;SELECT *
FROM `entries` ORDER BY `ID` DESC
LIMIT 3&quot;</span><span class="webhtml1-phpsymbol">;
</span><span class="webhtml1-specialphpvariableprefix">$result</span><span class="webhtml1-phpwhitespace"> = </span><span class="webhtml1-phpfunction">mysql_query</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-specialphpvariableprefix">$sql</span><span class="webhtml1-phpsymbol">);
</span><span class="webhtml1-phpkeyword">while</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-specialphpvariableprefix">$row</span><span class="webhtml1-phpwhitespace"> = </span><span class="webhtml1-phpfunction">mysql_fetch_array</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-specialphpvariableprefix">$result</span><span class="webhtml1-phpsymbol">)){
    </span><span class="webhtml1-phpkeyword">echo</span><span class="webhtml1-phpwhitespace"> </span><span class="webhtml1-specialphpvariableprefix">$row</span><span class="webhtml1-phpsymbol">[</span><span class="webhtml1-phpstring">'name'</span><span class="webhtml1-phpsymbol">].</span><span class="webhtml1-phpstring">&quot; Said: &lt;blockquote&gt;&quot;</span><span class="webhtml1-phpsymbol">.</span><span class="webhtml1-specialphpvariableprefix">$row</span><span class="webhtml1-phpsymbol">[</span><span class="webhtml1-phpstring">'comment'</span><span class="webhtml1-phpsymbol">].</span><span class="webhtml1-phpstring">&quot;&lt;/blockquote&gt;&lt;br /&gt;&quot;</span><span class="webhtml1-phpsymbol">;
}
</span><span class="webhtml1-specialphpmarker">?&gt;
</span><span class="webhtml1-mltag">&lt;</span><span class="webhtml1-mltagname">form</span><span class="webhtml1-mlwhitespace"> </span><span class="webhtml1-mlkey">action</span><span class="webhtml1-mlsymbol">=&quot;?&quot; </span><span class="webhtml1-mlkey">method</span><span class="webhtml1-mlsymbol">=&quot;post&quot;</span><span class="webhtml1-mltag">&gt;
</span><span class="webhtml1-mltext">Name:
</span><span class="webhtml1-mltag">&lt;</span><span class="webhtml1-mltagname">input</span><span class="webhtml1-mlwhitespace"> </span><span class="webhtml1-mlkey">type</span><span class="webhtml1-mlsymbol">=&quot;text&quot; </span><span class="webhtml1-mlkey">name</span><span class="webhtml1-mlsymbol">=&quot;name&quot; </span><span class="webhtml1-mltag">/&gt;&lt;</span><span class="webhtml1-mltagname">br</span><span class="webhtml1-mlwhitespace"> </span><span class="webhtml1-mltag">/&gt;
</span><span class="webhtml1-mltext">Comment: </span><span class="webhtml1-mltag">&lt;</span><span class="webhtml1-mltagname">br</span><span class="webhtml1-mlwhitespace"> </span><span class="webhtml1-mltag">/&gt;
&lt;</span><span class="webhtml1-mltagname">textarea</span><span class="webhtml1-mlwhitespace"> </span><span class="webhtml1-mlkey">name</span><span class="webhtml1-mlsymbol">=&quot;comment&quot;</span><span class="webhtml1-mltag">&gt;&lt;/</span><span class="webhtml1-mltagname">textarea</span><span class="webhtml1-mltag">&gt;&lt;</span><span class="webhtml1-mltagname">br</span><span class="webhtml1-mlwhitespace"> </span><span class="webhtml1-mltag">/&gt;
&lt;</span><span class="webhtml1-mltagname">input</span><span class="webhtml1-mlwhitespace"> </span><span class="webhtml1-mlkey">type</span><span class="webhtml1-mlsymbol">=&quot;submit&quot; </span><span class="webhtml1-mlkey">value</span><span class="webhtml1-mlsymbol">=&quot;Submit&quot; </span><span class="webhtml1-mltag">/&gt;
&lt;/</span><span class="webhtml1-mltagname">form</span><span class="webhtml1-mltag">&gt;</span><span class="webhtml1-mlwhitespace">
</span></code></pre>
]]></content:encoded>
			<wfw:commentRss>http://kloplop321.com/php-tutorials/index.php/2010/02/15/mysql-and-phpmyadmin-introduction-with-php-07-a-basic-guestbook/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>PHP Tutorial: Databases in general</title>
		<link>http://kloplop321.com/php-tutorials/index.php/2010/02/14/php-tutorial-databases-in-general/</link>
		<comments>http://kloplop321.com/php-tutorials/index.php/2010/02/14/php-tutorial-databases-in-general/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 08:00:16 +0000</pubDate>
		<dc:creator>Kloplop321</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[PHPMyAdmin]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[create database]]></category>
		<category><![CDATA[create table]]></category>
		<category><![CDATA[insert]]></category>
		<category><![CDATA[sqlite]]></category>
		<category><![CDATA[update]]></category>

		<guid isPermaLink="false">http://kloplop321.com/php-tutorials/?p=174</guid>
		<description><![CDATA[Developers often use the handy features included with databases to create solutions in PHP for what ever needs to be satisfied. Databases have functions like quickly matching data to Identifications, searching large sums of data, holding user information and much more that developers can utilize. There are many ways to use a database, or in [...]]]></description>
			<content:encoded><![CDATA[<p>Developers often use the handy features included with databases to create solutions in PHP for what ever needs to be satisfied. Databases have functions like quickly matching data to Identifications, searching large sums of data, holding user information and much more that developers can utilize. There are many ways to use a database, or in this case, to interface with a database. Most databases use a rough standard of a <a title="SQL full description" href="http://en.wikipedia.org/wiki/SQL" target="_blank">Structured Querying Language</a>, which is like code that the SQL server or application interprets. <span id="more-174"></span>In PHP, developers have the following options to interface with a database:</p>
<ul>
<li><a href="http://www.php.net/manual/en/book.dbase.php">dBase</a></li>
<li><a href="http://www.php.net/manual/en/book.dbplus.php">DB++</a></li>
<li><a href="http://www.php.net/manual/en/book.fbsql.php">FrontBase</a></li>
<li><a href="http://www.php.net/manual/en/book.filepro.php">filePro</a></li>
<li><a href="http://www.php.net/manual/en/book.ibase.php">Firebird/InterBase</a></li>
<li><a href="http://www.php.net/manual/en/book.ifx.php">Informix</a></li>
<li><a href="http://www.php.net/manual/en/book.ibm-db2.php">IBM DB2</a></li>
<li><a href="http://www.php.net/manual/en/book.ingres.php">Ingres</a></li>
<li><a href="http://www.php.net/manual/en/book.maxdb.php">MaxDB</a></li>
<li><a href="http://www.php.net/manual/en/book.mongo.php">Mongo</a></li>
<li><a href="http://www.php.net/manual/en/book.msql.php">mSQL</a></li>
<li><a href="http://www.php.net/manual/en/book.mssql.php">Mssql</a></li>
<li><a href="http://www.php.net/manual/en/book.mysql.php">MySQL</a></li>
<li><a href="http://www.php.net/manual/en/book.mysqli.php">Mysqli</a></li>
<li><a href="http://www.php.net/manual/en/book.mysqlnd.php">Mysqlnd</a></li>
<li><a href="http://www.php.net/manual/en/book.oci8.php">OCI8</a></li>
<li><a href="http://www.php.net/manual/en/book.ovrimos.php">Ovrimos SQL</a></li>
<li><a href="http://www.php.net/manual/en/book.paradox.php">Paradox</a></li>
<li><a href="http://www.php.net/manual/en/book.pgsql.php">PostgreSQL</a></li>
<li><a href="http://www.php.net/manual/en/book.sqlite.php">SQLite</a></li>
<li><a href="http://www.php.net/manual/en/book.sqlite3.php">SQLite3</a></li>
<li><a href="http://www.php.net/manual/en/book.sybase.php">Sybase</a></li>
<li><a href="http://www.php.net/manual/en/book.tokyo-tyrant.php">tokyo_ tyrant</a></li>
</ul>
<p>Some of these methods use the same database type, such as MySQL and Mysqli. However I will only be focusing on the most common methods, which incude MySQL, SQLite, and OBCD.</p>
<p>Most PHP developers use MySQL due to its support, popularity, cross-platform, and universal capabilities. It is not proprietary like Microsoft Access Databases, and it has a really handy tool called PHPMyAdmin.</p>
<p>SQL looks like this</p>
<p style="padding-left: 30px;">INSERT INTO My_table<br />
(field1, field2, field3)<br />
VALUES<br />
(&#8216;test&#8217;, &#8216;N&#8217;, NULL);</p>
<p>In PHP, we can wrap this in double quotes like so</p>
<pre>$sql = "INSERT INTO My_table
 (field1, field2, field3)
 VALUES
 ('test', 'N', NULL);";</pre>
<p>and then execute it with what ever database method we choose.</p>
<blockquote><p>MySQL:<br />
mysql_query($sql);<br />
SQLite:<br />
sqlite_query($db,$sql);<br />
OBCD:<br />
odbc_exec($db, $sql);</p></blockquote>
<p>As I have only had personal experience with two of the above, I will not cover OBCD any more than the above.</p>
<p>Back to MySQL and SQLite:<br />
Both MySQL and SQLite require an initiation at the beginning of each script execution. In MySQL&#8217;s case an example would be:</p>
<blockquote>
<div>
<div><code> &lt;?php<br />
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');<br />
if (!$link) {<br />
die('Could not connect: ' . mysql_error());<br />
}<br />
echo 'Connected successfully';<br />
mysql_close($link);<br />
?&gt; </code></div>
</div>
</blockquote>
<div>The mysql_connect function is what initiates MySQL for use in future code execution. The $link variable in this example can be used in almost all mysql_* functions in the case of multiple connections (Which I do not recommend). If a developer wants to manually close the connection, they may do so by using mysql_close() which terminates the connection and frees the MySQL server&#8217;s resources.</div>
<div>For SQLite, we are using a local file instead of a server. Essentially, PHP, or rather the SQLite plugin for PHP handles the SQL execution and data manipulation. This is a great solution if a developer wants to make backups easily through more direct measures. Also, if a developer is in a situation like I am in with my school&#8217;s server, then this is a great solution. If you don&#8217;t care to understand my situation, skip to the next paragraph. My situation was where the Web Hoster (will remain un-named, for they do not deserve to be advertised) had it so there was no &#8220;localhost&#8221; mysql connection, but rather a single server dedicated for MySQL execution. Great idea in theory if you want to make use of idle hardware, but in reality it is horrid. My pages were stuck with a 2(rare) to 40 second (most common in the middle) delay because it had to wait to connect to the central server. This obviously would not do, so I tried to find a file-based solution without having to make my own with CSV and other hacked-up jobs. The result: instant execution, no noticeable delay.</div>
<div>SQLite, as aforementioned, uses a file as the database. SQLite has both its pros and cons.</div>
<div>Pros:</div>
<div>
<ul>
<li>Fast</li>
<li>Simple</li>
<li>Not heavy on server load</li>
<li>Easy to copy</li>
</ul>
</div>
<div>Cons:</div>
<div>
<ul>
<li>People from the &#8220;other side&#8221; can download it if you put it in a public folder</li>
<li>It can be erased without a trace</li>
<li>it isn&#8217;t as flexible as MySQL</li>
</ul>
</div>
<div>I prefer to MySQL because of PHPMyAdmin, but I can deal with SQLite thanks to this conversion code I came up with (Not bi-directional, only MySQL to SQLite)</div>
<blockquote>
<div>&lt;?php<br />
$link = mysql_connect(&#8216;localhost&#8217;, &#8216;USER&#8217;, &#8216;PASS&#8217;);<br />
mysql_selectdb(&#8220;DB_NAME&#8221;);<br />
$name = &#8220;TABLE_NAME&#8221;;<br />
$sql = &#8220;SELECT *<br />
FROM `$name` LIMIT 1&#8243;;<br />
$res = mysql_query($sql);<br />
$row = mysql_fetch_array($res);<br />
$cols = mysql_num_fields($res);<br />
$sql = &#8220;SELECT *<br />
FROM `$name`&#8221;;<br />
$res = mysql_query($sql);<br />
$rowsdone = 0;<br />
if ($db = sqlite_open(&#8216;SQLITE_FILE_LOCATION&#8217;, 0666, $sqliteerror)) {<br />
$res = mysql_query($sql);<br />
while($row = mysql_fetch_array($res)){<br />
$sqli = &#8220;INSERT INTO $name VALUES(&#8220;;<br />
for($x = 0; $x &lt; $cols; $x++){<br />
$sqli .= &#8220;&#8216;&#8221;.sqlite_escape_string($row[$x]).&#8221;&#8216;&#8221;;<br />
if($x != $cols -1){<br />
$sqli .= &#8221; , &#8220;;<br />
}<br />
}<br />
$sqli .= &#8220;);&#8221;;<br />
$result = sqlite_query($db,$sqli);<br />
if(sqlite_last_error($db) != 1){<br />
echo sqlite_error_string(sqlite_last_error($db)).&#8221;\n&#8221;;<br />
//echo strip_tags($sqli);<br />
echo &#8220;&lt;br&gt;\n &#8220;;<br />
}<br />
}<br />
} else {<br />
die ($sqliteerror);<br />
}<br />
?&gt;</div>
</blockquote>
<div>The above script is only for transferring rows not for adding the tables to SQLite.</div>
<div>As seen above, in order to &#8220;connect&#8221; or open the SQLite Database, we use the line:</div>
<blockquote>
<div>if ($db = sqlite_open(&#8216;SQLITE_FILE_LOCATION&#8217;, 0666, $sqliteerror)) {</div>
</blockquote>
<div>0666 being the permissions code (no reference to satanic anything).</div>
<div>One note is that in MySQL, a developer would use mysql_real_escape_string to prepare strings for data entry, however in SQLite, a developer would use sqlite_escape_string (not the missing &#8220;real_&#8221; as there is no function named that).</div>
<div>A developer can use MySQL SQL in SQLite with a few adaptations:</div>
<div>A developer may not:</div>
<div>
<ul>
<li>use ` in the SQL</li>
<li>use fieldnames that also are keywords like order, by, count, etc&#8230;</li>
</ul>
<p>(I doubt that my suggestion is full and complete)</p>
</div>
<div>My method is to make everything through PHPMyAdmin, export it without comments, and use the table creation section in SQLite.</div>
<div>SQLite functions and MySQL functions are nearly interchangeable with just a text replacement and SQL checking, so I will from now on only cover MySQL (with possible exceptions).</div>
<div>A developer can make a database in MySQL with &#8220;<code>CREATE  DATABASE  `DB_NAME_HERE` ;" and then in php select that database for future use through</code></div>
<blockquote>
<div>mysql_selectdb(&#8220;<code>DB_NAME_HERE</code>&#8220;);</div>
</blockquote>
<div>Next, if a developer so desire, he may create a table with SQL like the following</div>
<blockquote>
<div><code>CREATE  TABLE  `</code><code>DB_NAME_HERE</code><code>`.`tablename` (</code></p>
<div>`id` INT( 8  )  UNSIGNED NOT  NULL  AUTO_INCREMENT ,<br />
`description` TEXT NOT  NULL ,<br />
PRIMARY  KEY (  `id`  ) ,<br />
INDEX (  `id`  )</div>
</div>
<div>) ENGINE  =  MYISAM ;</div>
</blockquote>
<div>Now that this intangible developer has a table, he can put information in like so:</div>
<blockquote>
<div><code>INSERT  INTO  `</code><code>DB_NAME_HERE</code><code>`.`tablename` (</code></p>
<div>`id` ,<br />
`description`</div>
<p>)<br />
VALUES (</p>
<div>NULL ,  &#8216;Beans do not taste like fruit.&#8217;</div>
</div>
<div>);</div>
</blockquote>
<div>A developer can use NULL as a value when the field has a default value or has an auto_increment property (like above).</div>
<div>Because I have set the id to be a primary key and index, there can be no duplicate keys(or identifications) in this table. Any developer who tries to force it will get an error.</div>
<div>If a developer is having an error in his code, he may use</div>
<blockquote>
<div><code>echo </code><code>mysql_error</code><code>();</code></div>
</blockquote>
<div>to find out what is wrong. In SQLite&#8217;s case he would need to use</div>
<blockquote>
<div>echo sqlite_error_string(sqlite_last_error($db));</div>
</blockquote>
<div>to find out what is wrong. In SQLite it isn&#8217;t as descriptive, so it takes more effort to find out what the issue is.</div>
<div>Next, in order to get information, a developer can do</div>
<blockquote>
<div>$sql = &#8220;SELECT  * FROM `TABLE_NAME`&#8221;;</div>
<div>$result = mysql_query($sql);</div>
</blockquote>
<div>and there are various ways to get the information like</div>
<blockquote>
<div>while($row = mysql_fetch_array($result)){</div>
<div>while($row = mysql_fetch_assoc($result)){</div>
</blockquote>
<div>Either may be used, but I prefer array to assoc.</div>
<div>Next, the developer can get the information row by row by using the variable $row in this case</div>
<blockquote>
<div>while($row = mysql_fetch_array($result)){</div>
<div>print_r($row);</div>
<div>}</div>
</blockquote>
<div>The above code will print out the array that the mysql_fetch_array function returns for every row that is in the $result.</div>
<div>A Developer may also update a row by referring to an identification in the SQL as such</div>
<blockquote>
<div><code>UPDATE  `DB_NAME`.`tablename`  SET  `description`  =   'Beans do not taste  like fruit. Yet they are supposed to be magical...' WHERE  `tablename`.`id`  =1;</code></div>
</blockquote>
<div>MySQL can also be compounded in terms of having multiple inserts (not selects) and updates, but they must be separated by a &#8220;;&#8221; and usually a new line.</div>
<div></div>
<div>If a developer would like to know if his current php interpreter has database connection functionality, use phpinfo(); and go to the page in the browser and search for &#8220;sql&#8221;. In my case, I have &#8220;&#8211;with-mysql&#8221; and &#8220;&#8211;with-sqlite&#8221; in my &#8220;Configure Command&#8221; section near the top.</div>
<div></div>
<div>This is only an introduction to the core and most useful features of Databases using Sequential Querying Languages. Further reading can be done at <a href="http://www.mysql.com/" target="_blank">mysql.com</a> <a href="http://php.net/manual/en/book.mysql.php">php mysql</a> <a href="http://www.sqlite.org/">sqlite.org</a> and <a href="http://php.net/manual/en/book.sqlite.php">php sqlite</a>.</div>
]]></content:encoded>
			<wfw:commentRss>http://kloplop321.com/php-tutorials/index.php/2010/02/14/php-tutorial-databases-in-general/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MySQL and PHPMyAdmin Introduction with PHP 06</title>
		<link>http://kloplop321.com/php-tutorials/index.php/2010/02/10/mysql-and-phpmyadmin-introduction-with-php-06/</link>
		<comments>http://kloplop321.com/php-tutorials/index.php/2010/02/10/mysql-and-phpmyadmin-introduction-with-php-06/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 19:51:16 +0000</pubDate>
		<dc:creator>Kloplop321</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[PHPMyAdmin]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[import]]></category>

		<guid isPermaLink="false">http://kloplop321.com/php-tutorials/?p=171</guid>
		<description><![CDATA[Want to dump your database? This video goes over the export feature of PHPMyAdmin which allows you to create and save file dumps of your database. You can use these dumps to make a duplicate database or update a pre-existing database. Or simply to backup regularly in case of database failure. I also marginally go [...]]]></description>
			<content:encoded><![CDATA[<p>Want to dump your database? This video goes over the export feature of PHPMyAdmin which allows you to create and save file dumps of your database. You can use these dumps to make a duplicate database or update a pre-existing database. Or simply to backup regularly in case of database failure. I also marginally go over importing and how to import.</p>
<p><object  type="application/x-shockwave-flash" style="width:800px; height:490px;" data="http://www.youtube.com/v/_pc_a4fYaio&#038;hl=en_US&#038;fs=1&#038;color1=0x006699&#038;color2=0x54abd6"><param name="movie" value="http://www.youtube.com/v/_pc_a4fYaio&#038;hl=en_US&#038;fs=1&#038;color1=0x006699&#038;color2=0x54abd6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param></object></p>
]]></content:encoded>
			<wfw:commentRss>http://kloplop321.com/php-tutorials/index.php/2010/02/10/mysql-and-phpmyadmin-introduction-with-php-06/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL and PHPMyAdmin Introduction with PHP 05</title>
		<link>http://kloplop321.com/php-tutorials/index.php/2009/12/26/mysql-and-phpmyadmin-introduction-with-php-05/</link>
		<comments>http://kloplop321.com/php-tutorials/index.php/2009/12/26/mysql-and-phpmyadmin-introduction-with-php-05/#comments</comments>
		<pubDate>Sat, 26 Dec 2009 16:39:58 +0000</pubDate>
		<dc:creator>Kloplop321</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[PHPMyAdmin]]></category>
		<category><![CDATA[Select]]></category>
		<category><![CDATA[Deleting]]></category>

		<guid isPermaLink="false">http://kloplop321.com/php-tutorials/?p=158</guid>
		<description><![CDATA[In this tutorial I go over deleting rows, not only in PHPMyAdmin, but in PHP as well. Once rows are deleted, they are not coming back. On the side note, it is good to use something that is unique to every row when modifying them or deleting them. Otherwise you can delete anything that matches [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial I go over deleting rows, not only in PHPMyAdmin, but in PHP as well. Once rows are deleted, they are not coming back. On the side note, it is good to use something that is unique to every row when modifying them or deleting them. Otherwise you can delete anything that matches the name being &#8220;orange&#8221; and delete two rows. This is why I usually always have an ID field in my rows.<br />
<object type="application/x-shockwave-flash" style="width:800px; height:472px;" data="http://kloplop321.com/php-tutorials/images/counter.swf"><param name="movie" value="http://kloplop321.com/php-tutorials/images/counter.swf" /><param name="allowFullScreen" value="true" /><param name="scale" value="noscale" /><param name="FlashVars" value="youtube=cnQmDYk3Pjs&amp;tutid=5&amp;part=1&amp;goals=How to delete rows in PHPMyAdmin and in PHP directly with MySQL&amp;vidpath=./tuts/vids/phpmyadmin05.mp4" />This video tutorial goes over how to select rows from a database in PHPMyAdmin and then in PHP and then process the rows individually. Also this goes over ordering(ORDER) and limitation(LIMIT) in the SQL.<br />
            	You can find this tutorial video on <a href="http://www.youtube.com/watch?v=cnQmDYk3Pjs">youtube here</a>.</object><br />
Source used after the jump;<br />
<span id="more-158"></span></p>
<pre><code><span class="webhtml1-mltag">&lt;?</span><span class="webhtml1-phpkeyword">php
$</span><span class="webhtml1-phpvariable">link</span><span class="webhtml1-phpwhitespace"> = </span><span class="webhtml1-phpfunction">mysql_connect</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-phpstring">'localhost'</span><span class="webhtml1-phpsymbol">, </span><span class="webhtml1-phpstring">'phpuser'</span><span class="webhtml1-phpsymbol">, </span><span class="webhtml1-phpstring">'phppass'</span><span class="webhtml1-phpsymbol">);
</span><span class="webhtml1-phpkeyword">if</span><span class="webhtml1-phpwhitespace"> (!</span><span class="webhtml1-phpkeyword">$</span><span class="webhtml1-phpvariable">link</span><span class="webhtml1-phpsymbol">) {
    </span><span class="webhtml1-phpkeyword">die</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-phpstring">'Not connected : '</span><span class="webhtml1-phpwhitespace"> . </span><span class="webhtml1-phpfunction">mysql_error</span><span class="webhtml1-phpsymbol">());
}</span><span class="webhtml1-phpkeyword">else</span><span class="webhtml1-phpsymbol">{
    </span><span class="webhtml1-phpcomment">//echo &quot;I am connected. &quot;;
</span><span class="webhtml1-phpsymbol">}

</span><span class="webhtml1-phpcomment">// make foo the current db
</span><span class="webhtml1-phpkeyword">$</span><span class="webhtml1-phpvariable">db_selected</span><span class="webhtml1-phpwhitespace"> = </span><span class="webhtml1-phpfunction">mysql_select_db</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-phpstring">'test'</span><span class="webhtml1-phpsymbol">, </span><span class="webhtml1-phpkeyword">$</span><span class="webhtml1-phpvariable">link</span><span class="webhtml1-phpsymbol">);
</span><span class="webhtml1-phpkeyword">if</span><span class="webhtml1-phpwhitespace"> (!</span><span class="webhtml1-phpkeyword">$</span><span class="webhtml1-phpvariable">db_selected</span><span class="webhtml1-phpsymbol">) {
    </span><span class="webhtml1-phpkeyword">die</span><span class="webhtml1-phpwhitespace"> (</span><span class="webhtml1-phpstring">'Can</span><span class="webhtml1-phpstringspecial">\'</span><span class="webhtml1-phpstring">t use test : '</span><span class="webhtml1-phpwhitespace"> . </span><span class="webhtml1-phpfunction">mysql_error</span><span class="webhtml1-phpsymbol">());
}
</span><span class="webhtml1-phpkeyword">if</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-phpkeyword">isset</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-phpkeyword">$</span><span class="webhtml1-phpvariable">_REQUEST</span><span class="webhtml1-phpsymbol">[</span><span class="webhtml1-phpstring">'del'</span><span class="webhtml1-phpsymbol">])){
    </span><span class="webhtml1-phpcomment">//DELETE FROM `test`.`tableish` WHERE `tableish`.`ID` = 3
</span><span class="webhtml1-phpwhitespace">    </span><span class="webhtml1-phpkeyword">$</span><span class="webhtml1-phpvariable">id</span><span class="webhtml1-phpwhitespace"> = (</span><span class="webhtml1-phpkeyword">int</span><span class="webhtml1-phpsymbol">)</span><span class="webhtml1-phpkeyword">$</span><span class="webhtml1-phpvariable">_REQUEST</span><span class="webhtml1-phpsymbol">[</span><span class="webhtml1-phpstring">'del'</span><span class="webhtml1-phpsymbol">];
    </span><span class="webhtml1-phpkeyword">$</span><span class="webhtml1-phpvariable">sql</span><span class="webhtml1-phpwhitespace"> = </span><span class="webhtml1-phpstring">&quot;DELETE FROM `tableish` WHERE `ID` = </span><span class="webhtml1-phpstringspecial">$id</span><span class="webhtml1-phpstring">&quot;</span><span class="webhtml1-phpsymbol">;
    </span><span class="webhtml1-phpfunction">mysql_query</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-phpkeyword">$</span><span class="webhtml1-phpvariable">sql</span><span class="webhtml1-phpsymbol">);
}
</span><span class="webhtml1-phpkeyword">$</span><span class="webhtml1-phpvariable">sql</span><span class="webhtml1-phpwhitespace"> = </span><span class="webhtml1-phpstring">&quot;SELECT * FROM `tableish` ORDER BY `tableish`.`ID` ASC&quot;</span><span class="webhtml1-phpsymbol">;
</span><span class="webhtml1-phpkeyword">$</span><span class="webhtml1-phpvariable">result</span><span class="webhtml1-phpwhitespace"> = </span><span class="webhtml1-phpfunction">mysql_query</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-phpkeyword">$</span><span class="webhtml1-phpvariable">sql</span><span class="webhtml1-phpsymbol">, </span><span class="webhtml1-phpkeyword">$</span><span class="webhtml1-phpvariable">link</span><span class="webhtml1-phpsymbol">);
</span><span class="webhtml1-phpkeyword">if</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-phpfunction">mysql_num_rows</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-phpkeyword">$</span><span class="webhtml1-phpvariable">result</span><span class="webhtml1-phpsymbol">) &gt; </span><span class="webhtml1-phpnumber">0</span><span class="webhtml1-phpsymbol">){
    </span><span class="webhtml1-phpkeyword">while</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-phpkeyword">$</span><span class="webhtml1-phpvariable">row</span><span class="webhtml1-phpwhitespace"> = </span><span class="webhtml1-phpfunction">mysql_fetch_array</span><span class="webhtml1-phpsymbol">(</span><span class="webhtml1-phpkeyword">$</span><span class="webhtml1-phpvariable">result</span><span class="webhtml1-phpsymbol">)){
        </span><span class="webhtml1-phpkeyword">echo</span><span class="webhtml1-phpwhitespace"> </span><span class="webhtml1-phpkeyword">$</span><span class="webhtml1-phpvariable">row</span><span class="webhtml1-phpsymbol">[</span><span class="webhtml1-phpstring">'name'</span><span class="webhtml1-phpsymbol">].</span><span class="webhtml1-phpstring">&quot;&lt;a href=</span><span class="webhtml1-phpstringspecial">\&quot;</span><span class="webhtml1-phpstring">?del=&quot;</span><span class="webhtml1-phpsymbol">.</span><span class="webhtml1-phpkeyword">$</span><span class="webhtml1-phpvariable">row</span><span class="webhtml1-phpsymbol">[</span><span class="webhtml1-phpstring">'ID'</span><span class="webhtml1-phpsymbol">].</span><span class="webhtml1-phpstring">&quot;</span><span class="webhtml1-phpstringspecial">\&quot;</span><span class="webhtml1-phpstring">&gt;Delete this row&lt;/a&gt;&lt;br /&gt;</span><span class="webhtml1-phpstringspecial">\n</span><span class="webhtml1-phpstring">&quot;</span><span class="webhtml1-phpsymbol">;
    }
}

</span><span class="webhtml1-mltag">?&gt;
</span></code></pre>
]]></content:encoded>
			<wfw:commentRss>http://kloplop321.com/php-tutorials/index.php/2009/12/26/mysql-and-phpmyadmin-introduction-with-php-05/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

