<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: php system script for maintaining mysql databases and tables</title>
	<link>http://breign.com/2008/06/12/php-system-script-for-maintaining-mysql-databases-and-tables/</link>
	<description>About my brains, my lifes, ideas, works. About computers. Jokes and dreams, reigns and realms...</description>
	<pubDate>Tue, 06 Jan 2009 06:20:56 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
		<item>
		<title>By: Borgscan</title>
		<link>http://breign.com/2008/06/12/php-system-script-for-maintaining-mysql-databases-and-tables/#comment-361</link>
		<dc:creator>Borgscan</dc:creator>
		<pubDate>Fri, 12 Dec 2008 13:22:02 +0000</pubDate>
		<guid>http://breign.com/2008/06/12/php-system-script-for-maintaining-mysql-databases-and-tables/#comment-361</guid>
		<description>Thanks for the information that it unlocks the if the connection is dropped, I didn't know that.

I made a slight mistake when calling the error handler too, it should be: 

…or die(sql_error((mysql_errno(), mysql_error(), $repair, realpath(__FILE__), __LINE__));</description>
		<content:encoded><![CDATA[<p>Thanks for the information that it unlocks the if the connection is dropped, I didn&#8217;t know that.</p>
<p>I made a slight mistake when calling the error handler too, it should be: </p>
<p>…or die(sql_error((mysql_errno(), mysql_error(), $repair, realpath(__FILE__), __LINE__));</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Benjo</title>
		<link>http://breign.com/2008/06/12/php-system-script-for-maintaining-mysql-databases-and-tables/#comment-359</link>
		<dc:creator>Benjo</dc:creator>
		<pubDate>Sun, 07 Dec 2008 21:24:56 +0000</pubDate>
		<guid>http://breign.com/2008/06/12/php-system-script-for-maintaining-mysql-databases-and-tables/#comment-359</guid>
		<description>Borgscan I must say you have pretty deep thoughts, but I think that the error handler in this script is an overhead. 
As posted on http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html the lock is released with a dropped connection - eg. if the script dies or terminates in any way other than hangs as a zombie process.
Don't get me wrong, your approach is very good and programs should have errors handled in every way.</description>
		<content:encoded><![CDATA[<p>Borgscan I must say you have pretty deep thoughts, but I think that the error handler in this script is an overhead.<br />
As posted on <a href="http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html</a> the lock is released with a dropped connection - eg. if the script dies or terminates in any way other than hangs as a zombie process.<br />
Don&#8217;t get me wrong, your approach is very good and programs should have errors handled in every way.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Borgscan</title>
		<link>http://breign.com/2008/06/12/php-system-script-for-maintaining-mysql-databases-and-tables/#comment-358</link>
		<dc:creator>Borgscan</dc:creator>
		<pubDate>Sun, 07 Dec 2008 13:09:20 +0000</pubDate>
		<guid>http://breign.com/2008/06/12/php-system-script-for-maintaining-mysql-databases-and-tables/#comment-358</guid>
		<description>Correct me if I'm wrong, but wouldn't your tables remain locked if your script dies here:

$repair = mysql_query("REPAIR TABLE ".$col_value." QUICK") or die('Query failed: ' . mysql_error());

I've been trying to figure out a way around this and the only one I can think of is to use an error handler that also unlocks the table. e.g:

...or die((mysql_errno(), mysql_error(), $repair, realpath(__FILE__), __LINE__);

$unlock = mysql_query("UNLOCK TABLES") or die('Query failed: ' . mysql_error());

Then your error handler could be someting like:

            function sql_error($errno, $error, $query, $file, $line)
	{
		define("SQL_ERRNO", $errno);
		define("SQL_ERROR", $error);
    	define("SQL_QUERY", $query);
		define("SQL_FILE", $file);
		define("SQL_LINE", $line);

		mysql_query("UNLOCK TABLES");
    	trigger_error("sql", E_USER_ERROR);
	}

	function error_handler($errno, $error, $file, $line)
	{
		if ($error == "sql")
		{
			echo "&lt;b&gt;An Error Has Occurred&lt;/b&gt;[$errno] ".SQL_ERROR."Query: ".SQL_QUERY."File: ".SQL_FILE."Line: ".SQL_LINE."PHP: ".PHP_VERSION." (".PHP_OS.")";
		}
		else
		{
			echo "&lt;b&gt;An Error Has Occurred&lt;/b&gt;";
		}
	}</description>
		<content:encoded><![CDATA[<p>Correct me if I&#8217;m wrong, but wouldn&#8217;t your tables remain locked if your script dies here:</p>
<p>$repair = mysql_query(&#8221;REPAIR TABLE &#8220;.$col_value.&#8221; QUICK&#8221;) or die(&#8217;Query failed: &#8216; . mysql_error());</p>
<p>I&#8217;ve been trying to figure out a way around this and the only one I can think of is to use an error handler that also unlocks the table. e.g:</p>
<p>&#8230;or die((mysql_errno(), mysql_error(), $repair, realpath(__FILE__), __LINE__);</p>
<p>$unlock = mysql_query(&#8221;UNLOCK TABLES&#8221;) or die(&#8217;Query failed: &#8216; . mysql_error());</p>
<p>Then your error handler could be someting like:</p>
<p>            function sql_error($errno, $error, $query, $file, $line)<br />
	{<br />
		define(&#8221;SQL_ERRNO&#8221;, $errno);<br />
		define(&#8221;SQL_ERROR&#8221;, $error);<br />
    	define(&#8221;SQL_QUERY&#8221;, $query);<br />
		define(&#8221;SQL_FILE&#8221;, $file);<br />
		define(&#8221;SQL_LINE&#8221;, $line);</p>
<p>		mysql_query(&#8221;UNLOCK TABLES&#8221;);<br />
    	trigger_error(&#8221;sql&#8221;, E_USER_ERROR);<br />
	}</p>
<p>	function error_handler($errno, $error, $file, $line)<br />
	{<br />
		if ($error == &#8220;sql&#8221;)<br />
		{<br />
			echo &#8220;<b>An Error Has Occurred</b>[$errno] &#8220;.SQL_ERROR.&#8221;Query: &#8220;.SQL_QUERY.&#8221;File: &#8220;.SQL_FILE.&#8221;Line: &#8220;.SQL_LINE.&#8221;PHP: &#8220;.PHP_VERSION.&#8221; (&#8221;.PHP_OS.&#8221;)&#8221;;<br />
		}<br />
		else<br />
		{<br />
			echo &#8220;<b>An Error Has Occurred</b>&#8220;;<br />
		}<br />
	}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tess</title>
		<link>http://breign.com/2008/06/12/php-system-script-for-maintaining-mysql-databases-and-tables/#comment-266</link>
		<dc:creator>Tess</dc:creator>
		<pubDate>Tue, 28 Oct 2008 22:11:18 +0000</pubDate>
		<guid>http://breign.com/2008/06/12/php-system-script-for-maintaining-mysql-databases-and-tables/#comment-266</guid>
		<description>Good post.</description>
		<content:encoded><![CDATA[<p>Good post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: php system script for maintaining mysql databases and tables</title>
		<link>http://breign.com/2008/06/12/php-system-script-for-maintaining-mysql-databases-and-tables/#comment-45</link>
		<dc:creator>php system script for maintaining mysql databases and tables</dc:creator>
		<pubDate>Thu, 12 Jun 2008 19:47:23 +0000</pubDate>
		<guid>http://breign.com/2008/06/12/php-system-script-for-maintaining-mysql-databases-and-tables/#comment-45</guid>
		<description>[...] JR Raphael wrote an interesting post today onHere&#8217;s a quick excerptUse it in cron and have a peace with tables, indexes and keys [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] JR Raphael wrote an interesting post today onHere&#8217;s a quick excerptUse it in cron and have a peace with tables, indexes and keys [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Benjo</title>
		<link>http://breign.com/2008/06/12/php-system-script-for-maintaining-mysql-databases-and-tables/#comment-44</link>
		<dc:creator>Benjo</dc:creator>
		<pubDate>Thu, 12 Jun 2008 19:39:22 +0000</pubDate>
		<guid>http://breign.com/2008/06/12/php-system-script-for-maintaining-mysql-databases-and-tables/#comment-44</guid>
		<description>maybe someone will get with more ideas of how to extend this script...</description>
		<content:encoded><![CDATA[<p>maybe someone will get with more ideas of how to extend this script&#8230;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
