get-next-auto-increment

Gesponsorde koppelingen

PHP script bestanden

  1. get-next-auto-increment

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php

// Author: Ruben Vandenbussche
// Website: http://www.RVandenbussche.nl
// Contact: info (at) RVandenbussche (dot) nl
// Date: 11 Nov 2008
//*******************************************
// Script: Get Auto Increment v1.0
//It does:
//  1.  Get the next auto increment from the table.
//*
//It doesn't:
//  1.  Make a connection with the database it assumes that it allready exists.
//*******************************************

// Summary:
// Getting the next auto increment from the given table ($table) is handy for example giving
// image names the same name as the auto increment id.

//WARNING:
//When multiple connections use the same table at the same time the next auto increment could
//be wrong.

//Script start here.

    function getAI($table){
        $query = mysql_query("SHOW TABLE STATUS LIKE '$table' ");
        $row = mysql_fetch_array($query);
        $auto_increment = $row['Auto_increment'];
        mysql_free_result($query);
        return ($auto_increment);
    }

    
    //get auto increment from database
    $id = getAI('article'); //article is the table where we get the auto increment from.
?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.