Please keep in mind that you shouldn't write to a database that is being actively used. If another process is currently reading the database it might crash.
A safe way to update your database is:
<?php
chdb_create('tmp.db', $data);
rename('tmp.db', 'database.db');
?>