Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- How to insert a known UUID/GUID (record_id) - in this case generated by PHP, an unknown or blank UUID/GUID, and a regular int field
- SQL Server Table creation code:
- CREATE TABLE dbo.MYTable
- (
- [id] UNIQUEIDENTIFIER NOT NULL,
- [core_uuid] UNIQUEIDENTIFIER NULL,
- [category_id] UNIQUEIDENTIFIER NULL,
- [other_id] INT NOT NULL DEFAULT 0,
- PRIMARY KEY NONCLUSTERED (id)
- );
- */
- // fix zero/null fields
- $record_id = 'C39A4043-7DF9-4FCB-B5F5-C47F813A97B5';
- $core_uuid = (!empty($core_uuid)) ? "'$core_uuid'" : "NULL";
- $category_id = (!empty($category_id)) ? "'$category_id'" : "NULL";
- // setup query for MS SQL Server
- $query = 'INSERT INTO [database].[schema].[table] ([id], [core_uuid], [category_id], [other_id]) '
- . 'VALUES (\''.$record_id.'\','.$core_uuid.','.$category_id.','.$other_id.')';
- // execute query
- $result = mssql_query($query);
- if (!$result) {
- // query failed, print error to log
- $err = mssql_get_last_message();
- $log->lwrite('--> MSSQL error: '.$err);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement