1UUID 2==== 3 4Generates an Universally Unique Identifier (`UUID <http://en.wikipedia.org/wiki/Universally_unique_identifier>`_) v4. 5 6Parameters 7.......... 8 9:: 10 11 UUID($b=null) 12 13:$b: If true will return the UUID in binary, removing the dashes so that you can store it on a DB using column data type binary(16). 14 15Examples 16........ 17 18.. code-block:: php 19 :linenos: 20 21 <?php 22 ... 23 24 echo $db->UUID(); 25 26 echo $db->UUID(true); 27 28 29Example storing UUID as binary(16): 30 31.. code-block:: php 32 :linenos: 33 :emphasize-lines: 12 34 35 <?php 36 37 require_once 'dalmp.php'; 38 39 $user = getenv('MYSQL_USER') ?: 'root'; 40 $password = getenv('MYSQL_PASS') ?: ''; 41 42 $DSN = "utf8://$user:$password".'@127.0.0.1/test'; 43 44 $db = new DALMP\Database($DSN); 45 46 $uuid = $db->UUID(); 47 48 $db->PExecute("INSERT INTO table (post, uuid) VALUES(?, UNHEX(REPLACE(?, '-', '')))", json_encode($_POST), $uuid); 49 50 51Example converting from binary(16) to original UUID format chat(36): 52 53.. code-block:: php 54 :linenos: 55 :emphasize-lines: 12 56 57 <?php 58 59 require_once 'dalmp.php'; 60 61 $user = getenv('MYSQL_USER') ?: 'root'; 62 $password = getenv('MYSQL_PASS') ?: ''; 63 64 $DSN = "utf8://$user:$password".'@127.0.0.1/test'; 65 66 $db = new DALMP\Database($DSN); 67 68 $sql = "SELECT LOWER(CONCAT_WS('-',LEFT(HEX(uuid),8),SUBSTR(HEX(uuid),9,4),SUBSTR(HEX(uuid),13,4),SUBSTR(HEX(uuid),17,4),RIGHT(HEX(uuid),12))) FROM table"; 69 70 $uuids = $db->FetchMode('ASSOC')->getCol($sql); 71 72 73.. seealso:: 74 75 `MySQL string functions <http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_unhex>`_.