PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, March 14, 2022

[FIXED] How use CodeIgniter querybuilder with inserting data to MSSQL (newid() )

 March 14, 2022     codeigniter, sql-server     No comments   

Issue

For id i use uniqueidentyfier, and in queries insert i write: newid() in, but, how do this in Query builder?

{
$db = \Config\Database::connect();

$data = [
 'id'  =>  'newid()',
 'id_zgloszenia'  =>  $idpp,
 'response'  => $response_pp,
 'header_response' => $head_res, 
 'data_datetime' => 'getdate()',   
];

$builder = $db->table('DOM5_PP_LOGI'); 

 $builder->insert($data);     

}  

I try like above, and also: $builder->set('id', uniqid());

But i had error: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Conversion failed when converting from a character string to uniqueidentifier.


Solution

You can try this to generate UUID by MSSQL:

$builder->set('id', 'NEWID()', FALSE);

Explain: set() will also accept an optional third parameter ($escape), that will prevent data from being escaped if set to FALSE. To illustrate the difference, here is set() used both with and without the escape parameter.

You can get find out more here: https://codeigniter.com/userguide3/database/query_builder.html#id8



Answered By - Tartarus
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing