简体   繁体   English

将插入查询从sql文件转换为php数组

[英]convert insert queries from sql file to php array

I have a sql file which is having lot of insert queries. 我有一个有很多插入查询的sql文件。 is there any way to convert these insert queries to php arrays? 有什么办法可以将这些插入查询转换为php数组?

i dont want to insert these items directly to database. 我不想将这些项目直接插入数据库。 before inserting i want to filter lot of items from these 在插入之前,我想从这些过滤很多项目

`INSERT INTO `products` (`p_id`, `p_name`, `p_parent`, `p_dependent`,`p_pid`) VALUES
(1, 'some', "some", '2', '1'),(1, 'some', "some", '2', '1'),(1, 'some', "some", '2', '1'),(1, 'some', "some", '2', '1')

is there any option in regex to convert these into array? 正则表达式中是否有任何选项可以将它们转换为数组?

Take the whole query in a PHP string, then explode it for paranthesis and you will find (after the first return) your query values. 将整个查询放入一个PHP字符串中,然后将其分解为无括号状态,您将发现(在第一次返回之后)查询值。 From here, you can further explode them by commas to return each value of the query if you want to avoid some of them. 从此处开始,如果要避免使用逗号,可以进一步用逗号将其展开,以返回查询的每个值。 After having your queries all good in a PHP array, just parse the array and execute insert statements with the values in your array. 在PHP数组中使查询一切正常之后,只需解析数组并使用数组中的值执行insert语句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM