renumber

Some times you lost continuity on tables with auto increment fields, for example instead of having a sequence like : 1 2 3 4 yo have something like: 1 5 18 30; in this cases, the method renumber('table') renumbers the table.

Parameters

renumber($table, $col='id')
$table:name of the table to renumber.
$col:name of the column with the auto-increment attribute.

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<?php

require_once 'dalmp.php';

$user = getenv('MYSQL_USER') ?: 'root';
$password = getenv('MYSQL_PASS') ?: '';

$DSN = "utf8://$user:$password".'@127.0.0.1/test';

$db = new DALMP\Database($DSN);

$db->renumber('table');

Example where uid is the auto-increment column:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<?php

require_once 'dalmp.php';

$user = getenv('MYSQL_USER') ?: 'root';
$password = getenv('MYSQL_PASS') ?: '';

$DSN = "utf8://$user:$password".'@127.0.0.1/test';

$db = new DALMP\Database($DSN);

$db->renumber('table', 'uid');

See also

MySQL AUTO_INCREMENT.

A great amount of time has been spent creating, crafting and maintaining this software, please consider donating.

Donating helps ensure continued support, development and availability.

dalmp


comments powered by Disqus