How Can I clone a database in Microsoft SQL server using PHP?
Your best option is to take and then restore a backup of the database.  If your sample database is fairly static then I suggest making a gold standard backup and using that.  If it's under constant modification then taking a backup and then restoring it on the spot should be sufficient.  

BACKUP DATABASE [Sample] TO DISK=N'&lt;path to file&gt;'

RESTORE DATABASE [TargetName] FROM DISK=N'&lt;path to file&gt;'
WITH REPLACE, RECOVERY
, MOVE 'file1' TO '&lt;new path for data file&gt;'
, MOVE 'log1' TO '&lt;new path for log file&gt;'


Just make those commands dynamic and grant whatever user you are using for this db_creator and db_backupoperator

However, this command assumes that [TargetName] doesn't already exist.  You can check for the existence of a database by querying sys.databases.  If you need to override an existing database, then you need to kick everyone out before starting the restore.  

Both of the commands above should be run from [master] to avoid conflicts.

This command will set a database to single_user mode, which will kick everyone out.  However, the first connection to it will take the only allowed connection, so you should run this and then immediately run the restore command, preferably in the same transaction.  

ALTER DATABASE [TargetName]
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;