No, it's not possible to have PHP generate the exact same UUID()
as MySQL because it's a (completely) random number.
It sounds like your problem is that you like using UUID()
in MySQL but don't want to execute an extra query to figure out what the new UUID
is.
So why not have PHP create the UUID
to be used as the primary key in your INSERT
query?? This comment on php.net should show you how to do this.
Using those sample functions:
$uuid = UUID::v4();
$sql = "INSERT INTO mytable (uuid, foo) VALUES ('{$uuid}', 'bar');";
echo "The UUID is: ". $uuid;
Edit: There are several methods on that page which generate different types of UUID
s. v4
is pseudo-random, but you could use a different version or create your own UUID
generator.