SHOW:
|
|
- or go back to the newest paste.
1 | <?php | |
2 | $username = ""; | |
3 | $password = ""; | |
4 | $database =""; | |
5 | $con = new mysqli("localhost",$username,$password,$database) or die("Error " . mysqli_error($con)); | |
6 | $con->query("SET NAMES 'utf8'"); | |
7 | $column = 'column_name'; | |
8 | $table = 'table_name'; | |
9 | $type = 'INT(1)'; | |
10 | $default = '0'; | |
11 | $after = 'column_name'; | |
12 | ||
13 | $default = (!EMPTY($default)) ? 'NOT NULL DEFAULT ' . $default : ''; | |
14 | ||
15 | // query | |
16 | $query_table = "SELECT $column from `$table`"; | |
17 | if ($result_table = $con->query($query_table)) { | |
18 | if ($result_table->num_rows > 0) { | |
19 | // $sql = "ALTER TABLE `$table` ADD `$column` $type $default AFTER `$after`"; | |
20 | // $sql = "ALTER TABLE `product1` CHANGE `hit` `hit` INT(11) NOT NULL DEFAULT '0'"; | |
21 | // if (!mysqli_query($con,$sql)) { | |
22 | // echo 'Error : '. $domain . '-' . mysqli_error($con) .'<br />'; | |
23 | // } else { | |
24 | // echo table updated<br />'; | |
25 | // } | |
26 | ||
27 | - | echo $domain . ' column already exists'; |
27 | + | echo $table . ' column already exists'; |
28 | } | |
29 | } else { | |
30 | ||
31 | // echo 'Error: ' . $domain . '- column does not exist<br />'; | |
32 | $sql = "ALTER TABLE `$table` ADD `$column` $type $default AFTER `$after`"; | |
33 | if (!mysqli_query($con,$sql)) { | |
34 | echo 'Error : $table update.' - ' . mysqli_error($con) .'<br />'; | |
35 | } | |
36 | echo $table . ' updated<br />'; | |
37 | } |