wordpress blog stats

Change Timezone Shared Hosting – PHP / MySQL

To change the timezone within a shared hosting, where you cant change the MySQL’s timezone, you need to execute a query which needs to be run after every MySQL you connect for database.

Change Timezone Shared Hosting

If you have a shared hosting, or due to any other reason, where you cannot change the MySQL’s timezone, here is what you need to do to fulfill your need of changing the timezone.

In the connection file, or whichever file where you connect to MySQL database, simply run the following query after you connect to the database.
SET time_zone = ‘-6:00′;

In PHP, you could write the code below:
mysql_query(“SET time_zone = ‘-6:00′”);

By executing the above query, your connection’s timezone will be decreased to -6 hours as per the actual timezone is set over there in the database.

Check Current Timezone – MySQL

To check MySQL’s current timezone, write the following query, which will return you the difference of GMT and the current timezone of MySQL:

SELECT TIMEDIFF(NOW(), CONVERT_TZ( NOW(),@@session.time_zone,’+00:00′ ) );

By checking the timezone of MySQL, you can easily manage the difference of GMT and can set your current timezone in PHP connection, which you want.

Change Grub Menu / Boot Order

If you have multiple OS installed in your system, and you want to change the default operating system from the list of Grub2, here is an easiest solution, which doesn’t actually require any software but just an editor to do a bit changing.

Change Grub Menu / Boot Order

All you need to do is to have a sudo / root access to change a file. Open up the following file in any editor like gedit or in terminal using vim, having sudo / root access:

/etc/default/grub

Once opened, you can see a text GRUB_DEFAULT, having value as 0, GRUB_DEFAULT=0

All you need to do is to change the value of this variable GRUB_DEFAULT to the order number of the OS from the Grub2 list, which you see and choose at start, to select your OS.

Note that, the numbering starts from 0, for example, if you have 4 items in Grub2 Menu:

Ubuntu, with Linux 2.6.35-22-generic
Ubuntu, with Linux 2.6.35-22-generic (recovery mode)
Ubuntu, with Linux 3.0.0-17-generic (on /dev/sda1)
Ubuntu, with Linux 3.0.0-17-generic (recovery mode)

and you want the third item from the above list to be selected as default, which is:
Ubuntu, with Linux 3.0.0-17-generic (on /dev/sda1)

you need to set the value of GRUB_DEFAULT as:
GRUB_DEFAULT=2

After you save the file, open up the Terminal, and write the following command:
sudo update-grub

Once done, simple restart your OS and see if you have successfully changed the boot order menu of Grub2.

Still Having Problems?

If you are still having problems and are unable to change the menu order of Grub2, after applying the above changes, you might have been missing something here. As you have multiple of Operating Systems in your system, make sure that the changes are being done on the main Operating System, like the one you recently installed, or the one which is coming as Default selection on Grub2.

Hope the solution works.

MySQL Physical Directory Path – Linux

If you are using MySQL, and want to know the actual physical path of MySQL, where MySQL stores the db, and its information files and the amount of data for MySQL data and MySQL index files i.e. table_name.MYD and table_name.MYI respectively, below is the easy solution.

MySQL Physical Directory Path

In Linux, all you need to do is to access the following folder:
/var/lib/mysql/

You can open it in Terminal or Nautilus (using sudo or root access). Once you get into the folder, you can easily find the folders which are actually your database names, and in the database name folders, you can find the table names, having MYD and MYI extensions, which are actually your data and index files.

Hope it helps.

Check Whose Online Using Database – PHP

While going through a project where theres a need of taking some action on those users who are currently logged in on to the website, I went through the following solution. Please note that, you will be needing a scripting language, database and ajax.

Here is what I think you should do, to get the solution to this problem.

Create a table, for example user_session in database, having the fields:
- user_id (integer & unique)
- last_seen (date time)

Now you can simply call ajax within your whole website, for example in your main index file, header or footer, like after every 1 minute or few seconds, as per your need, which will be INSERTING or UPDATING the user_id with the date and time of Ajax call, to be updated in last_seen field.

On the other hand, you have to run a script or a cronjob, which will be running in like after every few seconds or minutes, DELETING the records which are say 5 minutes older. The DELETE query should look like:

DELETE FROM user_session
WHERE last_seen < DATE_SUB(NOW(), INTERVAL 5 MINUTE);

Through these steps, u will only be having those users in your user_session table who are currently online, so you can perform any action with those users, or display the count of online users to your website etc.

