Implementing PDO, code correct so far?
Instead of checking for a UID collision before an insert, I would put a unique key on that column, and then write fallback code for the case (very very unlikely) when two collide. That way you can simplify your logic and reduce the number of queries to one instead of two. You also don't need a transaction if you implement this change, since there is only 1 query.

//you can remove the outer try/catch since only the execute() should possibly fail
$DBH-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //&lt;~ put this in the initialize of the db connection
$STH = $DBH-&gt;prepare("INSERT INTO USERS (uid,namn) VALUES (:uid, :name)");
$STH-&gt;bindParam(':uid', $uid);
$STH-&gt;bindParam(':namn', $_POST['namn']); // a value posted form user input
try {
    $STH-&gt;execute();
} catch( PDOException $e ) {
    //deal with collision 
}