<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>http://www.h3rald.com/</id>
  <title>H3RALD - Tag 'databases' (Atom Feed)</title>
  <updated>2007-09-15T11:10:00Z</updated>
  <link href="http://www.h3rald.com" rel="alternate"/>
  <link href="http://www.h3rald.com/tags/databases/atom/" rel="self"/>
  <author>
    <name>Fabio Cevasco</name>
    <uri>http://www.h3rald.com</uri>
  </author>
  <entry>
    <id>tag:www.h3rald.com,2007-09-15:/articles/simply-on-rails-4-default-data-migrations/</id>
    <title>Simply On Rails - Part 4: Quick and Easy Default Data Migrations</title>
    <published>2007-09-15T11:10:00Z</published>
    <updated>2009-09-06T18:10:55Z</updated>
    <link href="http://www.h3rald.com/articles/simply-on-rails-4-default-data-migrations/" rel="alternate"/>
    <category term="rails" scheme="http://www.h3rald.com/tags/rails/"/>
    <category term="ruby" scheme="http://www.h3rald.com/tags/ruby/"/>
    <category term="databases" scheme="http://www.h3rald.com/tags/databases/"/>
    <content type="html">
<![CDATA[
<p>In the <a href="http://www.h3rald.com/blog/simply-on-rails-3-shared-controller">last post</a> of this series I tried to find a <acronym title="Don&#39;t Repeat Yourself"><span class="caps">DRY</span></acronym> solution to deal with tables storing &#8220;ancillary&#8221; data, i.e. names of user roles, predefined categories, page state names and other similar things.<br />
I personally chose to put this kind of data to make my application more dynamic, although I could have decided to use ENUMs or simply ordinary varchar fields &#8212; that would have been easier, but less flexible. For now, I&#8217;m sticking with my original choice.</p>
<p>The data in these tables is kind of a prerequisite for the application to run: I must be able to have a status to assign to a user when creating it, and the same applies to roles. Sure, I could spend 20 minutes populating these tables manually, but it would be nice if there was a less tedious way, wouldn&#8217;t it?</p>
<p>There is indeed. The inspiration came from a technique described in the book (which I highly recommend) <em>Agile Web Development With Rails</em>, in which the author outlines how it would be possible to use Rails&#8217; fixtures and migrations to load data in the database automatically from <span class="caps">YAML</span> files. <br />
All you have to do is create a migration to load the specified <span class="caps">YAML</span> files and you&#8217;re all set.</p>
<p>I wanted to take a little step further, allowing the migration to load data from <em>all <span class="caps">YAML</span> files in a specific directory</em>, automatically.Let&#8217;s start creating the <span class="caps">YAML</span> files then and place them all in one directory of the application like <code>/db/migrate/defaults</code>. Here&#8217;s the one I used for user roles, for example:</p>
<div class="highlight"><pre><span class="l-Scalar-Plain">visitor</span><span class="p-Indicator">:</span>
<span class="err">	</span><span class="l-Scalar-Plain">id</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">1</span>
<span class="err">	</span><span class="l-Scalar-Plain">name</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">Visitor</span>
<span class="err">	</span><span class="l-Scalar-Plain">level</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">0</span>

<span class="l-Scalar-Plain">user</span><span class="p-Indicator">:</span>
<span class="err">	</span><span class="l-Scalar-Plain">id</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">2</span>
<span class="err">	</span><span class="l-Scalar-Plain">name</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">User</span>
<span class="err">	</span><span class="l-Scalar-Plain">level</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">10</span>

<span class="l-Scalar-Plain">contributor</span><span class="p-Indicator">:</span>
<span class="err">	</span><span class="l-Scalar-Plain">id</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">3</span>
<span class="err">	</span><span class="l-Scalar-Plain">name</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">Contributor</span>
<span class="err">	</span><span class="l-Scalar-Plain">level</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">20</span>

<span class="l-Scalar-Plain">provider</span><span class="p-Indicator">:</span>
<span class="err">	</span><span class="l-Scalar-Plain">id</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">4</span>
<span class="err">	</span><span class="l-Scalar-Plain">name</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">Provider</span>
<span class="err">	</span><span class="l-Scalar-Plain">level</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">50</span>

<span class="l-Scalar-Plain">operator</span><span class="p-Indicator">:</span>
<span class="err">	</span><span class="l-Scalar-Plain">id</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">5</span>
<span class="err">	</span><span class="l-Scalar-Plain">name</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">Operator</span>
<span class="err">	</span><span class="l-Scalar-Plain">level</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">100</span>

<span class="l-Scalar-Plain">administrator</span><span class="p-Indicator">:</span>
<span class="err">	</span><span class="l-Scalar-Plain">id</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">6</span>
<span class="err">	</span><span class="l-Scalar-Plain">name</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">Administrator</span>
<span class="err">	</span><span class="l-Scalar-Plain">level</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">500</span>

<span class="l-Scalar-Plain">webmaster</span><span class="p-Indicator">:</span>
<span class="err">	</span><span class="l-Scalar-Plain">id</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">7</span>
<span class="err">	</span><span class="l-Scalar-Plain">name</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">Webmaster</span>
<span class="err">	</span><span class="l-Scalar-Plain">level</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">1000</span>
</pre>
</div><p>The important thing to remember is to provide a unique string to identify each record, before specifying each fiels. The other files look similar, so I won&#8217;t bother listing them here.</p>
<p>And here&#8217;s the simple code for the migration:</p>
<div class="highlight"><pre><span class="nb">require</span> <span class="s1">&#39;active_record/fixtures&#39;</span>

<span class="k">class</span> <span class="nc">LoadDefaults</span> <span class="o">&lt;</span> <span class="no">ActiveRecord</span><span class="o">::</span><span class="no">Migration</span>

	<span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">up</span>
		<span class="n">down</span>
		<span class="n">models</span> <span class="o">=</span> <span class="nb">self</span><span class="o">.</span><span class="n">default_models</span>
		<span class="n">models</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">m</span><span class="o">|</span>   
			<span class="no">Fixtures</span><span class="o">.</span><span class="n">create_fixtures</span><span class="p">(</span><span class="nb">self</span><span class="o">.</span><span class="n">default_directory</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span>
		<span class="k">end</span>
	<span class="k">end</span>

	<span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">down</span>
		<span class="n">models</span> <span class="o">=</span> <span class="nb">self</span><span class="o">.</span><span class="n">default_models</span>
		<span class="n">models</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">m</span><span class="o">|</span>
			<span class="nb">eval</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">#{</span><span class="n">m</span><span class="o">.</span><span class="n">singularize</span><span class="o">.</span><span class="n">capitalize</span><span class="si">}</span><span class="s2">.delete_all&quot;</span><span class="p">)</span>
		<span class="k">end</span>
	<span class="k">end</span>

	<span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">default_directory</span>
		<span class="no">File</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="no">File</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="bp">__FILE__</span><span class="p">),</span> <span class="s2">&quot;defaults&quot;</span> <span class="p">)</span>
	<span class="k">end</span>

	<span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">default_models</span>
		<span class="n">files</span><span class="p">,</span> <span class="n">names</span> <span class="o">=</span> <span class="no">Dir</span><span class="o">.</span><span class="n">glob</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">#{</span><span class="nb">self</span><span class="o">.</span><span class="n">default_directory</span><span class="si">}</span><span class="s2">/*.yml&quot;</span><span class="p">),</span> <span class="o">[]</span>
		<span class="k">unless</span> <span class="n">files</span><span class="o">.</span><span class="n">blank?</span>
			<span class="n">files</span><span class="o">.</span><span class="n">each</span> <span class="p">{</span> <span class="o">|</span><span class="n">f</span><span class="o">|</span> <span class="n">names</span> <span class="o">&lt;&lt;</span> <span class="no">File</span><span class="o">.</span><span class="n">basename</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="s1">&#39;.yml&#39;</span><span class="p">)</span> <span class="p">}</span>
			<span class="n">names</span>
		<span class="k">else</span>
			<span class="o">[]</span>
		<span class="k">end</span>
	<span class="k">end</span>

<span class="k">end</span>
</pre>
</div><p>Basically the migration will look in a directory named &#8220;defaults&#8221; for some <span class="caps">YAML</span> files named after a particular database table, and it will attempt to load all the records defined in each one of them. <br />
The <code>down</code> method of the migration <em>deletes all the data in the specified tables</em>, so use with care&#8230;</p>]]>
    </content>
  </entry>
  <entry>
    <id>tag:www.h3rald.com,2007-07-14:/articles/simply-on-rails-2-database-design/</id>
    <title>Simply on Rails - Part 2: Database Design</title>
    <published>2007-07-14T09:27:00Z</published>
    <updated>2009-09-06T18:10:54Z</updated>
    <link href="http://www.h3rald.com/articles/simply-on-rails-2-database-design/" rel="alternate"/>
    <category term="rails" scheme="http://www.h3rald.com/tags/rails/"/>
    <category term="databases" scheme="http://www.h3rald.com/tags/databases/"/>
    <content type="html">
<![CDATA[
<p>This week I attended a course for work on how to <em>Implement Databases with Microsoft <span class="caps">SQL</span> Server 2005</em>. An interesting course indeed, which made me realize how feature-rich Bill&#8217;s product is, compared to the Open Source alternatives like MySQL. It also made me realize how nice it is to implement database-related logic (read: Models) using a <em>proper</em> programming language rather than using triggers, stored procedures, functions and other goodies offered by Transact-<span class="caps">SQL</span>.</p>
<p>It&#8217;s all a matter of taste and of necessities: using MS <span class="caps">SQL</span> Server for one of my website is simply not going to happen anytime soon, and I&#8217;m more than happy to have a database which can be used <em>just</em> as a database and a programming language (Ruby, in this case) which can do wonders, rather than a procedural-only surrogate.</p>
<p>Anyhow, back to our weekly series. After creating a <a href="/blog/simply-on-rails-1-concepts-map">concept map</a>, it&#8217;s time of <em>get real</em> and try to figure out a database architecture. The tool of choice this week is obviously the widely popular <a href="http://fabforce.net/dbdesigner4/">DbDesigner 4</a>. It&#8217;s free, it&#8217;s easy to use, and the results are pretty enough. There:</p>
<p><a href="/files/italysimply_database-architecture.png"><img src="/files/italysimply_database-architecture_thumb.png" alt="" /></a></p>
<p>It&#8217;s amazing how a relatively simple concept map can lead to such a complex database architecture, isn&#8217;t it?<br />
Well, it&#8217;s normal. One of the reasons of this is that I totally forgot about geographical information about the houses which will be featured on the site, or better, I thought about it as a <em>strings</em> typed in by the administrators, whereas it would be much better having dropdown boxes.</p>
<p>Countries, regions, privinces, areas and cities will be added to the database only once, rather than having to type them in every time a house is added. Obvious, but this lead to five tables more and nine (!) relationships more.</p>
<p>The other reason of why the number of tables is higher than the number of entities in the domain model is that I decided <em>not</em> to use the <span class="caps">ENUM</span> type. Firstly because <a href="http://wiki.rubyonrails.org/rails/pages/HowtoUseSetAndEnumColumns">it&#8217;s not handled very well by Rails</a><br />
 and also because there&#8217;s <a href="http://blog.arabx.com.au/?p=87">a number of reasons</a> why ENUMs should not be used.</p>
<p>The only problem now is that whenever I load a house, I&#8217;ll have to get data from a lot of tables at once (and this means a lot of joins underneath the model layer) or &#8211; worse &#8211; a lot of queries in case I decide to load related data &#8220;on the fly&#8221;. It looks like I&#8217;ll have to do a bit of <a href="http://railsexpress.de/blog/articles/2005/11/06/the-case-for-piggy-backed-attributes">piggy-backing</a> here and there. <a href="http://railsexpress.de/blog/articles/2006/05/29/simpler-piggy-backing">Someone</a> already thought about a way of doing this in a more &#8220;Model-friendly&#8221; way. Perhaps I&#8217;ll give it a shot.</p>]]>
    </content>
  </entry>
  <entry>
    <id>tag:www.h3rald.com,2006-04-17:/articles/16/</id>
    <title>Databases supported by CakePHP</title>
    <published>2006-04-17T05:30:00Z</published>
    <updated>2009-09-06T18:10:53Z</updated>
    <link href="http://www.h3rald.com/articles/16/" rel="alternate"/>
    <category term="cakephp" scheme="http://www.h3rald.com/tags/cakephp/"/>
    <category term="webdevelopment" scheme="http://www.h3rald.com/tags/webdevelopment/"/>
    <category term="databases" scheme="http://www.h3rald.com/tags/databases/"/>
    <content type="html">
<![CDATA[
<p>One of the most recurring questions on CakePHP User Group is probably <em>&#8220;Does Cake support X database?&#8221;</em>. Sure, most of us tend to use just MySQL for our websites and applications, but in certain situations some more <em>exotic</em> database support makes the difference. A partial answer to the question above could be <em>&#8220;Yes, probably, at least partially&#8221;</em>: CakePHP offers support for some database &#8220;natively&#8221; (i.e. Cake folks made some <em>ad hoc</em> database drivers), others through either <a href="http://adodb.sourceforge.net/">ADOdb</a> or <a href="http://pear.php.net/package/DB"><span class="caps">PEAR</span>::DB</a>.</p>
<p>CakePHP seems to use a <em>multiple level</em> database abstraction: in other words, popular abstraction layers like ADOdb or <span class="caps">PEAR</span>::DB have been wrapped in a &#8220;driver&#8221; which basically extends the DboSource class (which is the most high level database abstraction). Some people don&#8217;t like the idea, because this means that the could be some performance issues, for one, and also that inevitably not <em>all</em> features offered by either ADOdb or <span class="caps">PEAR</span>::DB are used. In my very, very, very modest opinion (I&#8217;m not an expert on this matter), this solution focus on achieving good database compatibility leaving the doors open for further tinkering, if needed.</p>
<p style="float:left;"><img src="http://base--/img/pictures/postgres.png" alt="" /></p>
<p>Having said this, yes, the possibilities are good that your favorite database is supported by CakePHP, more or less. Of course, as repeatedly pointed out by some CakePHP core developers, Cake dev team didn&#8217;t and is not going to test <em>every</em> database with Cake, using either of the two abstraction layers, but users are more than welcome to do so.</p>
<p>Let&#8217;s now have a look at what is <em>known to work</em> with Cake:</p>
<p><strong>MySQL</strong> works fine, and is currently recommended as <em>preferred</em> database solution. What about <strong>MySQLi</strong>? Well, thanks to mappleJoe there&#8217;s a (PHP5 only!) <a href="http://cakephp.org/pastes/show/770e73e77e4d7a3d32c2f3de3f175512">driver</a> ready to be used.</p>
*PostgreSQL*&#8217;s support is continuously improving. Something may work, something may not: the good news is that the folks who are using it are <a href="http://groups.google.com/group/cake-php/browse_thread/thread/85a29ab6ec6826a0/8eecea26ba53e1fd?q=postgres&amp;rnum=1#8eecea26ba53e1fd">sharing their thoughts</a> with the rest of us.
<p style="float:right;"><img src="http://base--/img/pictures/sqlite.gif" alt="" /></p>
<p><strong>SQLite</strong> is supported natively, or so it seems&#8230; what about the newest SQLite3? Yes, probably: there&#8217;s a quick <a href="http://www.thompsonlife.net/index.php?section=9">howto</a> on ThompsonLife.net to make it work through the dbo_pear driver.</p>
<p><strong>Access</strong> works through the ADOdb driver, as reported in CakePHP <a href="http://wiki.cakephp.org/docs:databases">wiki</a> (thanks ivanp).</p>
<p><a href="http://www.filemaker.com/">FileMaker</a> is getting there: things aren&#8217;t that easy, but bdb is doing <a href="http://groups.google.com/group/cake-php/browse_thread/thread/572d8dd2ba4cbdf7/dca851c795247c0b?q=database&amp;rnum=2#dca851c795247c0b">all his best</a> to make it work, good luck!</p>
<p>Neil Fincham was also trying to develop a custom driver to support <a href="http://www.pervasive.com/">Pervasive</a> through a <a href="http://www.unixodbc.org/">unixODBC</a> driver. Best of luck!</p>
<p>For other databases, check ADOdb&#8217;s <a href="http://phplens.com/adodb/supported.databases.html">list of supported databases</a> and use the <code>dbo-adodb</code> driver, or use <span class="caps">PEAR</span>::DB (for fbsql, ibase, informix, msql, mssql, mysql, mysqli, oci8, odbc, pgsql,sqlite and sybase) using the <code>dbo-pear</code> driver.</p>]]>
    </content>
  </entry>
  <entry>
    <id>tag:www.h3rald.com,2006-02-28:/articles/sqlyog5-review/</id>
    <title>SQLyog 5 - a fast and reliable MySQL front-end</title>
    <published>2006-02-28T12:50:00Z</published>
    <updated>2009-09-06T18:10:52Z</updated>
    <link href="http://www.h3rald.com/articles/sqlyog5-review/" rel="alternate"/>
    <category term="databases" scheme="http://www.h3rald.com/tags/databases/"/>
    <category term="review" scheme="http://www.h3rald.com/tags/review/"/>
    <content type="html">
<![CDATA[
MySQL[1] is a great database solution. Literally millions of people who use it can tell you that it is a well-performing, feature-rich database solution for almost any size project: it is low-cost (often free), and available on the majority of webservers all over the world. When I first discovered MySQL while learning some basic PHP programming, I almost immediately wondered how I'd effectively access MySQL and manage my databases other than through PHP code or command line. I was pointed to PHPMyAdmin[2], which I still use as a quick, general-purpose MySQL front-end. However, I wondered if there was anything better than that, and maybe not confined within a browser window...<br />
<br />
There are a few desktop "cousins" of PHPMyAdmin out there, especially for Windows, which is not surprising. After a quick search, three products come up immediately: MySQL-Front[3], Navicat MySQL[4] and SQLyog[5], all of them are proprietary solutions and seem to be the most popular ones around. <br />
<br />
<em>Alright, which one is the best?</em><br />
<br />
There are many different criteria available to choose a winner among these three products. The easiest for me was simply: "which one is free?"<br />
<br />
- SQLyog, with some restrictions, is our instant winner. Both MySQL-Front and Navicat MySQL offer a 30-day trial, while SQLyog can be free for life but only with basic features.  However, the number of basic features is considerable.<br />
<br />
<strong>First impressions</strong><br />
After launching SQLyog (free edition), a small and not-too-annoying nag screen appears: you click on it and it goes away, it doesn't last for 10 seconds like some others. The same screen appears when you try to access the power tools and advanced features which are not included in the free edition.  I got used to it after a short while, and that's the only annoyance of the free version of the product. <br />
<br />
The program's interface seems a bit unconventional for the traditional Windows user, especially if compared to the other two products. The main window is divided into four parts: the main menu and a navigation bar underneath it, a left column listing all the databases and tables in an expandable tree, the top half of the main window which hosts a SQL editor, and the lower half with everything else, including a tabbed area for displaying query results, messages, table data, table structure and history.<br />
<br />
It seems as if the SQL editor should be in a tab as well, but after using SQLYog for a while, you understand why is not: the editor has been positioned such that it can be used often, easily, and immediately. It took me a while to figure this out, but once you embrace this philosophy, you'll never stop using this program; all front-ends include a query editor, but it's often relatively hidden, meaning that it is at least one or two clicks away from the rest of the interface.<br />
<br />
<br />
<strong>Main Features</strong><br />
After specifying your credentials, the program will connect to the MySQL server and list all of the available databases in an Explorer-like left side panel. All tables can be accessed by clicking once on the corresponding database. All column fields, indexes and triggers (if any) are displayed by clicking on each table name.<br />
<br />
<em>So when I click on a database or a table the corresponding structure is displayed, right?</em><br />
<br />
Wrong. When you do that, nothing happens.  Remember the multi-tabbed lower panel, which is supposed to display results, table data, objects, etc.? Well, the focus is set to the <em>Result</em> column by default, so if you want to display the database or table structure you need to click on the <em>Objects</em> table, and voilï¿½ , the structure appears. Fortunately this behaviour can be changed by  modifying the program's options, through the Tools menu.<br />
 <br />
Clicking on <em>Table data</em> will display the first 50 records of the selected table, while the <em>Result</em> and <em>Messages</em> tabs will still be empty; the editor wasn't used, so there's no result to show, and we didn't get any errors or other messages from MySQL yet, so everything is as it should be.<br />
<br />
The most interesting feature from an educational point of view, so far, is actually the <em>History</em> tab, which is just one click away and shows the following:<br />
<br />
<code><br />
/*[11:11:11 AM][   0 ms]*/ show variables like '%character%'<br />
/*[11:11:11 AM][   0 ms]*/ Set character_set_connection=latin1<br />
/*[11:11:11 AM][   0 ms]*/ Set character_set_results=latin1<br />
/*[11:11:11 AM][   0 ms]*/ Set character_set_client=latin1<br />
/*[11:11:11 AM][   0 ms]*/ set sql_mode=''<br />
/*[11:11:11 AM][  15 ms]*/ show databases<br />
/*[11:11:22 AM][   0 ms]*/ use `zzine_drupal`<br />
/*[11:11:23 AM][ 203 ms]*/ select `TABLE_NAME` from `INFORMATION_SCHEMA`.`TABLES` <br />
                           where `TABLE_SCHEMA` = 'zzine_drupal' and `TABLE_TYPE` = 'BASE TABLE'<br />
/*[11:11:32 AM][  47 ms]*/ show full fields from `zzine_drupal`.`node`<br />
/*[11:11:32 AM][ 140 ms]*/ show keys from `zzine_drupal`.`node`<br />
/*[11:11:32 AM][   0 ms]*/ select * from `zzine_drupal`.`node` limit 0, 50<br />
</code><br />
<br />
The above is a log of all the SQL commands which were sent to the server so far: the program connected and showed all the databases, I clicked on the "zzine_drupal" database, got some info about it, and then clicked on the <em>node</em> table and displayed the first 50 records. So, if you are new to SQL and want to learn the syntax to query the database you can just have a glance at this tab every so often.<br />
<br />
Note that the time to execute a query is displayed in ms, and it's not wrong! SQLyog actually performs quite well, as boasted on the official site's features page[6]: <em>"[it] uses native MySQL C API - the fastest way to communicate with MySQL server"</em> - and they do mean it.<br />
<br />
<em>What else does SQLYog offer?</em><br />
<br />
 The free version includes the most used features, like the very two most basic operations: you can query the database by typing an SQL query into the editor and executing it (F5 or F8 if you want to edit the results) and change the value of each field through a convenient blob editor, which can display text or images, import content from a file or save it locally.<br />
Then the program groups all functionalities in standard dropdown menus on the top bar, and also presents the most used operations as clickable icons as well. Now, this can be handy, but the program displays 25+ icons without any text underneath, so either you keep hovering your mouse on each one waiting for an explanation message to appear, or you just use the standard dropdown menus anyway. The authors did an outstanding job creating an icon for (literally) every action: they are quite well made and explanatory enough if you look at them carefully, but they are still very similar, and too numerous to memorize.<br />
<br />
However, SQLyog is also 100% keyboard friendly, as almost every function has a shortcut. Memorizing just a few of them, and it's worthwhile, as it makes everything much faster.  At any rate it's better than memorizing all the icons instead!<br />
<br />
Let's examine each dropdown menu and the functions listed in them.<br />
<br />
<em><u>File</u></em><br />
This menu lists all the functions concerning database connection and disconnection, opening and saving SQL files, and opening new query tabs - the SQL editor panel can have multiple tabs.<br />
<br />
<em><u>Edit</u></em><br />
This menu refers to the SQL editor, not to the query results! It includes functions like execute queries, copy, paste, cut, undo, redo and find/replace, which does not find strings in a record/table/database, but only in the SQL editor. I do believe the "Find in Database" function is missing in SQLyog, and is present in some of the competitors, but you can search your database using the appropriate SQL queries, right? Maybe - in my opinion - an advanced <em>Find &lt;something&gt; in &lt;somewhere&gt;</em> wizard or dialogue should be implemented - as the developers seem to be very good at creating those types of things, we'll soon find out.<br />
<br />
<em><u>DB</u></em><br />
Maybe I'd have called this "database" for the sake of newbies, but this menu indeed groups all database-related functionalities together. Create/truncate/drop databases, create table and create view (maybe they could have been placed under the <em>table</em> menu), and other interesting features like creating an HTML schema on the database and even copying a whole database (or just a few tables) to a different host (even remote, if accessible) with a single click! It works, just don't try to copy a database onto another remote server on a 56K dialup connection, like I did...<br />
<br />
<br />
<em><u>Tables</u></em><br />
Another self-explanatory menu, listing all table-related operations like create, alter, rename, empty, drop, import, export tables, manage indexes, rearrange columns, etc. All these functions can be performed through wizards, dialogues or other equally simple methods that any average Windows user should be familiar with. There are only a few exception here and in other menus: when wizards would be inappropriate or inadequate for certain actions, SQLyog prepares a "template query" and lets the user fill it in, typically for more advanced needs, such as if you want to create a new (MySQL 5.0+ only) <em>trigger</em> named <em>test[i] on the [i]node</em> table of the aforementioned zzine_drupal database.  For this, SQLyog prepares the following query template: <br />
<br />
<code><br />
DELIMITER $$;<br />
<br />
DROP TRIGGER `zzine_drupal`.`test`$$<br />
<br />
CREATE TRIGGER `zzine_drupal`.`test` BEFORE/AFTER INSERT/UPDATE/DELETE on `zzine_drupal`.`node`<br />
FOR EACH ROW BEGIN<br />
<br />
END$$<br />
<br />
DELIMITER ;$$<br />
</code> <br />
<br />
...just remember to modify it according to your needs!<br />
Do you like SQLyog's query templates? Check out Edit-&gt;Insert Templates and there's almost everything for every taste.<br />
<br />
<br />
<em><u>Objects</u></em><br />
Presumably the authors created this menu to group some advanced or new functionalities together, but everything listed here is already present in one of the other menus: management of functions and triggers, view-related actions, and stored procedures... except for the <em>Drop Column</em> action, which is only available under this menu.<br />
<br />
<em><u>Tools</u></em><br />
This menu also lists two actions which we already saw under the <em>DB</em> menu, which is exporting or importing a database.  however, there is also an <em>Export resultset</em> wizard, as well as a very handy user management tool, information about the current database, and the program preferences.<br />
<br />
The program preferences apparently have two settings which perhaps should be changed by default, which concern the previously mentioned weird tab focus: if you'd like something more intuitive and you don't need (or want) to use the SQL editor a lot, you can safely unclick the "Keep focus on SQL Editor after query execution" and click the "Always select Objects tab when a new item is selected".<br />
<br />
Believe it or not, you get all this for free. No charge, no trial periods: these are the actual features offered by the free edition of SQLyog! No surprise that over 500,000 people already downloaded it!<br />
<br />
What's in the <em>Professional</em> and in the <em>Enterprise</em> edition then? Nothing much, and <em>Power tools</em>.<br />
<br />
<br />
<strong>"Power Tools"</strong><br />
When I wrote <em>nothing much</em> earlier I actually referred to the Professional Edition, which - as the feature matrix shows[8]- doesn't offer anything more than the free edition: basically you pay $9 to get rid of the nag screens, which are normally not very intrusive...<br />
<br />
<em><u>Tunneling</u></em><br />
On the contrary, the Enterprise Edition ($49) has a lot of very interesting advanced tools which are actually worthwhile to have. Perhaps the most essential feature missing in the free version, especially for people using a remote hosting solution, is <em>tunnelling</em>. You can use SQLyog to connect to a remote server, theoretically; in reality though, in order to do so your hosting provider must allow privileged remote connections to the database (i.e. &lt;user&gt;@% instead of &lt;user&gt;@localhost), which is not permitted 98% of the time for security reasons. So how can you use SQLyog to access your remote database(s)? With tunneling.<br />
The concept is simple: even if privileged remote connections are normally not permitted, privileged local connections are. So all you need to do is place a PHP script on your server, somewhere accessible, and specify it as a parameter for HTTP tunneling before establishing the connection; SQLyog will then access the script and the script will basically forward SQLyog's instruction to the database server, just as if the commands were issued locally. <br />
<br />
<em>I will never allow commands to be sent to my server unencrypted and through a PHP script, which can be exploited by the first script-kiddie passing by!</em><br />
<br />
This is a common, slightly biased, but ultimately reasonable concern, and for $49 you can also get SSH tunneling, provided that your host allows you to connect to the server through a SSH shell. I tried this option and it worked perfectly: with a 2MB/s ADSL connection all went smoothly and fast: the program proved to be a valid alternative to PHPMyAdmin in terms of speed and responsiveness. <br />
Do not try this on a 56K connection!  It's not worthwhile, and probably not even conceived of by the developers. As I always want to try extreme solutions, I also tried SSH tunneling on dialup and my final conclusion was: <em>stick with PHPMyAdmin</em>. SQLyog seems to have been developed in order to achieve relatively immediate responses, as a result, when a low speed connection is used to connect to a remote database, the program may hang for a little while before delivering results and executing queries as normal. Perhaps there's room for improvement here: it would be great to have progress bars display when an operation takes more time than normal.<br />
<br />
<em><u>Database Synchronization and Migration</u></em><br />
A common and useful feature you should expect from a MySQL front-end is a synchronization utility, and SQLyog has one: by clicking on <em>Database Synchronization</em> under the Powertools menu you can start a quick and easy synchronization wizard, to automatically update two databases. Simply provide the connection details (even if they are on different hosts or require tunneling), and select the databases you want to synchronize, also specifying if you want a two-way synchronization or only one way.  A similar function is <em>structure synchronization</em>, which can be used to keep only the structure (not the data) up-to-date between two databases. You won't be asked to create two new connections, but the operation can only be performed on databases that are already accessed by SQLyog.<br />
<br />
For more information on how to take advantage of SQLyog's advanced synchronization features, I recommend reading a very informative article specifically devoted to this subject, available online[8].<br />
<br />
Another VERY interesting features SQLyog offers (which has been the subject of a whole article on DatabaseJournal.com[9]) is the possibility to easily migrate to MySQL from other ODBC sources. Through a relatively painless wizard it is possible to migrate from another database type to MySQL, while making sure that any errors are handled as expected.<br />
<br />
<em><u>Periodic Tasks and Management</u></em>  <br />
MySQL is a wonderful relational database, but it fundamentally lacks the ability to execute scheduled queries and operations, which are normally accomplished by server-side scripts. SQLyog offers you the opportunity to easily create and administer periodic tasks, notifications and backups via a few wizards: the <em>Notification Services</em> wizard, which can be used to send the result of a particular user-defined periodic query to an email address or execute maintenance queries, and the <em>Scheduled Backups</em> wizard to automate full or partial database backups and exports.  Webyog[10] itself offers an informative how-to[10] on these tasks, step-by-step with screenshots.  Last but not least, you can manage all these scheduled jobs through a very handy <em>job manager</em> located in the <em>Powertools</em> menu.<br />
<br />
<br />
<strong>Final Judgement</strong><br />
SQLyog is a well-rounded, multi-functional front-end for MySQL which can be used by both newbies and more experienced users to manage their databases. I'd clean up and reorganize the interface a little bit and remove a lot of the icons as well as list all the functions under the top menus, possibly <em>without</em> the icons and without repeating the same function anywhere.<br />
<br />
Apart from those small items, SQLyog is definitely worth a shot, and the Webyog team definitely did a good job in this fifth version by incorporating all the latest MySQL 5 functionalities in an already excellent program. The free version in particular offers quite a wide range of functionalities with no trial period, and this certainly helped the program to grow in popularity.  I would never buy the Professional edition, simply because it only gets rid of nag screens without offering nothing new over and above the Free Edition.  On the other hand, the Enterprise Edition is an excellent and inexpensive solution if you need the power tools.<br />
<br />
SQLyog is just a few clicks away[11], only 7 Megabytes, and ready to install! <br />
<br />
<br />
<strong>Notes</strong><br />
[small][1]MySQL - Official Site: <a href="http://www.mysql.com/">http://www.mysql.com/</a> <br />
[2]PHPMyAdmin - Official Site: <a href="http://www.phpmyadmin.net/home_page/index.php">http://www.phpmyadmin.net/home_page/index.php</a><br />
[3]MySQL-Front: <a href="http://www.mysqlfront.de/">http://www.mysqlfront.de/</a><br />
[4]Navicat MySQL: <a href="http://www.navicat.com/">http://www.navicat.com/</a><br />
[5]Webyog Website: <a href="http://www.webyog.com/">http://www.webyog.com/</a><br />
[6]SQLyog, feature page: <a href="http://www.webyog.com/sqlyog/index.php ">http://www.webyog.com/sqlyog/index.php </a><br />
[7]SQLyog, features matrix: <a href="http://www.webyog.com/sqlyog/featurematrix.html">http://www.webyog.com/sqlyog/featurematrix.html</a><br />
[8] Peter Laursen &amp; Quy Ton,  "Using SQLyog Enterprise to Effectively Synchronize MySQL Databases" (PDF):<br />
<a href="http://www.webyog.com/articles/Using_SQLyog_Enterprise_to_Effectively_Synchronize_MySQL_Databases.pdf">http://www.webyog.com/articles/Using_SQLyog_Enterprise_to_Effectively_Synchronize_MySQL_Databases.pdf</a><br />
[9] Peter Laursen, "Migration to MySQL with SQLyog ver 4.1" : <a href="http://www.databasejournal.com/features/mysql/article.php/10897_3550146">http://www.databasejournal.com/features/mysql/article.php/10897_3550146</a><br />
[10]Webyog, "How to use Scheduled Backups with SQLyog": <a href="http://www.webyog.com/articles/how_to_use_scheduled_backup.html">http://www.webyog.com/articles/how_to_use_scheduled_backup.html</a><br />
[/small]]]>
    </content>
  </entry>
  <entry>
    <id>tag:www.h3rald.com,2005-11-25:/articles/quick-overview-of-sqlite/</id>
    <title>A Quick Overview of SQLite</title>
    <published>2005-11-25T16:52:38Z</published>
    <updated>2009-09-06T18:10:51Z</updated>
    <link href="http://www.h3rald.com/articles/quick-overview-of-sqlite/" rel="alternate"/>
    <category term="review" scheme="http://www.h3rald.com/tags/review/"/>
    <category term="databases" scheme="http://www.h3rald.com/tags/databases/"/>
    <content type="html">
<![CDATA[
A few months ago, my old hosting company started having problems with their servers. The servers would go down unexpectedly for 5-10 minutes on a relatively frequent basis, but for some weird reason... the MySQL databases were unusable for a couple of hours afterwards every time. "We had problems with MySQL, BUT the server was up, so we're still within the 99% uptime guarantee"... At the time I was thinking: "If only MySQL databases behaved like plain files..." <br />
<br />
<strong>What is SQLite?</strong><br />
<br />
When PHP5 was first released, I discovered SQLite: <em>"...a small C library that implements a self-contained, embeddable, zero-configuration SQL database engine"</em> (as quoted from the <a href="http://www.sqlite.org">official site</a>). PHP5 offers native support to this little wonder, whose development actually started long before PHP5 was released, and can be used with many, many other programming languages.<br />
 <br />
SQLite organizes each database in a .db file, and implements most of the SQL 92 standards, to access the databases with no need of a server process running at the same time. Access is accomplished through standard reading/writing file operations.<br />
<br />
Let's examine the pros and cons of using SQLite in your web applications.<br />
<br />
<strong>Features</strong><br />
<br />
- SQLite is FREE &amp;quot;for any purpose&amp;quot;, <a href="http://www.sqlite.org/copyright.html">they say</a>.<br />
- It doesn't rely on a server process to run<br />
- You don't need to spend time configuring your installation, because there's nothing to configure!<br />
- As there's no client-server negotiation, accesses to the database are much faster (2-3 times faster than a MySQL database)<br />
<br />
As a consequence of all this, there's actually no concept of &amp;quot;users&amp;quot; allowed to access the database; as I said, the actual data of each database is stored into a single file, and as such, it has permissions which regulate access. If a script has read or write access to the file, a read/write sql instruction can be executed on the database. You can therefore simply protect your databases as you would protect any other file on your server.<br />
<br />
- SQLite is small: the library is just 250KB, and takes care of everything, you don't need any other library or program to use it.<br />
- SQLite can handle files up to 2 terabytes in size.<br />
- SQLite implements most of the SQL 92 standard. This means you can usually use standard and well known queries to access it (with some exceptions, discussed in the next section).<br />
- SQLite does not enforce datatype constraints. Is this a feature or a bug? Well, they call it a feature, but others may not agree. As a matter of fact, you can put a string into a field marked  &amp;quot;integer&amp;quot; and vice versa, and furthermore, the string can be as big as you like!  There's one exception to this rule, though.  Columns marked as PRIMARY KEY must be of integer type. <br />
<br />
<br />
<strong>Limitations</strong><br />
Now that you have read all of the preceding material, and know that PHP5 supports SQLite natively, you might be thinking about putting MySQL in the bin and using SQLite for everything instead: it's smaller, faster, portable, simpler, and headache-free... it's love at first sight. Right?<br />
<br />
Well, the developers themselves decided to devote <a href="http://www.sqlite.org/whentouse.html">a page</a> to discuss when you should use SQLite and where you'd be better off sticking with your &amp;quot;old&amp;quot; database engine. Furthermore, being such a small and powerful piece of code, SQLite comes with some limitations which should be considered before starting to use it in a project:<br />
<br />
- Not all SQL queries and syntax are supported. For a full list, have a look <a href="http://www.sqlite.org/omitted.html">here</a>. The most notable things you'll miss in SQLite are: the inability (for now) to &amp;quot;ALTER TABLE&amp;quot; (you do this, they say, by creating a new modified table and deleting the old one), no VIEW, and no CHECK or FOREIGN KEY constraints (they are &amp;quot;parsed but not enforced&amp;quot;).<br />
<br />
- Syntax can be different sometimes. I noticed that, for example, in a JOIN between two or more tables, when accessing columns you ALWAYS have to specify &amp;lt;table&amp;gt;.&amp;lt;column&amp;gt;, whereas MySQL doesn't complain if there's ambiguity.<br />
<br />
- SQLite is not suitable for projects which requires a lot of semi-simultaneous writing operations. SQLite uses reader/writer locks: if there's someone reading from the database, writing to it is not allowed. This basically mean that multiple simultaneous read operations (SELECT x FROM ...) have higher priority than write operations (INSERT, UPDATE, ...), which are therefore delayed. <br />
<br />
- Do not use SQLite for big databases. Even though I said that (theoretically) databases up to 2 terabytes are supported, when your database is more than 1 GB, SQLite requires too much memory to run (256 bytes of RAM for each MB of database space, they say).<br />
<br />
- Generally, if your website gets lots of traffic, SQLite shouldn't be your primary database engine, for the issues mentioned above. php.net uses SQLite for its site, but only on certain parts of it. If you get fewer than 100,000 hits/day, SQLite should work fine - they say. So basically I can use for any site I make...<br />
<br />
<br />
<strong>Conclusions</strong><br />
Considering all features and limitations, SQLite is an excellent solution for small or medium websites, embedded applications, programs which only need a small database to function and shouldn't be bound to a server, temporary databases, testing, and the like. Always keep in mind that you're working with files, so keep them protected wherever you put them in your server (a connection is established simply by specifying the path to the file).<br />
<br />
Last but not least, if you're used to phpMyAdmin for administering your MySQL databases, there are similar tools for SQLite, such as <a href="http://www.sqlitemanager.org">sqlitemanager</a>.]]>
    </content>
  </entry>
  <entry>
    <id>tag:www.h3rald.com,2005-06-28:/articles/server-packages/</id>
    <title>Easy-to-install server packages</title>
    <published>2005-06-28T20:12:19Z</published>
    <updated>2009-09-06T18:10:50Z</updated>
    <link href="http://www.h3rald.com/articles/server-packages/" rel="alternate"/>
    <category term="review" scheme="http://www.h3rald.com/tags/review/"/>
    <category term="webdevelopment" scheme="http://www.h3rald.com/tags/webdevelopment/"/>
    <category term="php" scheme="http://www.h3rald.com/tags/php/"/>
    <category term="databases" scheme="http://www.h3rald.com/tags/databases/"/>
    <content type="html">
<![CDATA[
The first and most obvious difference between, say, a C++ programmer and a PHP developer is that the PHP developer needs a server with PHP support up and running somewhere in order to "show" others that the application is working. This normally means that a PHP developer must either have remote access to a server, or have one set up on his machine. Installing and configuring a server can be tricky sometimes, especially if you want to configure it "properly", but in some cases - for Linux/BSD users mainly - there are some pre-configured servers you can download and install. <br />
<br />
I won't examine all these methods in this article, but I'll describe three alternatives for installing and run a webserver on windows in 10 minutes or less.<br />
<br />
<strong>Preliminary considerations</strong><br />
Let's assume that you just want to have a server set up on your computer for <em>internal use</em> only, for testing purposes. That means that you wouldn't need to be concerned about "security" or similar issues - you just want to be able to run your PHP scripts and access your database(s) quickly and easily. <br />
<br />
As I said earlier, Linux users would probably opt for some package available for their favourite distros - they would only have to download and install an .rpm or .deb package for (presumably) Apache httpd, PHP and MySQL, and just use a basic configuration. There are other tools around which can help if you want to compile or configure Apache, but that is beyond the scope of this article.<br />
<br />
Let's just focus on Windows users, then. Normally they like things that are easy to install and can be configured in a few minutes <em>maximum</em> or not at all. Finally, let's assume that as a Windows user, you don't want to spend more money for a new operating system with a bundled server, like Windows 2003, because you can use <a href="http://www.apache.org">Apache</a> on Windows as well, for free.   Having said this, I actually found 3 possible solutions that are handy for PHP (or Perl) developers who don't want to spend time learning how to configure a server. There are people like that, including myself to some extent.<br />
<br />
<br />
<strong>WAMPserver</strong><br />
<a href="http://www.wampserver.com">WAMP</a> stands for "Windows Apache MySQL PHP", and I must say that this product happens to be my choice. The current version, available at the time of writing, offers:<br />
<br />
- PHP 5.0.4<br />
- Apache 1.3.33<br />
- MySQL 4.1.10a<br />
- phpMyadmin 2.6.1-pl3<br />
- SQLitemanager 1.0.4<br />
<br />
This is basically a fully working PHP5 environment, with other tools like phpMyadmin to administer your MySQL database even more easily (more laziness!), and, if you're into the new functionalities of PHP5, it also comes with sqlitemanager, a php application similar to phpMyAdmin but for sqlite databases, which are supported by default in PHP5.<br />
You download it, you start the installation program, and it's DONE. That's it. In 5 minutes you have your own little apache/php/mysql(ite) environment up and running and you can start showing off your sites to your friends and co-workers right away.<br />
<br />
The program also installs two services which can be run at startup, a little icon in the system tray to access all the tools and, of course, <a href="http://localhost">http://localhost</a> in your favourite browser.<br />
<br />
If all this is still not enough for you, and you want more things more easily, you can install addons to set up PHP4 (and seamlessly switch between the two with a single click!), Perl, Zend Accelerator, and so forth.<br />
<br />
<br />
<strong>EasyPHP</strong><br />
The second suite I will briefly describe is <a href="http://www.easyphp.org">EasyPHP</a>. This is a French project (like the previous one, actually), which offers PHP4, MySQL and Apache, plus phpMyAdmin to administer the MySQL databases. However, it doesn't offer PHP5 support yet (so it's not my favourite) and thus there's no sqlite support either.<br />
<br />
Apart from that, it works exactly like WAMP: you download it, you install it, and it's done. Services are installed and you have - again - your little icon on the system tray to access all its functions and tools. It works well, but it doesn't seem to have any add-ons available like WAMP does.<br />
<br />
<strong>XAMPP</strong><br />
This is by far the most complete distribution of the three I am focusing on. This project is developed by <a href="http://www.apachefriends.org">Apache Friends</a> and has a lot of features and flavours. XAMPP currently includes:<br />
<br />
- Apache HTTPD 2.0.54<br />
- MySQL 4.1.12<br />
- PHP 5.0.4 + 4.3.11 + PEAR + Switch<br />
- MiniPerl 5.8.6<br />
- Openssl 0.9.7g<br />
- PHPMyAdmin 2.6.2-pl1<br />
- XAMPP Control Panel 1.0<br />
- eAccelerator 0.9.3<br />
- Webalizer 2.01-10<br />
- Mercury Mail Transport System for Win32 and NetWare Systems v4.01a<br />
- FileZilla FTP Server 0.9.8a<br />
- SQLite 2.8.15<br />
- ADODB 4.63<br />
- Zend Optimizer 2.5.7<br />
- XAMPP Security for Windows 98, 2000, XP<br />
<br />
Honestly, you can't ask for more! If by chance you want to run this suite on other platforms, there's a version for Mac OS X, Solaris, and even Linux.<br />
<br />
The installation method for XAMPP is slightly more difficult than the other suites - you actually have to download and unzip it in a folder of your choice. Then you're off and running.<br />
<br />
Unfortunately (or fortunately), there's no icon on the system tray, so you need to actually access <a href="http://localhost">http://localhost</a> to get a list of services and tools. It also doesn't come with sqlitemanager, but you can download it and install it in the documents folder (like I did).<br />
<br />
I actually use XAMPP - the "lite" edition, which is smaller and has less features - for my USB drive. Since it doesn't require any services to be installed in order to run, you can simply copy it onto a USB stick and run it from there!<br />
<br />
<strong>Conclusion</strong><br />
I'm quite impressed by all of the server packages I reviewed; WAMP and XAMPP in particular. I can now carry around my websites and applications and instantly run them or show them to anyone who has a computer with a USB port.<br />
<br />
As I said in the beginning, these programs are NOT meant to be used in a production environment or to be accessed publicly, therefore, security is not a consideration here. In my opinion, they are simply excellent for testing purposes, and for now, that's what I need them for.]]>
    </content>
  </entry>
</feed>
