Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet
- -> LINES TERMINATED BY 'rn';
- INSERT INTO yourtable VALUES (1,2), (5,5), ...
- $file = file("content.txt"); //read file line by line
- foreach ($file as $val) {
- if (trim($val) != '') { //ignore empty lines
- mysql_query("INSERT INTO xxx SET club='" . $val . "'");
- }
- }
- <?php
- $conn = new PDO($dsn, $username, $password);
- $stmt = $conn->prepare('INSERT INTO table VALUES (NULL, ?)');
- foreach(file('list.txt') as $club) {
- $stmt->execute(array($club));
- }
- <?php
- $servername = "localhost";
- $username = "user";
- $password = "pass";
- $dbname = "db";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $file = file("list.txt"); //read file line by line
- foreach ($file as $val) {
- if (trim($val) != '') { //ignore empty lines
- $sql = "INSERT INTO `db`.`table` (`column`) VALUES ('$val');";
- if ($conn->query($sql) === TRUE) {
- echo "New record created successfully";
- } else {
- echo "Error: " . $sql . "<br>" . $conn->error;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement