SQL Command to Change Column Order in a MySQL Table

February 4th, 2014 No comments

Sometimes you need to change column order in a table. If you don’t have access to latest phpmyadmin version (4.0 and above), you don’t have any graphic solution to do this and you’ll have to use an SQL query.

First of all, you need to identify the type of field you want to move. It should look like VARCHAR(25), or INT(11) or something like this.

You can see some types in the image below
hotel

When you know what to move, let’s build the query. We’ll move hotel_bookingid column to the second place, just after id.

ALTER TABLE `hotels` MODIFY COLUMN `hotel_bookingid` INT(11) AFTER `id`

Please, note, that you need to include field type after its name. So if you want to move our_rating column, the query will look like:

ALTER TABLE `hotels` MODIFY COLUMN `our_rating` FLOAT AFTER `id`

Hope this will help someone, who doesn’t like the most recent version of PHPMyadmin or just doesn’t have access to it.

Categories: MySQL Tricks Tags:

Investigating What a Process is Actually Doing in Linux With strace

January 6th, 2014 No comments

If you need to debug a process in a linux environment, the simplest yet very effective solution should be strace.
It can be easily installed with “yum install strace” or “apt-get install strace” depending on the type of Linux you’re on.

Here are some usage samples.

First of all, if you don’t have a shortcut to strace, you should find the path where it resides. Type whereis strace. You should get something like this:
screen

Then use the path you get to find out what a process is actually doing. Type top, your output should look like:
top_output

In order to investigate a process, type  /usr/bin/strace -p6971 (in this sample 6971 is the process ID, you should enter yours).
strace_output
You can also redirect the process output to a file.

strace_output2

This will send strace output to a file until the strace process in interrrupted.

There are lots of additional parameters strace uses. I have mentioned only the most simple ones, you’re welcome to discover all other option to get the output you need.

Categories: Linux Tricks Tags:

How to Open Links in a New Tab in Hesk 2.5.2

January 4th, 2014 No comments

If you have used Hesk before, you must have mentioned that all links that were posted by users at the time of ticlet creation/reply were opening in new tabs. If you decide to update to 2.5.2 (I was using version 2.3 before), you will notice that all links will be opening in the current tab.

If you want to change this, you’ll need to change one function.

Go to inc/common.inc.php

Find function hesk_makeURL($text, $class = ”)

it should look like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function hesk_makeURL($text, $class = '')
{
global $hesk_settings;</code>

if ( ! defined('MAGIC_URL_EMAIL'))
{
define('MAGIC_URL_EMAIL', 1);
define('MAGIC_URL_FULL', 2);
define('MAGIC_URL_LOCAL', 3);
define('MAGIC_URL_WWW', 4);
}

$class = ($class) ? ' class="' . $class . '"' : '';

// matches a xxxx://aaaaa.bbb.cccc. ...
$text = preg_replace_callback(
'#(^|[\n\t (>.])([a-z][a-z\d+]*:/{2}(?:(?:[a-z0-9\-._~!$&\'(*+,;=:@|]+|%[\dA-F]{2})+|[0-9.]+|\[[a-z0-9.]+:[a-z0-9.]+:[a-z0-9.:]+\])(?::\d*)?(?:/(?:[a-z0-9\-._~!$&\'(*+,;=:@|]+|%[\dA-F]{2})*)*(?:\?(?:[a-z0-9\-._~!$&\'(*+,;=:@/?|]+|%[\dA-F]{2})*)?(?:\#(?:[a-z0-9\-._~!$&\'(*+,;=:@/?|]+|%[\dA-F]{2})*)?)#i',
create_function(
"\$matches",
"return make_clickable_callback(MAGIC_URL_FULL, \$matches[1], \$matches[2], '', '$class');"
),
$text
);

// matches a "www.xxxx.yyyy[/zzzz]" kinda lazy URL thing
$text = preg_replace_callback(
'#(^|[\n\t (>.])(www\.(?:[a-z0-9\-._~!$&\'(*+,;=:@|]+|%[\dA-F]{2})+(?::\d*)?(?:/(?:[a-z0-9\-._~!$&\'(*+,;=:@|]+|%[\dA-F]{2})*)*(?:\?(?:[a-z0-9\-._~!$&\'(*+,;=:@/?|]+|%[\dA-F]{2})*)?(?:\#(?:[a-z0-9\-._~!$&\'(*+,;=:@/?|]+|%[\dA-F]{2})*)?)#i',
create_function(
"\$matches",
"return make_clickable_callback(MAGIC_URL_WWW, \$matches[1], \$matches[2], '', '$class');"
),
$text
);

// matches an email address
$text = preg_replace_callback(
'#(^|[\n\t (>.])(([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*(?:[\w\!\#$\%\'\*\+\-\/\=\?\^\`{\|\}\~]|&)+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,63})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?))#i',
create_function(
"\$matches",
"return make_clickable_callback(MAGIC_URL_EMAIL, \$matches[1], \$matches[2], '', '$class');"
),
$text
);

// return $text;
} // END hesk_makeURL()

And replace it with the code from the previous version of Hesk:

1
2
3
4
5
6
7
8
9
function hesk_makeURL($strUrl)
{
    $myMsg = ' ' . $strUrl;
    $myMsg = preg_replace("#(^|[\n ])([\w]+?://[^ \"\n\r\t<]*)#is", "$1<a href=\"$2\" target=\"_blank\">$2</a>", $myMsg);
    $myMsg = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)#is", "$1<a href=\"http://$2\" target=\"_blank\">$2</a>", $myMsg);
    $myMsg = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "$1<a href=\"mailto:$2@$3\">$2@$3</a>", $myMsg);
    $myMsg = substr($myMsg, 1);
    return($myMsg);
} // End hesk_makeURL()

Save file and have fun.

Categories: PHP Solutions Tags: