<?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>v-nessa.net &#187; mysql</title>
	<atom:link href="http://www.v-nessa.net/tag/mysql/feed" rel="self" type="application/rss+xml" />
	<link>http://www.v-nessa.net</link>
	<description>pink is the new black</description>
	<lastBuildDate>Thu, 31 Mar 2011 21:13:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Importing CSV Into MySQL</title>
		<link>http://www.v-nessa.net/2007/12/08/importing-csv-into-mysql</link>
		<comments>http://www.v-nessa.net/2007/12/08/importing-csv-into-mysql#comments</comments>
		<pubDate>Sat, 08 Dec 2007 21:53:17 +0000</pubDate>
		<dc:creator>Nessa</dc:creator>
				<category><![CDATA[uncategorized]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.v-nessa.net/2007/12/08/importing-csv-into-mysql</guid>
		<description><![CDATA[The newer versions of phpMyAdmin for some reason no longer include the option to import CSV files. If you are trying to import an Excel or other delimited file, first make sure that it&#8217;s in CSV format (with Excel you can export it as CSV). Then log into phpMyAdmin or your MySQL prompt and run [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.v-nessa.net%2F2007%2F12%2F08%2Fimporting-csv-into-mysql"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.v-nessa.net%2F2007%2F12%2F08%2Fimporting-csv-into-mysql&amp;source=nessa421&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>The newer versions of phpMyAdmin for some reason no longer include the option to import CSV files.  If you are trying to import an Excel or other delimited file, first make sure that it&#8217;s in CSV format (with Excel you can export it as CSV).  Then log into phpMyAdmin or your MySQL prompt and run this command:</p>
<blockquote><p><font color="#ff66cc"><span class="content">load data local infile &#8216;<strong>/path/to/file.csv</strong>&#8216; into table <strong>yourtablename</strong><br />
fields terminated by &#8216;,&#8217;<br />
enclosed by &#8216;&#8221;&#8216;<br />
lines terminated by &#8216;\n&#8217;;</span></font></p></blockquote>
<p>With phpMyAdmin this is done within the &#8216;SQL&#8217; section, indicated by the &#8216;SQL&#8217; tab.</p>
<p><map name='google_ad_map_129_7fa65e237551a74a'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/129?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_129_7fa65e237551a74a' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=129&amp;url= http%3A%2F%2Fwww.v-nessa.net%2F2007%2F12%2F08%2Fimporting-csv-into-mysql' /></p><img src="http://www.v-nessa.net/?ak_action=api_record_view&id=129&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.v-nessa.net/2007/12/08/importing-csv-into-mysql/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Common PHP Errors</title>
		<link>http://www.v-nessa.net/2007/12/07/common-php-errors</link>
		<comments>http://www.v-nessa.net/2007/12/07/common-php-errors#comments</comments>
		<pubDate>Sat, 08 Dec 2007 03:44:14 +0000</pubDate>
		<dc:creator>Nessa</dc:creator>
				<category><![CDATA[uncategorized]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[troubleshooting]]></category>

		<guid isPermaLink="false">http://www.v-nessa.net/2007/12/07/common-php-errors</guid>
		<description><![CDATA[I&#8217;m going back to the basics here, you know, when you wrote your first PHP script and saw an ugly-ass error message pop up on your screen? Error messages are the best tool a programmer has. Set up Error Reporting Most PHP errors are straight forward, but there are times where you don&#8217;t see any [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.v-nessa.net%2F2007%2F12%2F07%2Fcommon-php-errors"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.v-nessa.net%2F2007%2F12%2F07%2Fcommon-php-errors&amp;source=nessa421&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I&#8217;m going back to the basics here, you know, when you wrote your first PHP script and saw an ugly-ass error message pop up on your screen?  Error messages are the best tool a programmer has.</p>
<p><strong>Set up Error Reporting</strong></p>
<p>Most PHP errors are straight forward, but there are times where you don&#8217;t see any which makes it very difficult to tell what the problem is.</p>
<p>The first step of PHP troubleshooting is to turn error reporting on. For security reasons you&#8217;ll want error reporting off by default, but if something goes wrong you&#8217;ll need the information for debugging. You can usually enable error reporting by adding this line to the problem script:</p>
<p><font color="#ff66cc">&lt;?php error_reporting(E_ALL) ?&gt;</font></p>
<p>Or you can add these lines to the root .htaccess:</p>
<p><font color="#ff66cc">php_flag display_errors on<br />
php_value error_reporting 6143</font></p>
<p>This will usually display an error useful for troubleshooting, that is, if the software and your server configuration allows it.</p>
<p><strong>Parse Errors</strong></p>
<blockquote><p>Parse error: parse error, unexpected T_STRING in&#8230;&#8230;</p></blockquote>
<p>This is a syntax error. Perhaps you forgot a semi-colon at the end of a line, or you forgot a double quote (&#8220;) or an end bracket (}) after you started one. For quote and semicolon issues, the problem is usually the line above the one reported in the error.  For brackets, it may be at the end of the script.</p>
<blockquote><p>Parse error: syntax error, unexpected $end in</p></blockquote>
<p>You&#8217;re most likely missing a <strong>}</strong> somewhere.  Make sure that each <strong>{</strong> you have is also closed with a <strong>}</strong>.</p>
<blockquote><p> Parse error: syntax error, unexpected T_STRING, expecting &#8216;,&#8217; or &#8216;;&#8217; in..</p></blockquote>
<p>There may be double quotes within double quotes. They either need to be escaped or brought to single quotes.   It&#8217;s also possible that a new PHP statement was started before the previous was finished.</p>
<p><strong>Header Errors</strong></p>
<blockquote><p>Warning: Cannot add header information &#8211; headers already sent by (output started at  /home/vnessa5/www/errors.php:9) in&#8230;.</p></blockquote>
<blockquote><p>Warning: Cannot send session cache limiter &#8211; headers already sent in somefile.php on line 222</p></blockquote>
<p>Naturally, HTML will parse before PHP. The script is trying to send header information after you&#8217;ve already sent output to the browser. HTTP headers are required to be sent before any output from your script, which means that a header function must be placed before any html or even a white space. There are two solutions for this. Either (1) Set the header tags the top of the document, or (2) insert a header redirect by adding this to the very top of the page to force the output buffer:</p>
<p><font color="#ff66cc">&lt;?php ob_start();</font></p>
<p>Then this at the very end of the page (not usually required)</p>
<p><font color="#ff66cc">ob_end_flush(); ?&gt;</font></p>
<p><strong>mySQL Result Source Errors</strong></p>
<blockquote><p>Warning: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in&#8230;</p></blockquote>
<p>You need to take a look at the $result variable used to define the loop. More than likely there is a syntax error on the reported line before the $result field, or the value of $result does not exist.</p>
<blockquote><p><strong> </strong>Supplied argument is not a valid stream resource&#8230;</p></blockquote>
<p>This is usually caused when your code is looking for a table or other resource in the database that does not exist.</p>
<blockquote></blockquote>
<p><strong>Sessions are not being created or maintained</strong></p>
<p>This can apply to any of the scenarios below:</p>
<p>(1) The program isn&#8217;t remembering your login<br />
(2) Your shopping cart won&#8217;t hold items<br />
(3) Your php script is redirecting like crazy<br />
(4) &#8220;Call undefined function session_start&#8221; error<br />
(5) PHP isn&#8217;t processing pages called by something like <em>index.php?page=home&amp;id=7</em></p>
<p>Your site is most likely dependent on register_globals. You can enable them by putting this line in your .htaccess (or just enabling in your php.ini if you have access):</p>
<blockquote><p>php_flag register_globals On</p></blockquote>
<p><strong>Stream Errors</strong></p>
<blockquote><p>Warning: failed to open stream&#8230;</p></blockquote>
<blockquote><p>Warning: main(/index.php): failed to open stream: No such file or directory in&#8230;</p></blockquote>
<p>This is usually because either the specified file is missing, or a file declared in a require() or include() function is missing. The easiest way to fix this is by re-installing the PHP program from a freshly-uploaded copy, or restoring the original config.php and just changing the db information. The include path may also be incorrect, but either way your script is looking for a file that isn&#8217;t there, or it is looking in the wrong place.</p>
<blockquote><p>Warning: fopen(&#8230;): failed to open stream: Permission denied in&#8230;</p></blockquote>
<p>This is a permissions and/or ownership issue. Try first setting the permissions to 777 just to see if the script will run. If so, you should narrow down the permissions to 775. If not, set the user/group to user:nobody.</p>
<blockquote><p>Warning: &lt;&#8230;&gt; is not a valid stream resource&#8230;</p></blockquote>
<blockquote><p>Warning: fread(): supplied argument is not a valid stream resource in&#8230;</p></blockquote>
<p>This is an error seen when trying to use functions like fopen(), fread(), feof(), etc. and are usually caused by an invalid or unavailable resource that is being called in the line specified. For instance, if the fread() function is returning this error, it could be that the file it is trying to access does not have the correct permissions or does not exist.</p>
<blockquote><p>Warning: Failed opening&#8230;.</p></blockquote>
<blockquote><p>Warning: Failed opening &#8216;&#8230;&#8217; for inclusion (include_path=&#8217;.:/usr/local/lib/php&#8217;) in Unknown on line 0</p></blockquote>
<p>Make the sure that the file mentioned (and its holding directorie) has read + execute permissions, and that the path to the file is correct. If not, you&#8217;ll need to add the path into the PHP code: (or .htaccess)</p>
<p><font color="#ff66cc">include(&#8220;/path/to/files&#8221;);</font><br />
<strong>Blank PHP Pages</strong></p>
<p>You go to a .php page, but it&#8217;s blank.</p>
<p>The scope of what can cause blank pages is very broad, but there are a few things to look at:</p>
<p>-Is error reporting turned off anywhere in the script or in the .htaccess? If so, turn it on to see what is happening (php_flag display_errors on), or add the lines at the top of this page into the script.</p>
<p>-Is the PHP script even generating any output (usually you can tell my finding the print function?</p>
<p>-Check the database connection, i.e, username, dbname, user added to db, etc.</p>
<p>-Try using the full &lt;?PHP ?&gt; tags, rather than the shorter versions &lt;? ?&gt;</p>
<p>Also, if the software is prebundled (like phpBB or Gallery), then the index or one of the include pages could be corrupted. Usually you can just replace the problem page with a working version from another installation.<br />
<strong>Max Execution Time Error</strong></p>
<p>You receive some variant of a &#8220;Max_execution_time&#8221; error when loading a page.</p>
<p>This is caused when a PHP script takes longer to execute than the server allows, but can be adjusted by adding a PHP directive to your .htaccess: (in seconds, 0 = unlimited) or modifying the value in php.ini.</p>
<blockquote><p>php_value max_execution_time 0</p></blockquote>
<p>Open_basedir Errors</p>
<blockquote><p>Warning: Unknown(): open_basedir restriction in effect.</p></blockquote>
<p>This is a protective feature of Apache that restricts PHP from accessing files/folders outside the user&#8217;s home directory. Most of the time this is due to an incorrect include path in one or more of the config files (which are usually mentioned). Look for something like this:</p>
<blockquote><p>/includes/somefile.php<br />
/admin/files/anotherfile.php</p></blockquote>
<p>The heading / tells the filesystem that these folders are on the server root, and thus prevents PHP from accessing them. You can usually fix this by changing the path to these files to be absolute to their location:</p>
<p><font color="#ff66cc">/home/username/public_html/includes/somefile.php</font></p>
<p>or</p>
<p><font color="#ff66cc">./includes/somefile.php</font></p>
<p><!--adsense#img_banner--></p>
<p><map name='google_ad_map_126_7fa65e237551a74a'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/126?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_126_7fa65e237551a74a' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=126&amp;url= http%3A%2F%2Fwww.v-nessa.net%2F2007%2F12%2F07%2Fcommon-php-errors' /></p><img src="http://www.v-nessa.net/?ak_action=api_record_view&id=126&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.v-nessa.net/2007/12/07/common-php-errors/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Convert Database to UTF-8</title>
		<link>http://www.v-nessa.net/2007/12/06/convert-database-to-utf-8</link>
		<comments>http://www.v-nessa.net/2007/12/06/convert-database-to-utf-8#comments</comments>
		<pubDate>Fri, 07 Dec 2007 03:25:18 +0000</pubDate>
		<dc:creator>Nessa</dc:creator>
				<category><![CDATA[uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">http://www.v-nessa.net/2007/12/06/convert-database-to-utf-8</guid>
		<description><![CDATA[We seriously see a ton of customers coming in with the type of databases that are a nightmare to move over. When you&#8217;re dealing with special characters in a database, you have to make sure that the charset and collation are dumped *with* the database, so that when you move it to another server the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.v-nessa.net%2F2007%2F12%2F06%2Fconvert-database-to-utf-8"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.v-nessa.net%2F2007%2F12%2F06%2Fconvert-database-to-utf-8&amp;source=nessa421&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>We seriously see a ton of customers coming in with the type of databases that are a nightmare to move over.  When you&#8217;re dealing with special characters in a database, you have to make sure that the charset and collation are dumped *with* the database, so that when you move it to another server the tables and data create properly.  The biggest annoyance so far is converting tables back to UTF-8, as when this is done through the MySQL shell or phpmyadmin is had to be done table-by-table.  So, I wrote this simple PHP script to do it all at once:</p>
<p><code><font color="#ff66cc">  &lt;?php<br />
// Database info</font></code></p>
<p><code><font color="#ff66cc">     $dbhost      = 'localhost';<br />
$dbuser      = 'db_user';<br />
$dbpass      = 'password';<br />
$dbname    = 'db_name';<br />
</font></code></p>
<p><code><font color="#ff66cc">   //---------------</font></code></p>
<p><code><font color="#ff66cc">    header('Content-type: text/plain');</font></code></p>
<p><code><font color="#ff66cc">$dbconn = mysql_connect($dbhost, $dbuser, $dbpass) or die( mysql_error() );<br />
$db = mysql_select_db($dbname) or die( mysql_error() );</font></code><br />
<code><br />
<font color="#ff66cc">$sql = 'SHOW TABLES';<br />
$result = mysql_query($sql) or die( mysql_error() );</font></code></p>
<p><code><font color="#ff66cc">while ( $row = mysql_fetch_row($result) )<br />
{<br />
$table = mysql_real_escape_string($row[0]);<br />
$sql = "ALTER TABLE $table DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci";<br />
mysql_query($sql) or die( mysql_error() );<br />
print "$table changed to UTF-8.\n";<br />
}</font></code><br />
<code><br />
<font color="#ff66cc">mysql_close($dbconn);<br />
?&gt;</font></code></p>
<p>If course, you can adjust the ALTER TABLE statement to any character set and  collation that you need.</p>
<p><map name='google_ad_map_128_7fa65e237551a74a'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/128?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_128_7fa65e237551a74a' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=128&amp;url= http%3A%2F%2Fwww.v-nessa.net%2F2007%2F12%2F06%2Fconvert-database-to-utf-8' /></p><img src="http://www.v-nessa.net/?ak_action=api_record_view&id=128&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.v-nessa.net/2007/12/06/convert-database-to-utf-8/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>How to Upgrade to a Non-Existent MySQL Version</title>
		<link>http://www.v-nessa.net/2007/11/28/how-to-upgrade-to-a-non-existent-mysql-version</link>
		<comments>http://www.v-nessa.net/2007/11/28/how-to-upgrade-to-a-non-existent-mysql-version#comments</comments>
		<pubDate>Thu, 29 Nov 2007 03:22:05 +0000</pubDate>
		<dc:creator>Nessa</dc:creator>
				<category><![CDATA[annoyances]]></category>
		<category><![CDATA[cpanel]]></category>
		<category><![CDATA[humor]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.v-nessa.net/2007/11/28/how-to-upgrade-to-a-non-existent-mysql-version/</guid>
		<description><![CDATA[Working in webhosting for a while now I&#8217;ve had some people ask for really weird shit, and I&#8217;ve dealt with a lot of people who try to sound a lot smarter than they actually are (I&#8217;m one of them). The latest of the bunch is a guy who asked for MySQL 7.0 claiming that he&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.v-nessa.net%2F2007%2F11%2F28%2Fhow-to-upgrade-to-a-non-existent-mysql-version"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.v-nessa.net%2F2007%2F11%2F28%2Fhow-to-upgrade-to-a-non-existent-mysql-version&amp;source=nessa421&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Working in webhosting for a while now I&#8217;ve had some people ask for really weird shit, and I&#8217;ve dealt with a lot of people who try to sound a lot smarter than they actually are (I&#8217;m one of them).  The latest of the bunch is a guy who asked for MySQL 7.0 claiming that he&#8217;s a MySQL programmer and that he specially programmed his database to work with MySQL 7.0.  He really didn&#8217;t take it to heart very well when I told him that there is no MySQL 7.0 and the most he can hope for is 6.0x alpha (FYI for future readers a year from now, read the damn date on this post).  Besides the point, the guy apparently felt like I was talking down to him so he went out of his way to mention that because he has a bachelors degree in computer science and that he&#8217;s an avid Microsoft Word user, he definately knows more than I do when it comes to doing my job.  So, I gave in and agreed to upgrade him to MySQL 7.0.</p>
<p>The trick of the trade here is that you can essentially install any version of MySQL that you want to, whether it exists or not!  It&#8217;s a long-standing suck point in cPanel that the MySQL version in user cPanels are read from a static file within the datastore directory:</p>
<blockquote><p>/home/username/.cpanel/datastore/_usr_sbin_mysqld_&#8211;version</p></blockquote>
<p>Within that file is the output of the &#8216;<strong>/usr/sbin/mysqld &#8211;version</strong>&#8216; command, which cPanel reads and outputs to each user&#8217;s cPanel.  You can easily edit this file in one user&#8217;s account to make it read whatever MySQL version you want:<br />
<a href="http://v-nessa.net"><img src="http://v-nessa.net/images/mysql_10.jpg" align="left" height="109" hspace="5" vspace="5" width="288" /></a><br />
Needless to say, after I &#8216;upgraded&#8217; his version to 7.0, he claims his scripts started working!</p>
<p><map name='google_ad_map_113_7fa65e237551a74a'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/113?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_113_7fa65e237551a74a' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=113&amp;url= http%3A%2F%2Fwww.v-nessa.net%2F2007%2F11%2F28%2Fhow-to-upgrade-to-a-non-existent-mysql-version' /></p><img src="http://www.v-nessa.net/?ak_action=api_record_view&id=113&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.v-nessa.net/2007/11/28/how-to-upgrade-to-a-non-existent-mysql-version/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Installing Sphinx for MySQL 5.1</title>
		<link>http://www.v-nessa.net/2007/07/21/installing-sphinx-for-mysql-51</link>
		<comments>http://www.v-nessa.net/2007/07/21/installing-sphinx-for-mysql-51#comments</comments>
		<pubDate>Sat, 21 Jul 2007 19:48:45 +0000</pubDate>
		<dc:creator>Nessa</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[uncategorized]]></category>

		<guid isPermaLink="false">http://www.v-nessa.net/2007/07/21/installing-sphinx-for-mysql-51/</guid>
		<description><![CDATA[This is probably one of the two things that drove me crazy over the last two weeks. The first was trying to get cPanel to stop being such a MySQL nazi, the second was getting Sphinx installed into MySQL 5.1 for one of the clients. I&#8217;ve installed it with 5.0 on Ubuntu before, but 5.1 [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.v-nessa.net%2F2007%2F07%2F21%2Finstalling-sphinx-for-mysql-51"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.v-nessa.net%2F2007%2F07%2F21%2Finstalling-sphinx-for-mysql-51&amp;source=nessa421&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>This is probably one of the two things that drove me crazy over the last two weeks.  The first was trying to get <a href="http://cpanel.net" title="cPanel" target="_blank">cPanel</a> to stop being such a MySQL nazi, the second was getting <a href="http://sphinxsearch.com/" title="Sphinx" target="_blank">Sphinx</a> installed into MySQL 5.1 for one of the clients.  I&#8217;ve installed it with 5.0 on Ubuntu before, but 5.1 with cPanel can be pretty torturous.  After talking to the developer who was able to fill in the blanks, I&#8217;ve decided to write my own documentation on how to install Sphinx as a dynamic MySQL plugin for an existing MySQL 5.1 installation.</p>
<p><strong>Before we start..</strong>.</p>
<p>You need MySQL 5.1 installed to use the plugin feature. If you&#8217;re running on cPanel or other version-dependent software it&#8217;s a really <em>really</em> bad idea to install MySQL from source, so you&#8217;ll probably want to read <a href="http://www.v-nessa.net/2007/07/20/upgrading-to-mysql-5120-on-cpanel/" title="Upgrading to MySQL 5.1" target="_blank">this</a> as a guide to upgrading via RPM.  Also, this walkthrough is specific to MySQL 5.1.20 (beta), since that&#8217;s the latest release out at the time of this writing.</p>
<p>You also need to have root access, and a decent knowledge of Linux and MySQL.</p>
<p><strong><br />
Download the Sphinx binaries and MySQL 5.1.20 patch:</strong><br />
<code><font color="#ff66cc"><br />
wget <a href="http://sphinxsearch.com/downloads/sphinx-0.9.7.tar.gz" class="external free" title="http://sphinxsearch.com/downloads/sphinx-0.9.7.tar.gz" rel="nofollow">http://sphinxsearch.com/downloads/sphinx-0.9.7.tar.gz</a><br />
tar -xvzf sphinx-0.9.7.tar.gz<br />
cd sphinx-0.9.7/mysqlse/<br />
wget <a href="http://v-nessa.net/imh_files/sphinxse097-mysql5120.patch" class="external free" title="http://v-nessa.net/imh_files/sphinxse097-mysql5120.patch" rel="nofollow">http://v-nessa.net/imh_files/sphinxse097-mysql5120.patch</a></font></code><font color="#ff66cc"><br />
<code><br />
patch -p1 &lt; sphinxse097-mysql5120.patch</code></font></p>
<p>I should point out that <a href="http://shodan.ru/" target="_blank">Andrew Aksyonoff</a> (the developer) provided that patch to make Sphinx compatible with MySQL 5.1.20, but you&#8217;d probably have to check back on his site for version ugprades and such, esp. for newer versions of MySQL.</p>
<p>Now download the MySQL 5.1 sources &#8212; these are only going to be used to compile the Sphinx module:<br />
<code><font color="#ff66cc"><br />
cd /usr/src<br />
wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.20-beta.tar.gz/from/http://mysql.he.net/<br />
tar -xvzf mysql-5.1.20-beta.tar.gz<br />
cd mysql-5.1.20-beta<br />
cp -Rf /usr/src/sphinx-0.9.7/mysqlse/ storage/sphinx<br />
</font></code></p>
<p>Compile the Sphinx module against the MySQL 5.1 sources, but don&#8217;t install:<br />
<code><font color="#ff66cc"><br />
sh BUILD/autorun.sh<br />
./configure<br />
make</font></code></p>
<p>If you look in <strong>storage/sphinx/.libs</strong> you&#8217;ll see the loadable .so files that can plug in to MySQL easily.  I suggest you copy them into a more permanent location:<br />
<code><font color="#ff66cc"><br />
mkdir /var/lib/mysql/plugins<br />
cp  storage/sphinx/.libs/ha_sphinx.* /var/lib/mysql/plugins</font></code></p>
<p>Now add this line to <strong>/etc/my.cnf</strong> and restart mysql:<br />
<code><font color="#ff66cc"><br />
plugin_dir=/var/lib/mysql/plugins</font></code></p>
<p>To install, log into the MySQL root and issue the &#8216;INSTALL PLUGIN&#8217; command:<br />
<font color="#ff66cc"><br />
<code>mysql -u root<br />
mysql&gt; INSTALL PLUGIN sphinx SONAME 'ha_sphinx.so';<br />
</code></font></p>
<p>To verify its installation, just run the &#8216;SHOW ENGINES&#8217; command:</p>
<p><code><font color="#ff66cc">mysql&gt; show engines;<br />
| CSV        | YES     | CSV storage engine<br />
.....<br />
| SPHINX     | YES     | Sphinx storage engine 0.9.7</font></code></p>
<p><code></code><br />
If you need further info, check out the <a href="http://sphinxsearch.com/doc.html" title="Sphinx Documentation" target="_blank">doc-u-men-ta-tion</a>.</p>
<p><!--adsense--></p>
<p><map name='google_ad_map_84_7fa65e237551a74a'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/84?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_84_7fa65e237551a74a' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=84&amp;url= http%3A%2F%2Fwww.v-nessa.net%2F2007%2F07%2F21%2Finstalling-sphinx-for-mysql-51' /></p><img src="http://www.v-nessa.net/?ak_action=api_record_view&id=84&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.v-nessa.net/2007/07/21/installing-sphinx-for-mysql-51/feed</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Upgrading to MySQL 5.1.x on cPanel</title>
		<link>http://www.v-nessa.net/2007/07/20/upgrading-to-mysql-5120-on-cpanel</link>
		<comments>http://www.v-nessa.net/2007/07/20/upgrading-to-mysql-5120-on-cpanel#comments</comments>
		<pubDate>Sat, 21 Jul 2007 00:12:47 +0000</pubDate>
		<dc:creator>Nessa</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://www.v-nessa.net/2007/07/22/upgrading-to-mysql-5120-on-cpanel/</guid>
		<description><![CDATA[If you have server that run on cPanel, you&#8217;ll probably know how big of a Nazi it is in regards to the MySQL versions it can run. We just got this new line of servers at work and one of them I was pretty heartset on installing MySQL 5.1, mainly because of its loadable plugin [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.v-nessa.net%2F2007%2F07%2F20%2Fupgrading-to-mysql-5120-on-cpanel"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.v-nessa.net%2F2007%2F07%2F20%2Fupgrading-to-mysql-5120-on-cpanel&amp;source=nessa421&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>If you have server that run on cPanel, you&#8217;ll probably know how big of a Nazi it is in regards to the MySQL versions it can run.  We just got this new line of servers at work and one of them I was pretty heartset on installing MySQL 5.1, mainly because of its loadable plugin features where you can install a plugin or module without having to recompile the whole damn thing.  Upgrading to 5.1 is easy, you just have to follow the right steps.</p>
<p>First, I would recommend upgrading to cPanel 11 or EDGE, which should have support for compiling Apache with non-supported versions of MySQL.  On this server, I&#8217;m currently running 11 on the bleeding edge build.  Also, it&#8217;s a splendid idea to dump all your databases before upgrading.<br />
Note that these instructions mention MySQL 5.1.20-beta because that&#8217;s the latest release available at the time of my writing&#8230;.but you can essentially follow this guide for any version of MySQL!</p>
<p>1. Copy the MySQL libraries from the server into a temporary location:<br />
<font color="#ff66cc"><code><br />
mkdir /root/sqllibs<br />
cp /usr/lib/libmysqlclient.* /root/sqllibs</code></font></p>
<p>2. Find any installed MySQL packages:<br />
<font color="#ff66cc"><br />
<code>rpm -qa | grep -i mysql-</code></font></p>
<p>This should present a list of installed rpm&#8217;s&#8230;remove them with<strong> rpm -e</strong> ,but note that some may need to be removed before others.  Some people also would remove the <strong>/var/lib/mysql </strong>directory, but you can leave that there.</p>
<p>3.  Download and install the MySQL 5.1.x packages:</p>
<p>Hop on over to <a href="http://dev.mysql.com/downloads/mysql/5.1.html#linux-x86-32bit-rpms" title="MySQL RPMs" target="_blank">http://dev.mysql.com/downloads/mysql/5.1.html#linux-x86-32bit-rpms</a> and download the 5.1 RPM&#8217;s and install them:<br />
<font color="#ff66cc"><br />
<code>rpm -i MySQL-client-5.1.20-0.glibc23.i386.rpm<br />
rpm -i MySQL-devel-5.1.20-0.glibc23.i386.rpm<br />
rpm -i MySQL-embedded-5.1.20-0.glibc23.i386.rpm<br />
rpm -i MySQL-test-5.1.20-0.glibc23.i386.rpm<br />
rpm -i MySQL-server-5.1.20-0.glibc23.i386.rpm</code></font></p>
<p>4. Prepare cPanel</p>
<p>You&#8217;ll want to make sure that cPanel&#8217;s updates don&#8217;t reset the MySQL version, so you need to run the following commands to force cPanel to skip MySQL updates:<br />
<font color="#ff66cc"><br />
<code>touch /etc/mysqldisable<br />
touch /etc/mysqlupdisable</code></font></p>
<p>Now edit <strong>/var/cpanel/cpanel.config </strong>and change the MySQL version to<strong> 5.1</strong></p>
<p>Create the symlink:<br />
<font color="#ff66cc"><br />
<code>ln -s /var/lib/mysql/mysql.sock /tmp</code></font></p>
<p>Also, verify that the MySQL version is correct by running <strong>mysql -V </strong></p>
<blockquote><p><font color="#ff66cc">root@vps [~]# mysql -V<br />
mysql  Ver 14.13 Distrib 5.1.20-beta, for pc-linux-gnu (i686) using readline 5.0</font></p></blockquote>
<p>5. Set up MySQL</p>
<p>MySQL should have already been started at this point, so you can attempt to log in as root using <strong>mysql -u root .  </strong>If you are able to log in on the first try, great.  If not, you&#8217;ll need to reset the MySQL password:<br />
<font color="#ff66cc"><br />
<code>pico /etc/my.cnf</code></font></p>
<p>Add this line, and restart MySQL<br />
<font color="#ff66cc"><br />
<code><strong>skip-grant-tables</strong></code></font><br />
<font color="#ff66cc"><br />
<code>service mysql restart</code></font></p>
<p>Now log into MySQL root and set the password:</p>
<p><code><font color="#ff66cc"><br />
mysql -u root<br />
mysql&gt; FLUSH PRIVILEGES;<br />
mysql&gt; GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;<br />
mysql&gt; FLUSH PRIVILEGES;<br />
mysql&gt; exit;</font></code></p>
<p><code><font color="#ff66cc">service mysql restart</font></code></p>
<p>When you&#8217;re done, remove the  <strong>skip-grant-tables</strong> line from /etc/my.cnf and restart MySQL.  Then log into Webhost Manager and reset the password *again*&#8230; this is necessary to build a bridge between the linux root user and the MySQL root user, so you can log into MySQL both through WHM&#8217;s phpMyAdmin, and SSH without a password when logged into the server as root.</p>
<p>All you need to do now is recompile Apache, but move the MySQL libraries back so easyapache can find them:</p>
<p><font color="#ff66cc"><code>mv /root/sqllibs/libmysqlclient.* /usr/lib/mysql/</code></font></p>
<p>I haven&#8217;t tested too many configurations yet, but what works for me is Apache 2.2.4 with php 5.2.3, compiled with MySQL and mysqli, but NOT system MySQL.</p>
<p><!--adsense#img_banner--></p>
<p><map name='google_ad_map_83_7fa65e237551a74a'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/83?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_83_7fa65e237551a74a' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=83&amp;url= http%3A%2F%2Fwww.v-nessa.net%2F2007%2F07%2F20%2Fupgrading-to-mysql-5120-on-cpanel' /></p><img src="http://www.v-nessa.net/?ak_action=api_record_view&id=83&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.v-nessa.net/2007/07/20/upgrading-to-mysql-5120-on-cpanel/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Simple MySQL Search Query</title>
		<link>http://www.v-nessa.net/2007/07/04/simple-mysql-search-query</link>
		<comments>http://www.v-nessa.net/2007/07/04/simple-mysql-search-query#comments</comments>
		<pubDate>Wed, 04 Jul 2007 07:35:38 +0000</pubDate>
		<dc:creator>Nessa</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://www.v-nessa.net/2007/07/04/simple-mysql-search-query/</guid>
		<description><![CDATA[If you use MySQL to keep a ton of records, it might be nice to be able to search for the particular entry you&#8217;re looking for via a simple form on your site. To set this up, we&#8217;ll make two scripts &#8212; one being the form itself, the other being script that executes the MySQL [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.v-nessa.net%2F2007%2F07%2F04%2Fsimple-mysql-search-query"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.v-nessa.net%2F2007%2F07%2F04%2Fsimple-mysql-search-query&amp;source=nessa421&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>If you use MySQL to keep a ton of records, it might be nice to be able to search for the particular entry you&#8217;re looking for via a simple form on your site.  To set this up, we&#8217;ll make two scripts &#8212; one being the form itself, the other being script that executes the MySQL query.</p>
<p>In this example I created a simple form to query a database to look a person&#8217;s last name from a  database column in an &#8216;addressbook&#8217; database.  First, we need to create the form.  This is just a simple html file with a single input field:<br />
<code><font color="#ff66cc"><br />
&lt;html&gt;<br />
&lt;body&gt;<br />
&lt;h4&gt;Enter Last Name:&lt;/h4&gt;<br />
&lt;form action="query.php" method="post"&gt;<br />
Server: &lt;input name="lastName" type="text" /&gt;<br />
&lt;input type="submit" value="Submit" /&gt;<br />
&lt;/form&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
</font></code></p>
<p>Here i named the form field &#8216;lastName&#8217;, which will be the variable passed on to the php script and returned later on, and that the form action is set to &#8216;query.php&#8217;, which is the name of the script processing the form.  Next, create a file called query.php:</p>
<p>In the first section we need to define a few database variables to allow the script to connect to the database:</p>
<p><code><font color="#ff66cc"><br />
&lt;?php<br />
// Make a MySQL Connection<br />
$dbhost = "localhost";<br />
$dbname = "database_name";<br />
$dbuser = "database_user";<br />
$dbpass = "password";<br />
</font></code></p>
<p>Next, we need to define the posted variable &#8216;lastName&#8217;, which we created in the form to allow that variable to pass into this script.  If you have register_globals turned on (which is a BAD idea), you don&#8217;t need to do this.</p>
<p><code><font color="#ff66cc"><br />
$lastName = $_POST['lastName'];<br />
</font></code><br />
Now for actual query itself.  The syntax you use to search a database table is as follows:<br />
<code><font color="#ff66cc"><br />
SELECT &lt;what info&gt; FROM &lt;table&gt; WHERE &lt;column&gt;='&lt;search term'&gt;<br />
</font></code><br />
So in that case, I want to select everything from the &#8216;names&#8217; table where the last name is equal to what I search for, denoted by the variable &#8216;lastName&#8217;<br />
<code><font color="#ff66cc"><br />
$query = "SELECT * FROM names WHERE lastname='$lastName'";<br />
</font></code><br />
Similarly if you wanted to search two tables in one query you can just use the UNION command like so:<br />
<code><font color="#ff66cc"><br />
$query = "SELECT * FROM name WHERE lastname='$lastName' UNION SELECT * FROM morenames WHERE lastName='$lastName'<br />
</font></code></p>
<p>Now that all that crap is defined, create the database link:</p>
<p><code><font color="#ff66cc"><br />
$dblink = mysql_connect($dbhost, $dbuser, $dbpass);<br />
mysql_select_db($dbname, $dblink);<br />
?&gt;<br />
</font></code><br />
Now you can echo the results back into an array (in case there is more than one entry):<br />
<code><font color="#ff66cc"><br />
&lt;h2&gt; Query Results for &lt;?php echo($lastName); ?&gt; : &lt;/h2&gt;<br />
&lt;?php</font></code><font color="#ff66cc"><code><br />
$result = mysql_query($query) or die(mysql_error());<br />
$row = mysql_fetch_array($result) or die(mysql_error());<br />
while($row = mysql_fetch_array($result)){<br />
echo $row['lastName']. " ", $row['firstName'];<br />
echo "&lt;br /&gt;";<br />
}<br />
?&gt;<br />
</code></font><br />
To explain above, the query is run against the database and the results are fetched as an array.  The row(s) contained the search terms are then displayed to the screen based on the colums specified, which in this case are &#8216;firstName&#8217; and &#8216;lastName&#8217;<br />
In case you&#8217;re on the slower end, here&#8217;s the entire query.php script:</p>
<p><code><font color="#ff66cc">&lt;?php<br />
// Make a MySQL Connection<br />
$dbhost = "localhost";<br />
$dbname = "database_name";<br />
$dbuser = "database_user";<br />
$dbpass = "password";</font></code></p>
<p><code><font color="#ff66cc"> $lastName = $_POST['lastName'];</font></code></p>
<p><code><font color="#ff66cc"> $query = "SELECT * FROM names WHERE lastname='$lastName'";</font></code></p>
<p><code><font color="#ff66cc">$dblink = mysql_connect($dbhost, $dbuser, $dbpass);<br />
mysql_select_db($dbname, $dblink);<br />
?&gt;</font></code></p>
<p><code><font color="#ff66cc"> &lt;h2&gt; Query Results for &lt;?php echo($lastName); ?&gt; : &lt;/h2&gt;<br />
&lt;?php</font></code><font color="#ff66cc"><code><br />
$result = mysql_query($query) or die(mysql_error());<br />
$row = mysql_fetch_array($result) or die(mysql_error());<br />
while($row = mysql_fetch_array($result)){<br />
echo $row['lastName']. " ", $row['firstName'];<br />
echo "&lt;br /&gt;";<br />
}<br />
?&gt;</code></font></p>
<p><!--adsense--></p>
<p><map name='google_ad_map_80_7fa65e237551a74a'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/80?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_80_7fa65e237551a74a' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=80&amp;url= http%3A%2F%2Fwww.v-nessa.net%2F2007%2F07%2F04%2Fsimple-mysql-search-query' /></p><img src="http://www.v-nessa.net/?ak_action=api_record_view&id=80&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.v-nessa.net/2007/07/04/simple-mysql-search-query/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Optimizing PHP, Revisited.</title>
		<link>http://www.v-nessa.net/2007/04/16/optimizing-php-revisited</link>
		<comments>http://www.v-nessa.net/2007/04/16/optimizing-php-revisited#comments</comments>
		<pubDate>Mon, 16 Apr 2007 12:34:19 +0000</pubDate>
		<dc:creator>Nessa</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[site design]]></category>

		<guid isPermaLink="false">http://www.v-nessa.net/2007/04/16/optimizing-php-revisited/</guid>
		<description><![CDATA[I wrote an article a while back on PHP optimization, but it was pretty lacking in most aspects, probably because I&#8217;m a lazy poster. I&#8217;ve revisited that article and reposted to hopfully have it be a little more helpful on the area. &#8220;My website is slow&#8221; Yes, we&#8217;ve already established that. And while your visitors [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.v-nessa.net%2F2007%2F04%2F16%2Foptimizing-php-revisited"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.v-nessa.net%2F2007%2F04%2F16%2Foptimizing-php-revisited&amp;source=nessa421&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I wrote an article a while back on PHP optimization, but it was pretty lacking in most aspects, probably because I&#8217;m a lazy poster.  I&#8217;ve revisited that article and reposted to hopfully have it be a little more helpful on the area.<br />
<span id="more-46"></span></p>
<p><strong>&#8220;My website is slow&#8221;</strong></p>
<p>Yes, we&#8217;ve already established that.  And while your visitors are waiting for it to load, they are probably Mapquest-ing your house and buying a shovel at their local hardware store.  No one cares how hot your website is if they have to wait an eternity to see it.</p>
<p>Before we continue on this topic, it&#8217;s important for you to understand how PHP works.  PHP is an HTML-embedded scripting language that is executed server-side, therefore it generates dynamic content more quickly and efficiently than most other programming languages.  The obvous conclusion is that the server your site is hosted on needs to provide a good PHP environment, and your site needs to be optimized to take advantage of that.</p>
<p>FYI, One of my other posts <a href="http://www.v-nessa.net/2007/04/15/timing-your-php-scripts/">demonstrates a code addition</a> that you can implement into your website to display how long a page takes to generate.  This can be helpful in relializing exactly how long your site takes to load!</p>
<h2> <u><strong>Setting the Server Environment</strong></u></h2>
<p>This section will probably not have much relevance to websites that are hosted on shared or free hosting plans, as most hosting companies shy away from making server-side changes.   You may choose to skip this section and go straight to the programming concepts, my feelings won&#8217;t be hurt.</p>
<p><strong>Your Hosting</strong></p>
<p>If you are serious about your website and want the best performance possible, you should probably look into a v-dedicated hosted environment.  The benefits of this is that 1) you are on your own server, so other websites will not affect yours, and 2) you can usually choose your own server configuration.  If you need a quick and easy solution, <a href="http://inmotionhosting.com/dedicated_server.html" title="InMotion Hosting" target="_blank">InMotion</a> Hosting offers a nice selection of v-dedicated hosting plans.</p>
<p>If VPS hosting is not an option to you yet, you can ask your host if they have any shared servers based on the configuration you need.  There&#8217;s also the option of hosting your own website, but we won&#8217;t go into that here.</p>
<p><strong>MySQL/PHP Versions</strong></p>
<p>My website is currently running on CentOS 4, Apache 1.3.37, PHP 5.2.1, and MySQL 5.  This does well for my website, but you&#8217;ll want to make sure that whatever combination you choose will work well together.  I would say that PHP 5.2.1 and MySQL 5 are the best combination to use as long as your website software is compatible.  If not, the alternative PHP 4.4.6 and MySQL 4.1 should be just fine.  Keep in mind that as far as MySQL and PHP are concerned, newer is usually better.</p>
<p><strong>PHP Accelerators</strong></p>
<p>Hands down, a Zend/eAccelerator platform is the best way to go.  <a href="http://www.zend.com/products/zend_optimizer" title="Zend" target="_blank">Zend Optimizer</a> is the most popular and stable (and free!) PHP acceleration agent there is, and <a href="http://eaccelerator.net" title="eAccelerator" target="_blank">eAccelerator</a> compliments it nicely with its advanced caching and processing engine.  Since I installed both on my server, I&#8217;ve noticed a considerably faster loading time in my website.</p>
<p>Zend can be installed easily by it&#8217;s autoinstaller, but if you need help installing eAccelerator, have a quick look at Shelby&#8217;s walkthrough.</p>
<p><!--adsense--></p>
<h2><strong><u>Optimizing your Website</u></strong></h2>
<p>This section mainly deals with small modifications you can make to your site to help it load faster.  I&#8217;m not going to go too much into programming here, but there are a lot resources online that can <a href="http://www.dublish.com/articles/10.html" title="Optimizing PHP" target="_blank">help you out</a> in that department.</p>
<p><strong>Keep Your Stuff up to Date</strong></p>
<p>If you’re using bundled software like a CMS, blog, Gallery, etc., software developers are constantly making updates and improvements to up the speed and security of their programs. If you’re not willing to keep up with the newest releases, don’t expect peak performance of your site.</p>
<p><strong>Caching</strong></p>
<p>You know how when you go to a website a few minutes after you&#8217;ve already been there it seems to have loaded a ton faster?  That&#8217;s because there are two caching agents in place &#8212; your ISP has cached that website into their nameservers to avoid having to do another external lookup, and your browser cached the website on your computer to avoid having to look it up, period.  If you implement the same concept into your website, the logical conclusion is that the server will serve your pages more efficiently.  The benefit of caching is that is generally uses less resources since the database isn&#8217;t being utilized as much, which cuts down on resources.  Some bundled software will have an option or third-party plugin that can easily set up caching on your site.  You can also use something like <a href="http://httpd.apache.org/docs/2.0/mod/mod_cache.html" title="mod_cache" target="_blank">mod_cache</a> for Apache to accomplish similar results.</p>
<p><strong>What is all this junk?</strong></p>
<p>Do you really find it necessary to bog your website down with ads and useless plugins?  You&#8217;re really not doing your site (or your visitors for that matter) a favor by loading your site with a lot of junk.  I&#8217;m not saying to stay away from plugins and ads altogether (being that my site uses both of all of the above), but to use them in moderation and be aware of the ones that suck.  Honestly, there are a lot of really nice additions to some of my favorite software, but some of them can cause your site to load a lot more slowly.</p>
<p><strong>Images</strong></p>
<p>Lastly, most novice web designers tend to make this mistake when adding images to their sites.  Since digital media has become more popular, it&#8217;s become a lot easier just to upload images straight from your camera onto the web.  Most digital cameras nowadays take multi-pixel snapshots, which can amount to  pictures that are several megs in size.  What most beginner programmers don&#8217;t know is that when you upload an image this size and then just resize it with HTML &lt;img&gt; tags, it does NOT change the actual MB size of the image itself.  Resizing the images with HTML also makes the pictures look crappy by reducing their quality.</p>
<p>If you are adding images to your site, you should take their loading time into consideration.  Resize them first on your computer, then upload them to your site.  You also try to use web-friendly image formats like GIF, JPEG, and PNG, which yield high-quality images without the massive size.</p>
<p><!--adsense#img_banner--></p>
<p><map name='google_ad_map_46_7fa65e237551a74a'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/46?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_46_7fa65e237551a74a' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=46&amp;url= http%3A%2F%2Fwww.v-nessa.net%2F2007%2F04%2F16%2Foptimizing-php-revisited' /></p><img src="http://www.v-nessa.net/?ak_action=api_record_view&id=46&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.v-nessa.net/2007/04/16/optimizing-php-revisited/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Make a Sexy Tag Cloud with PHP and MySQL</title>
		<link>http://www.v-nessa.net/2007/02/12/how-to-make-a-sexy-tag-cloud</link>
		<comments>http://www.v-nessa.net/2007/02/12/how-to-make-a-sexy-tag-cloud#comments</comments>
		<pubDate>Mon, 12 Feb 2007 06:59:39 +0000</pubDate>
		<dc:creator>Nessa</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.v-nessa.net/2007/02/12/how-to-make-a-sexy-tag-cloud/</guid>
		<description><![CDATA[Well it seems that everyone has one, and I&#8217;d have to admit that a tag cloud is a good way to spice up your site a little bit. I first thought of this when setting up a friend&#8217;s site&#8230; he wasn&#8217;t using a CMS like WordPress or anything that I could find a quick tag [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.v-nessa.net%2F2007%2F02%2F12%2Fhow-to-make-a-sexy-tag-cloud"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.v-nessa.net%2F2007%2F02%2F12%2Fhow-to-make-a-sexy-tag-cloud&amp;source=nessa421&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="http://v-nessa.net/images/tag_cloud.gif" rel="lightbox[groupname]" title="Tag Cloud"><img src="http://v-nessa.net/images/tag_cloud.gif" alt="Tag Cloud" align="right" height="189" width="246" /></a>Well it seems that everyone has one, and I&#8217;d have to admit that a tag cloud is a good way to spice up your site a little bit.  I first thought of this when setting up a friend&#8217;s site&#8230; he wasn&#8217;t using a CMS like <a href="http://wordpress.org" title="Wordpress" target="_blank">WordPress</a> or anything that I could find a quick tag cloud plugin for, so I figured I could probably just make my own.  Well, I did and now I shall share it.</p>
<p>This tutorial will show you how to set up a simple tag cloud using PHP and MySQL, with a little bit of Ajax effects<br />
Before we get started, take a quick look at the <a href="http://www.v-nessa.net/cloud/" onclick="NewWindow(this.href,'windowname','300','150','no','center');return false" onfocus="this.blur()">sample cloud</a>.<br />
<span id="more-32"></span></p>
<p><strong><br />
Getting Started</strong></p>
<p>The server requirements to make a tag cloud are minimal.  You will need a new or existing <a href="http://mysql.com" title="MySQL" target="_blank">MySQL</a> database and <a href="http://php.net" title="PHP" target="_blank">PHP4+</a>.  It would also be extremely helpful to have something like <a href="http://www.phpmyadmin.net" title="phpMyAdmin" target="_blank">phpMyAdmin</a> or a MySQL command prompt to create the table.</p>
<p><strong><br />
</strong></p>
<p><strong>Creating the Table</strong></p>
<p>The first thing you need to do is create the database table.  You can do this in either a new or existing database:<br />
<font color="#ff66cc"><br />
<code>CREATE TABLE tags (<br />
id int(11) NOT NULL AUTO_INCREMENT,<br />
PRIMARY KEY(id),<br />
tag varchar(100) NOT NULL,<br />
count int(11) NOT NULL DEFAULT '0'<br />
);</code></font></p>
<p>I ran this query via command line, but it may be easier to use phpMyAdmin or whatever database tool you use.  Basically, this is a simply MySQL command that creates the &#8216;<strong>tags</strong>&#8216; table with three columns: <strong>id</strong>, <strong>tag</strong>, and <strong>count</strong>.  The <strong>id</strong> table is being set to auto-increment, meaning that every time a new entry is added the number will go up by 1.  Depending on how you are implementing your tag cloud, you may want to remove this value if you have trouble adding entries.</p>
<p><strong>Creating the Cloud </strong><br />
Now for the actual code itself.  In this section I will break down the script that fetches the tags from the database and creates a pretty tag cloud.  At the end you will find a full sample script that you can use for reference.</p>
<p><font color="#ff66cc"><code>$db_host = "localhost";<br />
$db_user = "username";<br />
$db_pass = "password";<br />
$db_name = "cloud";<br />
</code><code><br />
mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());<br />
mysql_select_db($db_name);</code></font></p>
<p>This is the section where you define a few variables and use them to connect to the database.  You wil obviously need to input your database name, username, and password in order to allow the script to connect.</p>
<p><font color="#ff66cc"><code>function tag_info() {<br />
$result = mysql_query("SELECT * FROM tags GROUP BY tag ORDER BY count DESC");<br />
while($row = mysql_fetch_array($result)) {<br />
$arr[$row['tag']] = $row['count'];<br />
}<br />
ksort($arr);<br />
return $arr;<br />
}</code></font></p>
<p>This is the function that grabs the tag information from the database and displays everything in the tag column as an array.  Now to build the cloud:<br />
<font color="#ff66cc"><br />
<code>function tag_cloud() {</code></font></p>
<p><code><font color="#ff66cc">$min_size = 10;</font></code><font color="#ff66cc"><br />
<code>$max_size = 30;</code></font></p>
<p><code><font color="#ff66cc">$tags = tag_info();</font></code></p>
<p><code><font color="#ff66cc">$minimum_count = min(array_values($tags));<br />
$maximum_count = max(array_values($tags));<br />
$spread = $maximum_count - $minimum_count;</font></code></p>
<p><code><font color="#ff66cc">if($spread == 0) {<br />
$spread = 1;<br />
}</font></code><font color="#ff66cc"><br />
<code><br />
$cloud_html = '';<br />
$cloud_tags = array();</code></font></p>
<p><font color="#ff66cc"><code>foreach ($tags as $tag =&gt; $count) {<br />
$size = $min_size + ($count - $minimum_count)<br />
* ($max_size - $min_size) / $spread;<br />
$cloud_tags[] = '&lt;a style="font-size: '. floor($size) . 'px'<br />
. '" class="tag_cloud" href="http://www.v-nessa.net/index.php?s=' . $tag<br />
. '" title="\'' . $tag  . '\' returned a count of ' . $count . '"&gt;'<br />
. htmlspecialchars(stripslashes($tag)) . '&lt;/a&gt;';<br />
}<br />
$cloud_html = join("\n", $cloud_tags) . "\n";<br />
return $cloud_html;</code></font></p>
<p><code><font color="#ff66cc">}</font></code></p>
<p><code><font color="#ff66cc">?&gt;</font></code></p>
<p>Take special note of this code:<br />
<font color="#ff66cc"><br />
<code>class="tag_cloud" href="http://www.v-nessa.net/index.php?s=' . $tag</code></font></p>
<p>In this section I&#8217;m basically telling the script to append the tag name at the end of a link&#8230;in this case it&#8217;s my search path, meaning that clicking on, for instance, the ruby tag will take you to this link:</p>
<p><strong>http://www.v-nessa.net/index.php?s=ruby</strong></p>
<p>This will just take you to a search for the term &#8220;ruby&#8221; on my site, but you can specify how you want the tag name to be incorporated into a link.  For instance:<br />
<font color="#ff66cc"><br />
<code>class="tag_cloud" href="http://www.v-nessa.net/tags/' . $tag</code></font></p>
<p>The above example shows the primary purpose of a tag cloud, which will take the tag pulled from a database and pull all articles under that tag.  An example of this is on the menu of my site, to the right.</p>
<p>The last part of the script should be the style sheet, which will direct how the cloud will look:<br />
<font color="#ff66cc"><br />
<code>&lt;style type="text/css"&gt;<br />
.tag_cloud<br />
{padding: 3px; text-decoration: none;<br />
font-family: verdana;   }<br />
.tag_cloud:link  { color: #FF66CC; }<br />
.tag_cloud:visited { color: #9900FF; }<br />
.tag_cloud:hover { color: #FF66CC; background: #000000; }<br />
.tag_cloud:active { color: #6699FF; background: #000000; }<br />
&lt;/style&gt;</code><br />
</font></p>
<p>To Display the tag cloud, you just need to insert this code into your web page (or sidebar):</p>
<p><font color="#ff66cc"><code> &lt;div id="wrapper"&gt;<br />
&lt;?php print tag_cloud(); ?&gt;<br />
&lt;/div&gt;</code></font></p>
<p>And there you go&#8230;your very own tag cloud.  You&#8217;ll of course need to populate the table with your own tags, ids and count numbers, or plug this script into your blog to fetch the tags from its database.</p>
<p>You can find a full copy of the script <a href="http://www.v-nessa.net/scripts/tag_cloud.phps" title="Tag Cloud" target="_blank">here</a>.</p>
<p><a href="http://tinyurl.com/3cu9zg"><br />
</a></p>
<p><!--adsense#img_banner--></p>
<p><map name='google_ad_map_32_7fa65e237551a74a'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/32?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_32_7fa65e237551a74a' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=32&amp;url= http%3A%2F%2Fwww.v-nessa.net%2F2007%2F02%2F12%2Fhow-to-make-a-sexy-tag-cloud' /></p><img src="http://www.v-nessa.net/?ak_action=api_record_view&id=32&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.v-nessa.net/2007/02/12/how-to-make-a-sexy-tag-cloud/feed</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>The Basic MySQL Injection</title>
		<link>http://www.v-nessa.net/2007/01/17/the-basic-mysql-injection-2</link>
		<comments>http://www.v-nessa.net/2007/01/17/the-basic-mysql-injection-2#comments</comments>
		<pubDate>Thu, 18 Jan 2007 03:44:53 +0000</pubDate>
		<dc:creator>Nessa</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://www.v-nessa.net/2007/01/17/the-basic-mysql-injection-2/</guid>
		<description><![CDATA[Ahhhh the classic hack that doesn&#8217;t work anymore&#8230; which is why I&#8217;m posting it here. I always thought it was kind of an interesting concept but no one ever made it simple for me, so I shall do this for you. How to do a simple MySQL Injection Ok, so this is your basic PHP [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.v-nessa.net%2F2007%2F01%2F17%2Fthe-basic-mysql-injection-2"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.v-nessa.net%2F2007%2F01%2F17%2Fthe-basic-mysql-injection-2&amp;source=nessa421&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Ahhhh the classic hack that doesn&#8217;t work anymore&#8230; which is why I&#8217;m posting it here.  I always thought it was kind of an interesting concept but no one ever made it simple for me, so I shall do this for you.</p>
<p><strong>How to do a simple MySQL Injection</strong></p>
<p>Ok, so this is your basic PHP login script that asks for your username and password, which would then query the database to authenticate you:<br />
<font color="#ff66cc"><br />
<code></code></font></p>
<blockquote><p><font color="#ff66cc">$user = $_POST["username"];<br />
$pass = $_POST["password"];<br />
$query = mysql_query(&#8220;SELECT * FROM users WHERE user=&#8217;$user&#8217; AND password=&#8217;$password&#8217;&#8221;);<br />
$rows = mysql_fetch_row($query);<br />
if ($rows == 0) {<br />
die (&#8216;Login Incorrect!&#8217;); }</font></p></blockquote>
<p>Assuming that <a href="http://us3.php.net/register_globals" title="Register Globals" target="_blank">register_globals</a> are enabled on the server, this script will work and in return use the <a href="http://us3.php.net/manual/en/reserved.variables.php" title="Predefined Variables" target="_blank">POST</a> variable to query the database for an already-defined row to see if both conditions are being met, which are obviously the username/password fields.  If the input does not meet this requirement, then the connection dies and returns the &#8220;<em>Login Incorrect</em>&#8221; error.  So assume I log in with the username &#8220;<em>nessa</em>&#8221; and the password &#8220;<em>sexy</em>.&#8221;  The <strong>$query</strong> string will pass this command to MySQL:<br />
<font color="#ff66cc"><br />
<code>$query = mysql_query("SELECT * FROM users WHERE user='nessa' AND password=" OR"=' OR '1'='1'");</code></font></p>
<p>Since I used the <strong>OR</strong> clause in the password field, that can leave a few possibilities up to the database to determine whether a statement is true or false.  As you can see, <strong>&#8216;</strong> will always be equal to <strong>&#8216;</strong>, and <strong>1</strong> is always equal to <strong>1</strong>, so MySQL is happy as long as these requirements are met.</p>
<p>So what does that tell you?  You can easily replace either the username or password fields withe a <strong>&#8221;</strong> or a <strong>&#8221; OR 1</strong> and you will have a successful login each time.  Of course there are a lot more combinations that will work &#8212; you might want to check out this site:</p>
<p><a href="http://www.justinshattuck.com/?p=156&amp;akst_action=share-this">http://www.justinshattuck.com/?p=156&amp;akst_action=share-this</a></p>
<p>Now seeing that this site is powered by PHP and MySQL, you probably think I&#8217;m stupid by posting this.  Well quite frankly, MySQL injections are old and nearly impossible with well-scripted PHP software and good PHP environment.  If you&#8217;re running a custom script or old software, here&#8217;s how you can protect your crappy software from being exploited:<br />
<strong>Check your magic quotes setting in php.ini or .htaccess:</strong></p>
<p><strong>magic_quotes_gpc</strong> should be turned on, as this automatically slash-escapes your codes so MySQL is less likely to make a false positive.  As of PHP4, this setting is enabled by default.</p>
<p>If you don&#8217;t want to use magic quotes, use <strong>mysql_real_escape_string():</strong></p>
<p>Here&#8217;s a simple script you can use as an include to automatically escape null characters:</p>
<p><span style="color: #000000"><span style="color: #0000bb"><font face="Courier New"><!--p<br--></font></span><font face="Courier New"><span style="color: #ff8000">// Quote variable to make safe<br />
</span><span style="color: #007700">function </span><span style="color: #0000bb">quote_smart</span><span style="color: #007700">(</span><span style="color: #0000bb">$value</span></font><span style="color: #007700"><font face="Courier New">)<br />
{<br />
</font></span><font face="Courier New"><span style="color: #ff8000">// Stripslashes<br />
</span><span style="color: #007700">if (</span><span style="color: #0000bb">get_magic_quotes_gpc</span></font><font face="Courier New"><span style="color: #007700">()) {<br />
</span><span style="color: #0000bb">$value </span><span style="color: #007700">= </span><span style="color: #0000bb">stripslashes</span><span style="color: #007700">(</span><span style="color: #0000bb">$value</span></font><span style="color: #007700"><font face="Courier New">);<br />
}<br />
</font></span><font face="Courier New"><span style="color: #ff8000">// Quote if not integer<br />
</span><span style="color: #007700">if (!</span><span style="color: #0000bb">is_numeric</span><span style="color: #007700">(</span><span style="color: #0000bb">$value</span></font><font face="Courier New"><span style="color: #007700">)) {<br />
</span><span style="color: #0000bb">$value </span><span style="color: #007700">= </span><span style="color: #dd0000">&#8220;&#8216;&#8221; </span><span style="color: #007700">. </span><span style="color: #0000bb">mysql_real_escape_string</span><span style="color: #007700">(</span><span style="color: #0000bb">$value</span><span style="color: #007700">) . </span><span style="color: #dd0000">&#8220;&#8216;&#8221;</span></font><font face="Courier New"><span style="color: #007700">;<br />
}<br />
return </span><span style="color: #0000bb">$value</span></font><font face="Courier New"><span style="color: #007700">;<br />
}<br />
</span><span style="color: #0000bb">?&gt;</span> </font></span></p>
<p><span style="color: #000000"><font face="Verdana">And the obvious, if you&#8217;re using bundled software make sure you keep it up to date.  New exploits are being found all the time, so don&#8217;t put yourself out there by not updating your shit.</font></span></p>
<p><a href="http://tinyurl.com/3cu9zg"><br />
</a></p>
<p><!--adsense--></p>
<p><map name='google_ad_map_23_7fa65e237551a74a'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/23?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_23_7fa65e237551a74a' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=23&amp;url= http%3A%2F%2Fwww.v-nessa.net%2F2007%2F01%2F17%2Fthe-basic-mysql-injection-2' /></p><img src="http://www.v-nessa.net/?ak_action=api_record_view&id=23&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.v-nessa.net/2007/01/17/the-basic-mysql-injection-2/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

