Friday, March 22, 2019

How to import a large CSV in MySQL table

I have struggled for a while to import my large CSV (comma, separated, values) files in my apps.
The common method should be using:
LOAD DATA LOCAL INFILE 'myfile.csv' INTO TABLE table
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(field1, field2, field3, ....);
Seem to be so nice and simple so far, until receiving errors encountered by MySQL versions or incompatibility with the server acceptance (disabled functions).
I am recommending the next method that really worked:
Insert to the database line-by-line of CSV with this PHP file run by Command Prompt:
insert.php:
<?php  
include 'config.php';
ini_set('max_execution_time', 0);
if (($handle = fopen("mycsvfile.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
   $c2=str_replace("'","\'", $data[2]);
       $sql = "INSERT my_table (field1, field2) 
   values('val1','val2')";
   mysql_query($sql,$link) or die("Insertion Failed:" . mysql_error());
    }
    fclose($handle);
}
?>

Thursday, March 21, 2019

Live traffic feed in real time


Alternatives to Feedjit

A tracking code is a small snippet of code that is usually implemented as JavaScript in the HTML source code of a website. 
These lines of code allow webmasters to analyze the flow of visitors to websites and the activities of users.
Real-time tracking is meant to show the latest visitor without refreshing the page.
The tracking code is mostly used as a website widget.
A web widget commonly referred to simply as a widget is a small program that you can easily put on your website or blog.For free and unlimited visitors logs we strongly recommend you to use :
https://ip2.app/stats.php
You must register an account to get your personal tracking code to paste it in website widgets.
Then you can watch your live traffic flow including visitors IP address, source and visited pages:


Free IP geolocation API by IP2.app

An API (Application Programming Interface) is a set of programming tools for accessing a Web-based software application.
IP2.app helps website developers to request information automatically from a known IP address for Web-apps.
IP.app database is updated weekly with fresh geographic information.
The Geolocation is the process of determining the physical, real-world location of a person or device using digital information by an IP address.
The IP is the encoded address of an Internet device.
This API is completely free to use for an unlimited number of requests and domains.
Free is referring to no-cost and to freedom to use by anyone who needs geolocation for Internet visitors.
https://ip2.app/api.php