问题描述
我正在编写如下所示的 php 代码,它会扫描目录 ($src_dir) 并列出所有 mp4 文件.
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
这是从Line#A获得的O/P:
Array ( [0] => 36031P.mp4 [1] => hello.mp4 )
我在索引 0 和索引 1 处得到两个值.第一个是 36031P.mp4,第二个是 hello.mp4
I am getting two values at Index 0 and Index 1. The 1st is 36031P.mp4 and 2nd is hello.mp4
之后,我编写了一个脚本,将数据插入表 Podcast_Export
.
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
问题陈述:
我想知道我应该在上面的脚本中进行哪些更改,以便在表中插入以下数据:
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
推荐答案
您正在插入一个字符串值 'array_values($mp4_files)'
,您只需要删除该值周围的引号.类似:
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')");
但是,如果您删除 array_values
周围的引号,那么它将插入以下数组作为字符串 Array ( [0] => 36031P.mp4 [1] => hello.mp4)
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 )
所以,最好在这里使用带有 $mp4_files
数组的循环并插入您的数据.
so, its better to use loop here with $mp4_files
array and insert your data.
旁注:
我建议您为 House#
列使用不同的名称,例如 house_no
.
I suggest you to use different name for House#
column something like house_no
.
这篇关于如何使用php在SQLite表中插入数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!