How to Import CSV data to a MySQL table in a database from command line?
First log into MySQL from command line and create the table “table_user” under the database “db_user”
mysql> use db_user;
mysql> desc table_user;
+——-+————–+——+—–+———+—————-+
| Field | Type | Null | Key | Default | Extra |
+——-+————–+——+—–+———+—————-+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | | NULL | |
| age | varchar(20) | NO | | NULL | |
| email | varchar(255) | NO | | NULL | |
+——-+————–+——+—–+———+—————-+
4 rows in set (0.00 sec)
mysql> load data local infile ‘/userinfo.csv’
-> into table table_user
-> fields terminated by ‘,’
-> lines terminated by ‘\n’
-> (name, age, email);
Note: “id” field is skipped from the list for it to be auto incremented.
Check more information at kurinchilamp.kurinchilion.com
PHP: Fatal error: Maximum execution time of 30 seconds exceeded
This error happens when the execution time of the PHP script exceeds the time limit for program execution in Php.ini file.
By default the timer is set to 30 seconds in php.ini and you can track the time limit by tracing for ‘max_execution_time’ directive in php.ini.
Fahrner Image Replacement CSS
FIR stands for Fahrner Image Replacement named after Todd Fahrner.
It is a standard compliant technique in which <h1> and <span> tags are used to have nice heading and highlights.
Key fact in this technique is that the text will get displayed even if the CSS is disabled for some reason, hence presenting the text on browsers and in screen readers.
Read more
PHP Register Globals and Security Vulnerability
Register Globals directive is turned OFF from PHP version 4.2.
PHP Global Variables
Environment variables, GET, POST, Server, Cookie variables are knows as Global Variables.
When register_globals directive is turned ON (like what most ISP’s did), you can access/set the global variables like $username, $password instead of $_POST["username"], $_POST["password"].
PHP: escapeshellcmd, escapeshellarg
escapeshellcmd and escapeshellarg are two commands that are used to escape the defect causing characters that are present in the system command or the arguments that get passed to it respectively. Before passing the commands to the system or exec, the strings get escaped using these commands.
Sample program to demonstrate the usage:
<?php
// shell command
$mycmd = “ls -al”;
$returncmd = escapeshellcmd($mycmd);
system($returncmd);
// shell arguments
$myshellargs = “al”;
system(“ls -”.escapeshellargs($myshellargs);
?>
PHP Backtick operator `
PHP Backtick operator `
This is the equivalent of shell_exec() command in php. It needs to be present in pair for the commands within it to get executed at the system level.
When shell_exec is disabled or when safe_mode is enabled, this operator is disabled.
PHP XSS: htmlspecialchars vs. htmlentities
Cross site scripting XSS is a term used to refer attacks or loop holes present in the scripting used by websites favoring hackers to exploit this path towards identity theft or phishing.
In PHP, two functions are mainly used to circumvent XSS attacks.
i) htmlspecialchars
ii) htmlentities