Recent Postings

Recent Comments


RSS2 feed


Most Popular Posts

Archive for May 2007

MySQL equivalent of PATINDEX

Thursday, 31st May 2007 1:17pm
One of the Transact-SQL expressions that I use quite often in SQL Server is PATINDEX which I use to find the starting position of the first occurrence of a pattern in a specified expression.

To find the starting position of say pattern 'ev' in 'web development' just as an example, you would use:

SELECT PATINDEX('%ev%', 'web development')

In MySQL you have a choice of two functions to use, POSITION and LOCATE. Using POSITION in MySQL the above example would be :

SELECT POSITION('ev' IN 'web development');

I think LOCATE is a better function because it allows you to specify an optional starting position to begin the search and also because its usage is similar to the T-SQL equivalent.
Using LOCATE without specifying the starting position above example would like this:

SELECT LOCATE('ev', 'web development');

and specifying a starting point of say 4 as an example:

SELECT LOCATE('ev', 'web development', 4);

delicious delicious | digg digg

Category: MySQL | Comments : 3

MySQL connection error

Saturday, 12th May 2007 9:12pm
Tonight when I tried to run the MySQL Query Browser on Windows I got the following error message:

MySql Error Number 2003, can't connect to MySQL server on 'localhost'

When I pinged the server as suggested by the dialog box, everything looked alright but still I could not connect to MySQL. I then checked to see if the MySQL service was running in the control panel's Administrative Tools/Services section. For some reason the MySQL service had stopped running and on manually re-starting the service I managed to once again connect to MySQL as normal.

delicious delicious | digg digg

Category: MySQL | Comments : 3

Replacing text in multiple files

Saturday, 5th May 2007 11:39pm
There are some things that I have to perform a number of times and they require simple and quick solutions and searching and replacing text in a number of files normally constituting a project is one of them.

Sometimes there is the temptation to just code your own small application to do the task but this is unnecessary because there are a number of free utilities that do the job very well. For standalone applications I use very simple applications like TurboSR Search and Replace and Replace In files. Both are simple search and replace utilities that make changes to a whole range of text, HTML, XML or other text-based files including php.

The best scenario I think it to use an IDE that has an in-built function to replace text in a whole project if the files are source code files and one such example is PSPad . With PSPad you can specify whether you want to change and replace text in a project, open files or you can specify a folder as you would do with a stand-alone utility. I normally prefer project because I would be working in a project and at the end of the search I get a report specifying which files have been changed.

delicious delicious | digg digg

Category: Freeware | Comments : 0