Here is text fileSolutionhost localhost user root pass ro
<html>
<head>
</head>
<?php
$conn = mysqli_connect(\"localhost\", \"root\", \" \");
if (!$conn){
die(\"Can not connect: \" . mysqli_error());
}
mysqli_select_db($conn,\"snippets\");
$sql = \"CREATE TABLE P1artists (
ArtistID int ,
artistName varchar(50)
)\";
mysqli_query($conn,$sql);
mysqli_close($conn);
?>
</body>
</html>
//Here is text file
Solution
$host = \"localhost\";
$user = \"root\";
$pass = \"root\";
$db = \"database\";
$connection = mysql_connect($host, $user, $pass) or die (\"Unable to connect to the database or Invalid credentials!\");
mysql_select_db($db) or die (\"Unable to select database or database not found!\");
$file = \"localhost:8888/samples.txt\";
$file_handle = fopen($file, \"r\");
fclose($file_handle);
while (($sample = fgetcsv($file_handle, 1000, \"|\")) !== FALSE) {
$sample_query=\"INSERT into samples(ID,NAME) values(\'$sample[0]\',\'$sample[1]\')\";
mysql_query(\"TRUNCATE TABLE samples\") or die(\"MySQL Error: \" . mysql_error()); //Delete the existing rows
mysql_query($sample_query) or die(mysql_error());
}
echo \"Done!\";
