0

I'm trying to make update a MySQL database using PHP with the data to be inserted coming from a text file. However, when I run a query from PHP the database does not update.

If I run the mysql client from the terminal, mysql -u root -p --local-infile videos and enter LOAD DATA LOCAL INFILE /home/user/movies.txt INTO TABLE films; it works fine.

Here is the code from my Index PHP file (hosted on Apache2).

Am I doing anything wrong? Like syntax, etc?

<?php

$username="root"; $password="12345"; $database="videos";

$con = mysqli_connect("localhost",$username,$password, $database);

mysqli_query("LOAD DATA LOCAL INFILE '/home/user/movies.txt' INTO TABLE films");

$result = mysqli_query($con, "SELECT title, yr, genre, plot, rating FROM films") or die("Unable to query.");

echo "<table border='1'>";
echo "<tr> <th>Title</th> <th>Year</th> <th>Genre</th> <th>Plot</th> <th>Rating</th> </tr>";

// keep getting the next row until no rows left
while($row = mysqli_fetch_array( $result )) {
  // print out contents of each row into a table
  echo "<tr> <td>";
  echo $row['title'];
  echo "</td><td>";
  echo $row['yr'];
  echo "</td><td>";
  echo $row['genre'];
  echo "</td><td>";
  echo $row['plot'];
  echo "</td><td>";
  echo $row['rating'];
  echo "</td></tr>";
}

echo "</table>";
?>

Thanks.

EDIT: Echoed the error message for the LOAD DATA LOCAL.., Errormessage: The used command is not allowed with this MySQL version

3
  • You should echo the actual errors to the browser or check your error logs. Commented Aug 3, 2015 at 18:00
  • Your first sentence seems to say mySql is the programming language and PHP is the database. That is of course not the case Commented Aug 3, 2015 at 19:03
  • Clarified use of mysql vs php Commented Aug 5, 2015 at 20:04

1 Answer 1

1

Found this: using mysql LOAD statment in PHP fails, but doing it via command line works

And I used:

$conn = mysqli_init();
mysqli_options($conn, MYSQLI_OPT_LOCAL_INFILE, true);
mysqli_real_connect($conn,server,user,code,database);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.