Reputation: 1517
I am working on a php code as shown below which scans the directory ($src_dir) and list all mp4 files.
$src_dir = ('\\\ABCD-ST-001\Audio_Test\podcast\incoming_folder');
$mp4_files = preg_grep('~\.(mp4)$~', scandir($src_dir));
print_r(array_values($mp4_files)); // LineA
Here is the O/P obtained from Line#A:
Array ( [0] => 36031P.mp4 [1] => hello.mp4 )
I am getting two values at Index 0 and Index 1. The 1st is 36031P.mp4 and 2nd is hello.mp4
After that I have wrote a script which insert data in table Podcast_Export
.
$db->exec("INSERT INTO Podcast_Export ('House#', 'Status') VALUES ('array_values($mp4_files)', 'Go')"); /* have to place this question on SO*/
On running the above script, I am getting the following data inside the table which is not I want.
array_values(Array) Go
array_values(Array) Go
Problem Statement:
I am wondering what changes I should make in the script above so that it inserts the following data inside the table:
36031 Go
hello Go
Upvotes: 0
Views: 1365
Reputation: 16117
You are inserting a string value 'array_values($mp4_files)'
, you just need to remove quotes around this value. something like:
$db->exec("INSERT INTO Podcast_Export ('House#', 'Status') VALUES (array_values($mp4_files), 'Go')");
But, if you delete the quotes around array_values
then it will insert following array as a string Array ( [0] => 36031P.mp4 [1] => hello.mp4 )
so, its better to use loop here with $mp4_files
array and insert your data.
Side Note:
I suggest you to use different name for House#
column something like house_no
.
Upvotes: 1