When using the command line clients of MySQL or Postgresql it is often the case that the output of some select statement does not display very well, either because the query returns too many columns or the contents of a column are too long. In such cases it would be really nice to display the query results line by line in a vertical listing instead of the horizontal listing. A similar display can be found in both MySQL and Postgresql. So, let’s assume that you have a table that was created with the following SQL statement:
Continue reading “Vertical display output in MySQL and Postgresql”Month January 2013
How to add Captcha verification in the comments of the Yii blog demo
This post is about adding captcha verification in the comments section of the Yii demo blog. This post was triggered from two comments posted on the page of the tutorial (Comment 1 and Comment 2). In order for you to follow through the current post you need to have the Yii framework in place and you need to have followed all the steps of the Blog Tutorial up untill the “Creating and Displaying Comments” section. So, let’s start:
If you have followed the tutorial you should by now have a working Leave a comment form in place that is displayed underneath each individual post of your blog web application. The form should contain the Name, Email, Website and Comment fields that will populate the corresponding properties of your Comment model. The Post ID should be set on submit, the Status of the Comment should also be set on submit and the Time Created should be set just before saving the Comment (if this is a newly created comment).
How to get your Error reporting constant values
PHP lets you specify the Error Reporting level, so that when a piece of your code is run based on this setting of the php.ini file the generated errors and/or warnings will be shown or not. Generally speaking in a development environment it is recommended to set this as high as possible so that you are informed about all the little details of your code whereas in a production environment this setting is usually set to something less “explanatory”.
In order to set the value of the error_reporting directive php constant values and bitwise operators are used, as they are described in the PHP manual . The setting can be set during runtime using the php error_reporting() function (manual) passing as a parameter the int value calculated based on the constant values and bitwise operators used. The function returns the integer value of the previous error_reporting level.
Now if you wish to find out what is your current error_reporting level you could go and have a look in your php.ini file or you could use the error_reporting() function with no parameters, in which case the function will return an integer value representing the current error reporting level. If you go via the php.ini file you will see the names of the constants used and the operations applied to produce your current reporting level but if you try to get a similar result via a php file that you have written you might notice that it is more difficult to understand what is going on since now you are only dealing with an integer value and not with the named constants. So which is the description of your error reporting level and how can you retrieve it from within a php file?
Continue reading “How to get your Error reporting constant values”How to create a symbolic link
A symbolic link is a “connection” we create between a location and a physical file or directory. The file or directory exists in a known location A in our system and we wish to create a connection to that location from a different location in our system B. An easy way to think of a symbolic link is like a shortcut from one location to another.
A symbolic link is created with the following command
ln -s TARGET NAME_OF_LINK
where ln is the basic unix command, the parameter -s specifies that we wish to create a symbolic link, TARGET should be replaced with the destination of our link and NAME_OF_LINK should be replaced with what we want our link to be named after.
Continue reading “How to create a symbolic link”Value of an environment variable
If you wish to see the value of an environment variable the easiest way to do so is to print the contents of the variable in your shell. To do so you have to use the following command:
echo $var_name
If there is an environment variable defined named var_name then the above command will output its contents in standard output (your shell). If there is no variable with that name defined the above command will output an empty line. If you see var_name outputed in your shell you probably forgot to type in the $ sign before the name of your variable. Remember that echo simply echoes a string in standard output so if you do not specify that the string you typed is a variable ($ sign) then it will simply output your string.
Now if you do not exactly remember the name of your environment variable the easiest way to find out if it is defined or not would be to output all the environment variables defined and either move your way through the list like
printenv
or pipe the output to grep providing a part of the name of the variable like
printenv | grep name
