How to insert UUID values inside MYSQL table using SQL command?

I try to insert values using SQL command for a created and modified field. Is this possible or it can not be used as an SQL command. An example: 2011-09-12 20:20:52
Another field is UUID value.

Should be used only PHP and fill in all values in the particular format?

It is possible. Show us the problem you’re having and someone will know why it’s causing you trouble. But those look like datetime values to me, not UUIDs.

Please find a PHP function:

<?php

$cur_timestamp = time();
$cur_timezone_paris = $cur_timestamp;  //+6 hours vs. server time (an option)
$cur_datetime = date("Y-m-d H:i:s",$cur_timezone_paris); //2011-10-13 10:43:25
    
function getNewUUID() {
	$sql = "SELECT UUID()";
	$res = mysql_query($sql) or mysql_error_show($sql,__FILE__,__LINE__);
	$row = mysql_fetch_array($res);
	return $row[0];
}

function Add($id, $created¸, $modified) {
    $s->id = getNewUUID();
	$s->created = new Doctrine_Expression('NOW()');
	$s->modified = new Doctrine_Expression('NOW()');
	$s->save();
	return true;
	}

$sql = "INSERT INTO MyTable (`id`,`created`,`modified`) ";

?>

Once you add in the values to your query, what’s the actual problem you’re having?

I’d really recommend you stop using the old mysql_ functions as you are doing in your getNewUUID() function - they’ve been removed from PHP for quite a few years now, after being deprecated for many more. Use mysqli or, my preference, PDO instead.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.