Hello,
I am trying to inject data extracted via php-json to sql database but unable to run it in loop mode. It is working just for one data, then stops.
If it's necessary, I can share the complete php file.
test.php
<?php
include_once 'imdb.class.php';
//mysql config.
$servername = "127.0.0.1";
$username = "root";
$password = "mypasswd";
$dbname = "mariadb";
$dbport = "3306";
//open mysql connection.
$conn = new mysqli($servername, $username, $password, $dbname, $dbport);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//read video database to array.
$sql = mysqli_query($conn, "select * from video ORDER BY name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$video[] = $row;
}
############## here we go ! ########################
$aTests = [
'Top Gun',
'Chicago',
];
###########################################
$i = 1 ;
foreach ($aTests as $sMovie) { #--------!!!
$i++;
$IMDB = new IMDB($sMovie);
if ($IMDB->isReady) {
$title = $IMDB->getTitle($bForceLocal = true);
$description = mysqli_real_escape_string($conn, $IMDB->getDescription());
$plot = mysqli_real_escape_string($conn, $IMDB->getPlot($iLimit = 0));
..
..many other queries below...
..
..
$sql = "INSERT INTO video
(name, 2nd_name, 3rd_name, time, protocol, category_id, cat_genre_id_1,.......)
VALUES ('$title $year', '$title $year', '0', '$runtime', '', '3090', '559', '1', '1', ....)
if ($conn->query($sql) !== TRUE) {
echo '<p style="text-align: center;">Error: ' . $sql . '<br>' . $conn->error . '</p>';
die;
My question:
Instead of entering data into php
file, can I run it like below way?
while read -r line; do
php test.php $line
done < words_from_file
Thank you
Boris
--- Post updated at 08:35 AM ---
Solved now.
Replaced foreach
line as shown below :
foreach($argv as $sMovie) {
Thank you
Boris