PHPackages                             vend/mysql-uuid - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. vend/mysql-uuid

AbandonedArchivedLibrary[Database &amp; ORM](/categories/database)

vend/mysql-uuid
===============

A MySQL UUID converter and formatter

2.0.0(5y ago)31201.4k↓42.1%5GPL3PHPPHP &gt;=5.4.0

Since Jul 11Pushed 2y ago105 watchersCompare

[ Source](https://github.com/vend/mysql-uuid)[ Packagist](https://packagist.org/packages/vend/mysql-uuid)[ RSS](/packages/vend-mysql-uuid/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (8)Used By (0)

MySQL UUIDs
===========

[](#mysql-uuids)

[![Build Status](https://camo.githubusercontent.com/b0d119c70a46f9788bbc5fec8c37ceb1056fb4a62d63fbd3f5e071f6b9fad89c/68747470733a2f2f7472617669732d63692e6f72672f76656e642f6d7973716c2d757569642e706e67)](https://travis-ci.org/vend/mysql-uuid)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/ae2772e19ffdd5c0e90c89575738f0f333e9b4c94dfdacc749b75bd55b6d5810/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f76656e642f6d7973716c2d757569642f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/vend/mysql-uuid/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/d8c0914c42679cc1b24a0b336534a3d63d2a37c793899d2f0b96e19113434ee2/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f76656e642f6d7973716c2d757569642f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/vend/mysql-uuid/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/0e914b919ecc9f534f3fe9bca21f8a58d496fe077978b96c3bda73fb1827c5b7/68747470733a2f2f706f7365722e707567782e6f72672f76656e642f6d7973716c2d757569642f762f737461626c652e737667)](https://packagist.org/packages/vend/mysql-uuid)[![License](https://camo.githubusercontent.com/d4fa612f18f0d75363c466e6e64fcf236f8863838e02c87258a58ee27a2ce421/68747470733a2f2f706f7365722e707567782e6f72672f76656e642f6d7973716c2d757569642f6c6963656e73652e737667)](https://packagist.org/packages/vend/mysql-uuid)

Description
-----------

[](#description)

This is a small library for working with MySQL UUIDs in PHP. MySQL UUIDs are 128-bit values returned from the `UUID()` command in MySQL, and by default are formatted as a hex-and-dash traditional UUID string, like this:

```
02fbfeee-02ff-11e4-9583-080027f3add4

```

There are a couple of problems with using this sort of value directly:

- The string stores the most frequently changing timestamp field at the start (that is, it's little-endian); using this value directly will spread writes all across your tablespace and indexes, ruining any sort of locality. We want the *last* part of the string to contain the most frequently changing part of the UUID value.
- The string can't be directly used in a 128-bit column, such as `BINARY(16)`; storing the string directly would take about 37 bytes rather than 16, bloating indexes and row sizes.

MySQL UUIDs are generated according to "[DCE 1.1: Remote Procedure Call](http://www.opengroup.org/public/pubs/catalog/c706.htm)" (Appendix A) CAE (Common Applications Environment) Specifications published by The Open Group in October 1997 (Document Number C706).

Why Do This?
------------

[](#why-do-this)

Mainly for data clustering. We don't want a single buffer pool page to be under a lot of pressure for inserts (as would be the case with an auto\_increment column), and we also don't want to randomly spread data across the entire index/table.

Installation
------------

[](#installation)

Install via composer. That's it.

Supported Formats
-----------------

[](#supported-formats)

This library uses `pack()` and `unpack()` to munge MySQL UUID values into ones more suitable for use as a database key. The supported formats are:

- **Standard UUID strings**, with dashes.
- **Hex UUIDs**, which are just like string UUIDs, but without the field separator dashes - perhaps useful for using with MySQL's `HEX()` and `UNHEX()`
- **Binary UUIDs**, which are 16 byte binary strings with just the underlying 128-bit UUID value, no formatting at all

Quick API Example
-----------------

[](#quick-api-example)

```
