Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $username = "";
- $password = "";
- $database ="";
- $con = new mysqli("localhost",$username,$password,$database) or die("Error " . mysqli_error($con));
- $con->query("SET NAMES 'utf8'");
- $column = 'column_name';
- $table = 'table_name';
- $type = 'INT(1)';
- $default = '0';
- $after = 'column_name';
- $default = (!EMPTY($default)) ? 'NOT NULL DEFAULT ' . $default : '';
- // query
- $query_table = "SELECT $column from `$table`";
- if ($result_table = $con->query($query_table)) {
- if ($result_table->num_rows > 0) {
- // $sql = "ALTER TABLE `$table` ADD `$column` $type $default AFTER `$after`";
- // $sql = "ALTER TABLE `product1` CHANGE `hit` `hit` INT(11) NOT NULL DEFAULT '0'";
- // if (!mysqli_query($con,$sql)) {
- // echo 'Error : '. $domain . '-' . mysqli_error($con) .'<br />';
- // } else {
- // echo table updated<br />';
- // }
- echo $table . ' column already exists';
- }
- } else {
- // echo 'Error: ' . $domain . '- column does not exist<br />';
- $sql = "ALTER TABLE `$table` ADD `$column` $type $default AFTER `$after`";
- if (!mysqli_query($con,$sql)) {
- echo 'Error : $table update.' - ' . mysqli_error($con) .'<br />';
- }
- echo $table . ' updated<br />';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement