when i backup all moodle site and install into an other local xampp server it says "Error writing to database"
Did you remember to create a user with permission to access the SQL database on the backed up server?
If not, you're in for trouble.
yes i create as the same as the backup site user account in the config .php
In that case, and assuming that you have changed the config.php appropriately, what remains is the XAMP environment you're using. That's about all I can think of without more details.
I haven't used XAMP in years so, sorry, but I can't really help you there.
Good luck!