If you have any other great solution to the problem, or have any other comments or suggestions, feel free to comment on the post.

FUNCTION FIELD does not exist – ORDER BY FIELD Error

While using ORDER BY Field function of MySQL, the following error occurred:

FUNCTION database_name.FIELD does not exist

Here’s a quick solution

FUNCTION FIELD does not exist

If you are using a query like below:

SELECT * FROM tbl ORDER BY FIELD (id,1,2,3);

then there’s a chance you may face this type of error while running the query.

Solution is simple. Remove the space between FIELD and round bracket (.

So the query should look like:

SELECT * FROM tbl ORDER BY FIELD(id,1,2,3);

and your problem could have resolved.

Hope this works.

While using PHP’s session_start function, an error started showing as:

Notice: session_start(): ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied

Here’s a simple solution.

Solution – Notice: session_start(): ps_files_cleanup_dir: opendir failed: Permission denied

To resolve this error, all you need to do is to open up your php.ini file, which is usually existing in the following path:
/etc/php5/apache2

and change the value of variable session.gc_probability to 0, if the value is 1, or if the value is 1 then change it to 0.

Now restart the apache server through the following command as in linux terminal:
sudo /etc/init.d/apache2 restart

and the error could have been resolved.

PHP – Verb Pronoun Adjective Into Noun – Match & Search Words

While finding out a PHP converter, which converts different parts of text into noun, like from verb to noun, I found a great solution in algorithm known as Porter Stemming Algorithm. Though this type of script is needed when you want to match the words of different forms, and treat them as one single word, like in counting, as it will try to cut some of the ending characters of the word and make them look similar, to be treated as one.

Convert Parts of Text Into Noun

If you are finding a script in PHP or any other language like Java, Perl, Python, VB, Javascript etc, which will let you convert words like verb into noun, plural into singular, past tense into present tense, all you need to do is to get the Porter Stemming Algorithm from the following website link:
Porter Stemming Algorithm

By using this website, all you need to do is to download your specific language’s script (which is a text file over there), and copy the functionality into your code and start using the function for converting different forms into noun.

Search Column Or Field Name In Tables Or Database

Are you looking for a MySQL Query to search for a specific field name or column name, existing in the tables of a database?

Search Column Or Field Name In Tables Or Database

To search a column name or field name within the whole database, following query will be beneficial, as it will be able to retrieve your desired column, existing in the any of the tables of the chosen database:

SELECT DISTINCT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME IN ('your_column_name')
AND TABLE_SCHEMA='your_db_name';

Please note that, the above query will retrieve all the table names of the chosen database, in which your desired column name exists.

Search Multiple Column Or Field Names In Database

You can also use LIKE operator instead of IN operator, as if you are not very much sure of the column name, or if you want to search multiple column names with similar name, for example, if you want to search for the fields parent_id and parent_name, so you can use the LIKE operator here as below:

SELECT DISTINCT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE ('parent%')
AND TABLE_SCHEMA='your_db_name';

or

SELECT DISTINCT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE ('%parent%')
AND TABLE_SCHEMA='your_db_name';

Sphinx Command Line Search

If you are using sphinx and you want to search sphinx through command line, like in putty, terminal etc., there here is the command you can use to search sphinx directly through command line.

Sphinx Command Line Search

To search on an sphinx index in command line, like in terminal / putty etc., where you want to search on different keywords and see the results, you can use any of the following two commands:

sudo /usr/local/sphinx/bin/search -c /usr/local/sphinx/etc/sphinx.conf -i index_name "test"

or

sudo /usr/local/sphinx/bin/search –index index_name "test"

Replace index_name with the index you want to search in sphinx, and replace test with the keyword you want to search in the index.

Also, please check the sphinx directory, as the directory path may vary for search and sphinx.conf

Hope this will help you in searching sphinx indexes through command line.

New iPhone5 Launched – Launch Of iPhone 5

Apple’s iPhone5 is finally launched on 12th September, 2012.

As per the news, following are the updates of this new iPhone 5:

  • The new iPhone5, made entirely of glass and aluminum
  • iPhone 5 is 18% thinner and 20% lighter (112 grams) than the iPhone 4S
  • iPhone 5 having A6 chip, will be having double performance from the A5 chip inside the iPhone 4S
  • Improved battery life
  • and more

Let us know if there are some other updates to this new iPhone 5 which makes it better than iPhone 4, or share any reviews of iPhone4 vs iPhone5 with us.

Share your comments in the comments box for this new iPhone.