MySQL: Learn by Examples

Often times we need reference to a real working example to understand the actual technical documentation. Just trying to put together useful SQL queries that are working and tested against MySQL 5.0 database.

Update part of the column value that matches the given String

column value (pre-update): Apt # 1234

update <tablename> set <column>=replace(<column>, [...]

Password Protecting Your Pages with htaccess

Simple steps to password protect your pages with htaccess

Step-1: Make sure that “mod_rewrite”  extension of apache is enabled. If it’s already enabled, skip this step.

Step-2: Create a “.htaccess” file in the web root  folder. If “.htaccess” file is already exists, skip this step also.

Step-3: Add following code to the “.htaccess” file.

Implementing Sequences in MySQL

One of the major issues developers face while using MySQL database is sequences. Oracle has inherent support for sequences and getting a sequence is as easy as executing a one liner SQL.

select seq_name.nextval from dual;

However, since MySQL database does not support sequences, most oracle developers find it quite tricky to implement a custom [...]

Selecting the Right Mysql Engine

When You designing MySQL based applications, You should decide which engine to use for storing your data. If you don’t think about it during the design phase, you are likely to face complications later in the process.

MyISAM, InnoDB, BDB and HEAP are the most common and popular storage engines. All have some advantages and [...]

How to create a virtual host

Three quick and simple steps to set up a virtual host:

Step-1: Open the apache conf file. Location of this depends upon the location of your server. Possible location of this file is “/etc/httpd/conf/httpd.conf” or “/etc/apache2/httpd.conf”.

Step-2: Add following settings:

<VirtualHost IP Address:Port(80)> DocumentRoot location of your side root ServerName host name ServerAlias *.host name [...]

Select Custom Column using Propel in Symfony

Sample code to fetch custom columns using propel into symfony

$c = new Criteria(); $c->clearSelectColumns(); $c->addSelectColumn(JokePeer::VOTE); $jokes = array(); $rs = JokePeer::doSelectStmt($c); while ($row = $rs->fetch()){ $joke = new Joke(); $joke-> hydrate($row) ; // hydrate is function that populate data into Object.$jokes[] = $joke; }

This sample code works only with propel 1.3. Use doSelectRS() [...]

How to Create a Cron file into Symfony

Steps to create a cron file with symfony database settings–

Create a Folder batch. Create your cron script file. Add following code on starting of your script. require_once(dirname(__FILE__).’/../config/ProjectConfiguration.class.php’); $configuration=ProjectConfiguration::getApplicationConfiguration(‘frontend’,'prod’,true); sfContext::createInstance($configuration);

The “frontend” is your application.

The script enables you to use all application settings and access all the peer files.