Hi, im new in yii, and i am tryin to use an existing sql server database with yii. I could create the models,controllers,and views but, when i try to save a new object with a uniqueidentifier type pk, the system says:
Conversion failed when converting from a character string to uniqueidentifier
I did validate an example : {33EF43BE-1D79-0148-831F-462752D033CD} and is ok.
This is part of my Model’s code:
public function beforeSave() {
if (!$this->ContactoGUID) {
$this->ContactoGUID = $this->guid();
//$this->owner->guid = $guid->guid;
}
}
function guid(){
if (function_exists('com_create_guid')){
return com_create_guid();
}else{
mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
$charid = strtoupper(md5(uniqid(rand(), true)));
$hyphen = chr(45);// "-"
$uuid = chr(123)// "{"
.substr($charid, 0, <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />.$hyphen
.substr($charid, 8, 4).$hyphen
.substr($charid,12, 4).$hyphen
.substr($charid,16, 4).$hyphen
.substr($charid,20,12)
.chr(125);// "}"
return $uuid;
}
}
Can anybody give me a hand with this?
Thanks in advance,
Best Regards
Martin