MySQL Tabelle ID zurücksetzen (PHP Script)
php.jpg MySQL: Reset Auto Increament.
idreset.html

<html>
<head>
<title>ID Reset</title>
</head>
<body>
<form name='idresets' method="POST" action="idreset.php">
<table align="center" border="0">
<tr>
 <td>
  <label for="usid">DB Kennung:</label>
 </td>
 <td>
  <input type="text" name="us" id="usid" value=""/>
 </td>
</tr>
<tr>
 <td>
  <label for="pwid">DB Kennwort:</label>
 </td>
 <td>
  <input type="Password" name="pw" id="pwid" value=""/>
 </td>
</tr>
<tr>
 <td>
  <label for="hostid">DB Host:</label>
 </td>
 <td>
  <input type="text" name="host" id="hostid" value=""/>
 </td>
</tr>
<tr>
 <td>
  <label for="dbid">DB Name:</label>
 </td>
 <td>
  <input type="text" name="db" id="dbid" value=""/>
 </td>
</tr>
<tr>
 <td>
  <label for="tabelleid">DB Tabelle:</label>
 </td>
 <td>
 <input type="text" name="tabelle" id="tabelleid" value=""/>
 </td>
</tr>
<tr>
 <td colspan=2 align="center">
  <input type = "submit" name = "reset" value = "ID Reset">
 </td>
</tr>
</table>
</body>
</html>
    

HTML Kopieren

idreset.php

<?php
foreach($_POST as $x => $y){
  $$x = trim($y);
}
if(function_exists('mysqli_connect')){
 $mysqli = new mysqli($host, $us, $pw, $db);
 $mysqli->query("ALTER TABLE `".$tabelle."` DROP `id`;");
 $mysqli->query("ALTER TABLE `".$tabelle."` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;");
 echo "ID reset erfolgreich!";
}else{
 $con = @mysql_connect ($host,$us,$pw);
 $sdb = mysql_select_db($db);
 mysql_query("ALTER TABLE `".$tabelle."` DROP `id`;") or die(mysql_error());
 mysql_query("ALTER TABLE `".$tabelle."` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;") or die(mysql_error());
 echo "ID reset erfolgreich!";
}
?>
    

PHP Kopieren