Replace string in MySQL
Answer:
Replace a string with the UPDATE statement is easy in MySQL
E.g.
mysql> UPDATE table1 SET name = REPLACE (name, 'foo', 'bar');
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
Replace string in MySQL
Answer:
Replace a string with the UPDATE statement is easy in MySQL
E.g.
mysql> UPDATE table1 SET name = REPLACE (name, 'foo', 'bar');
Make a file executable in Linux
Answer:
Assume you have create a shell script, my.sh, you need to make this file executable, you can use the chmod command.
# chmod +x my.sh
Then you can execute the script directly
# ./my.sh
Set the auto increment start value in MySQL?
Answer:
In MySQL, you can change the table's auto increment start value by the following command.
mysql> ALTER TABLE `my_table` AUTO_INCREMENT = 2000;
Query OK, 2 rows affected (0.06 sec)
Records: 2 Duplicates: 0 Warnings: 0
Convert array to object in PHP
Answer:
It is easy to cast an object to an array in PHP, using the following method.
<?php
$obj = new stdClass();
$obj->foo = "foo";
$obj->bar = "bar";
var_dump ( (array) $obj );
It will print out...
array(2) {
["foo"]=>
string(3) "foo"
["bar"]=>
string(3) "bar"
}
A simple hash in Perl
Answer:
Hash is a dictionary like data structure in Perl. It allows you to direct access to a particular element inside a hash.
Example:
use strict;
use warnings;
my %hash = (
"a" => "1",
"b" => "2",
);
print $hash{"b"}; # print "2"