简体   繁体   中英

PHP check if row exists in .sql dump file

I am wondering how to check if a row exists in a MYSQL .sql dump file without loading it into a database. I also wish to check 3 fields. FieldA,FieldB, FieldC with userinfo1,userinfo2,userinfo3, all of those are strings. The filename is database1.sql and is stored on an FTP server. Is there a way to do this wiht leaving the file on the other server and not importing it into another database?

Ok so first of all there is no way to do any processing on the file without having it on the server where PHP is running. You can however have a PHP script which logs into the FTP and automatically downloads and processes the file.

As to the SQL processing, the easiest way is to read the file line by line, first use strpos("INSERT INTO .....) to check for the beginning of the correct query type (insert, update ... whatever it might be and then use something like:

https://code.google.com/p/php-sql-parser/wiki/ParserManual and go over the generated array and compare the values. This is fairly simple and easy to do. However the library comes with some overhead so if speed is an issue or files are very big, you will need some complex preg_match regular expression to get the necessary values and checksum them. After that you can store them in a temporary array and go over this checksums array each time to match whether you already have those values...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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