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

September 14, 2011 at 7:33 pm Leave a comment

JQuery: Showing a progress image while processing background task

I thought to write a simple example to show a progress bar or a gif image showing a that a task is happening at the background using a jquery function.

i) Include jquery script file in the header section and the following code in the head

<script language="javascript">
$(document).ready(function(){
    $('#progress').hide();
    $("#main a.bgdiv").click(function(){
        $("#progress").show("slow");
        $("body").load($(this).attr('href'));
        return false;
    });
});
</script>

(more…)

June 11, 2009 at 7:59 pm 1 comment

cakePHP: Session enabled messages using Session->setFlash

There are different ways to flash or publish the messages for a user action. Usability plays a major role in determining how the navigation pattern for a web application takes place.

  • publishing the outcome of user action on the same page
  • designing a single page to flash all success, error, warning, notice level messages
  • designing a separate page for each message that gets published for the user

To read more on CakePHP refer …

June 9, 2009 at 10:31 pm Leave a comment

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.

Read more to know the solution »

May 28, 2009 at 9:07 pm Leave a comment

What is a Third-party cookie?

Third party cookies are the cookies that are served by sites other than the site that you are visiting.

For example, Ad serving companies serve their cookies to your computer when you visit a particular site to track which Ads were served, their relevancy to the content where the Ads get published and other such details in addition to keeping track of the user preferences.

May 24, 2009 at 8:55 pm Leave a comment

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

May 21, 2009 at 8:00 pm Leave a comment

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"].

Read more

May 20, 2009 at 8:00 pm Leave a comment

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);
?>

May 19, 2009 at 1:10 am Leave a comment

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.

May 18, 2009 at 11:42 am Leave a comment

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

Read more

May 17, 2009 at 11:14 am Leave a comment

Older Posts


 

February 2012
M T W T F S S
« Sep    
 12345
6789101112
13141516171819
20212223242526
272829  

Blog Stats

  • 19,219 hits

Follow

Get every new post delivered to your Inbox.