Posted
on January 16, 2018, 9:34 am,
by admin,
under
mysql.
CREATE TABLE newtable LIKE oldtable; |
Posted
on January 11, 2018, 3:35 pm,
by admin,
under
mysql.
CREATE PROCEDURE example1()
label1:BEGIN
DECLARE rowCount INT DEFAULT 0;
DECLARE i INT DEFAULT 0;
SELECT COUNT(*) INTO rowCount FROM my_table;
WHILE (i <= rowCount) DO
SELECT i;
SET i = i+1000;
END WHILE;
END; |
Posted
on January 11, 2018, 3:33 pm,
by admin,
under
mysql.
The difference with WHILE
is that it execute statement before checking the condition. As a result, it iterates one more time than WHILE
does.
CREATE PROCEDURE example2()
label1:BEGIN
DECLARE rowCount INT DEFAULT 0;
DECLARE i INT DEFAULT 0;
SELECT COUNT(*) INTO rowCount FROM my_table;
REPEAT
SELECT i;
SET i = i+1000;
UNTIL i > rowCount
END REPEAT;
END; |
Posted
on December 19, 2017, 4:59 pm,
by admin,
under
mysql.
In MySQL, function is different than procedure by returning the value and can be called within SELECT
statement.
DETERMINISTIC
means that the function always produces same results for the same input parameters.
CREATE FUNCTION `Sample`(parameter VARCHAR(10)) RETURNS TINYINT(3) UNSIGNED
DETERMINISTIC
BEGIN
DECLARE myfunctionID TINYINT UNSIGNED;
IF parameter = 'sample1' THEN
SET returnID = 1;
ELSEIF parameter = 'sample2' THEN
SET returnID = 2;
ELSEIF parameter = 'sample3' THEN
SET returnID = 3;
END IF;
END IF;
RETURN myfunctionID;
END |
Posted
on November 22, 2017, 1:28 pm,
by admin,
under
dns,
mail.
Step 1. Add SPF record to your DNS server
Create TXT record type and add the following text without quotes “”
@ TXT "v=spf1 a mx include:myrelay.com ~all" |
Step 2. Check if SPF record is added correctly
username@laptop:/home/username# dig myhostname.com TXT
<<>> DiG 9.10.3-P4-Ubuntu <<>> myhostname.com TXT
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 62028
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4000
;; QUESTION SECTION:
;myhostname.com. IN TXT
;; ANSWER SECTION:
myhostname.com. 86400 IN TXT "v=spf1 a mx include:myrelay.com ~all"
;; Query time: 7 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; WHEN: Wed Nov 22 13:36:40 GMT 2017
;; MSG SIZE rcvd: 104 |
Step 3. Test it by sending email to your gmail account, then go the receiver’s mailbox and check email source header
Received-SPF: pass (google.com: domain of www-data@myhostname.com designates 24.33.20.159 as permitted sender) client-ip=24.33.20.159;
Authentication-Results: mx.google.com;
spf=pass (google.com: domain of www-data@myhostname.com designates 24.33.20.159 as permitted sender) smtp.mailfrom=www-data@myhostname.com |
Posted
on November 22, 2017, 12:35 pm,
by admin,
under
apache,
tips.
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s on(s)|offs()
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R] |
Posted
on September 22, 2017, 12:56 pm,
by admin,
under
mysql.
SELECT COUNT(*) FROM information_schema.TABLES WHERE table_schema = 'databasename'; |
Posted
on September 19, 2017, 2:57 pm,
by admin,
under
mysql.
Former practice:
CREATE DATABASE mydatabase CHARACTER SET utf8 COLLATE utf8_general_ci; |
Current practice:
CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; |
Posted
on September 11, 2017, 11:51 am,
by admin,
under
mail.
Open /etc/postfix/main.cf file:
bash# vi /etc/postfix/main.cf |
Append / modify line as follows to bind to localhost (127.0.0.1) only:
inet_interfaces = 127.0.0.1 |
Type the following to restart Postfix:
bash# /etc/init.d/postfix restart |
Posted
on August 23, 2017, 10:35 am,
by admin,
under
php.
<?php
function memoryChecker($variable) {
echo 'in function: '.memory_get_usage()."\n";
}
echo 'before function: '.memory_get_usage()."\n";
$var = "hello world\n";
memoryChecker($var); |