Showing posts with label Databases. Show all posts
Showing posts with label Databases. Show all posts

Thursday, February 15, 2007

Useful web design/development videos

A few days ago I found a nice and very useful resource for anyone who has to do with web design or web development. The main content is a series of videos (offered for free by the author) centered around four main topics: CSS, JavaScript, PHP and MySQL. There are very easy to watch and practice lessons and if you are interested in this topics you will not waste your time. Here are the links and my "ratings":

CSS
CSS DIV-Layouts - USEFUL & MUST KNOW THIS
Cascading Style Sheets - Part I - USEFUL
Cascading Style Sheets - Part II - USEFUL
CSS “Absolute” and “Relative” Positioning - VERY USEFUL
Rounded Corners with CSS - USEFUL & POPULAR

PHP
PHP Basics - MUST KNOW THIS
PHP Conditional Statements - MUST KNOW THIS
PHP Custom Functions - MUST KNOW THIS
PHP and Arrays - MUST KNOW THIS
PHP Pagination - MUST KNOW THIS
Inserting MySQL Data with PHP - USEFUL
Query MySQL From PHP - Part 1 - MUST KNOW THIS
Query MySQL From PHP - Part 2 - MUST KNOW THIS
Query MySQL From PHP - Part 3 - USEFUL
Using Cookies in PHP - USEFUL
PHP “Include” and “Require” - MUST KNOW THIS
PHP Objects & Classes - Part I - USEFUL
PHP Objects & Classes - Part II - USEFUL & OOP KNOWLEDGE NEEDED
PHP Objects & Classes - Part III - USEFUL & OOP KNOWLEDGE NEEDED

JavaScript
Home-made Javascript WYSIWYG - I DON'T KNOW
JavaScript Voting Stars - NICE & POPULAR

Saturday, February 3, 2007

MySQL client startup options

MySQL client comes with an large number of startup options, some of which are extremely useful in daily MySQL interaction.

--compress
This option compresses the upstream and downstream data packets transferred between the client and server, assuming both ends of the connection support such compression. Use this option to improve performance when communication bandwidth is limited -- for example, over a slow network link.

--debug
This option forces MySQL to write debugging data to a special log file, both at startup and shutdown and when processing transactions. It can be usefully combined with the --debug-info option for additional debugging information. Use this option to obtain detailed diagnostic information on MySQL, particularly when working with an experimental server or client.

--force
This option forces MySQL to continue processing a block of SQL commands even if an error occurred. Use this option during an automated installation/de-installation routine -- for example, when you're attempting to bulk-inject records into a database as part of application initialization and don't want duplicate entries to disrupt the process.

--pager
This option pipes the output of MySQL queries to an external "pager" program such as cat, less or more. Use this option when your query returns a large result set and you wish to interactively page through it screen by screen.

--xml
This option formats the result of your MySQL queries as well-formed XML. Use this option when you wish to package the output of your queries in a standard format, usually as a prelude to integrating it with a third-party application.

--one-database
This option tells the MySQL client to ignore all commands except those related to the database named in the option. Use this option to filter out actions pertaining to a single database from an SQL injection file, or to skip certain database updates.

--tee
This option lets you log all query output to an external file. Use this option when you need a record of your transactions, either for later reference or to maintain an audit trail.

--wait
Normally, the MySQL client will automatically abort if unable to connect to the server. This option forces it to wait for a defined interval and then try again. Use this option to cut down on keystrokes when attempting to contact a remote or non-responsive MySQL server.

--safe-updates
This option tells MySQL to ignore all unqualified DML commands -- that is, commands that do not contain filter criteria such as WHERE, LIMIT or HAVING clauses. This provides a safety net against accidental modification or deletion of complete tables or databases. Use this option when you want to automatically protect yourself from dangerous queries that could cause widespread data corruption or loss.

--prompt
This option allows you to alter the standard mysql> command prompt using various pre-defined format specifiers. Use this option to make your MySQL client print useful navigation or temporal information during your MySQL session -- for example, the current date or time, server statistics or your location in the database/table hierarchy.

Friday, February 2, 2007

Using SQLite as a database backend for a lightweight server

At home I use an rather old (antique some may say) computer (PII@350, 256RAM) as a web server and for testing purposes. All went fine until one of the pages hosted was hit by the "digg effect" and about 15 users wanted to see that page every second. The main problem was that I used MySQL to store some access logs and generate some real-time statistics. Physical memory was limited and Apache and MySQL soon started to fight for every remaining byte and eventually the page was unavailable.
After this experience I started to look for a alternative for the database storage and I found an interesting one: SQLite. SQLite is a small C library that implements a self-contained, embeddable, zero-configuration SQL database engine. Here are some features you may find interesting:

  • Transactions are atomic, consistent, isolated, and durable (ACID) even after system crashes and power failures.
  • Zero-configuration - no setup or administration needed.
  • Implements most of SQL92. (Features not supported)
  • A complete database is stored in a single disk file.
  • Simple, easy to use API.
  • Sources are in the public domain.
The next step was to make it work with my server setup (Apache and PHP5) and it was easy. To test it's relative performance to MySQL I implemented a simple scenario using both database engines: a page that logs each access (IP, DATETIME), looks for current user location (using a ip2country table of about 50.000 rows) and then shows some real time statistics (unique visitors and visitors grouped by country). Then I measured the average load time for this page using 5 concurrent user connections over a 10 minutes period. Here are the results (keep in mind that using SQLite saved about 80 to 128 MB of physical memory which can now be used by Apache or by the operating system):

SQLite is here a bit faster than MySQL using INNODB and both are a lot slower than MySQL/MYISAM. The main advantage of SQLite and INNODB is that you can use ACID transactions. I found SQLite being a good replacement for MySQL in most of my personal projects but before you start using it you should know the situations where SQLite works well and where it doesn't.