Archive for May 2007
MySQL equivalent of PATINDEX
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);
MySQL connection error
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.
Replacing text in multiple files
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.