Is there a way I could retrieve data from a mysql db table and save them in a binary file?
My table looks like this
id domain_name isAuth
1 www.yah.com 1
2 www.go.com 0
3 www.goo.com 1
4 www.foo.com 1
Is there a way I could retrieve data from a mysql db table and save them in a binary file?
My table looks like this
id domain_name isAuth
1 www.yah.com 1
2 www.go.com 0
3 www.goo.com 1
4 www.foo.com 1
Since performance seems to be the issue here, assuming $data is the result of a call to PDOStatement::fetchAll or mysqli_fetch_all, I suggest serialize and unserialize:
/* fetch $data */
file_put_contents('my_file.dat', serialize($data));
/* do some other stuff */
$data = unserialize(file_get_contents('my_file.dat'));
/* use $data */
pack you could write actual binary data, thus creating a much denser file. In a language with reasonable performance (like C or Java) you would normally do this because it has better performance than anything else and the resulting file is no larger than needed. However, writing a function in PHP that iterates over an array and packs it is most likely a lot slower than using a built-in function like serialize, which is written in C.