Append/Prepend string to a field in MySQL

Just now I am working with a problem where I need to update a column/field by appending something. I was in a bit trouble for a 2 mins as I was finding a solution for this. First thing came to my mind is

UPDATE `table_name` SET `field_name`=`field_name`+’appending string’ WHERE `field_name`=’xxx’;

I knew this won’t work in my case. It is suitable when I need to SUM up floating point. However, I simply need to append to current value. Within two mins I got the idea that worked 100%. It is:

UPDATE `table_name` SET `field_name`=concat(`field_name`, ‘ appending string’) WHERE `field_name`=’xxx’;


PDF output generating library using PHP

If you are looking for creating PDF output of your HTML pages, you can do it using PHP’s PDFlib module. However, there are some libraries for faster development of your script. Some even are not dependent on PDFlib. Please see below for quick overview.

dompdf is an HTML to PDF converter. At its heart, dompdf is (mostly) CSS2.1 compliant HTML layout and rendering engine written in PHP. It is a style-driven renderer: it will download and read external stylesheets, inline style tags, and the style attributes of individual HTML elements. It also supports most presentational HTML attributes.


* handles most CSS2.1 properties, including @import, @media & @page rules
* supports most presentational HTML 4.0 attributes
* supports external stylesheets, either local or through http/ftp (via fopen-wrappers)
* supports complex tables, including row & column spans, separate & collapsed border models, individual cell styling, (no nested tables yet however)
* image support (gif, png & jpeg)
* no dependencies on external PDF libraries, thanks to the R&OS PDF class
* inline PHP support. See below for details. Continue reading →

Concat multiple rows!

Today I was wondering how can I concatenate multiple rows in a single row. Suppose, I need to get the email addresses of a user table. The “SELECT `email` FROM `usertable`;” will return something like this:




But I needed:

email1, email2, email3

It is very easy to process and make same output using PHP. But I thought there must be a way in MySQL. After searching a while I got the solution. Its simple.

SELECT group_concat(`email`) from `usertable`;

Thats it. Now I got what I wanted :).

MySQL starting failed!

Today one of my junior friend asked me to help with his new VPS. He was in trouble that his mysql server was not starting up. After logging in the server, I saw the problem. It was showing:

Timeout error occurred trying to start MySQL Daemon.
Starting MySQL:                                            [FAILED]

I tried many ways. But none worked. Later, thought, I can rebuild the VPS as it is new VPS.

Continue reading →

PHP_SELF is empty!

Last two days, I am playing or learning to play with nginx web server. I have heard some reputation about it and saw some performance chart in the web. I liked it for its, as claimed, extremely low memory footprint for one of my small VPS.

After reading some tutorial in Projanmo Forum, I am successfully configured nginx, with with fastcgi, php-fpm, mysql etc. When I visit the website, I found some problems. Some section were not working. Later I found, where I used $_SERVER[‘PHP_SELF’] were not not working. Later investigating the phpinfo(); I have seen that some global php variables are empty. I found nothing on net. Later alamgir bro, helped to sort out. In fact the whole tutorial is contributed by him.

Solving this issue is real easy. Just add the following the in your nginx php configuration section.

include        fastcgi_params

The changed codes may look like: [copied directly from his mail]

location ~ \.php$ {
root           /www;
fastcgi_index  index.php;

include        fastcgi_params;  #newly added

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;



hope this will save your time :-).

MySQL problem

Today, I have to waste a long time with new server. Last night my internet connection disconnected while cPanel was installing in the server. Later I have seen that everything running fine except mysql. It is showing some error like:

Warning, no valid mysql.sock file found.mysql has failed

searching many tutorials, forums after 2/3 hours later I found the following post. Continue reading →