cleate colum in every table mysql

how can  i insert colum timestampA(type timestamp)    into all table on database ph can I do one time I must do by hand table in each table
teeraAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Amar BardoliwalaCommented:
Hello teera,

You should find your answer from following link

http://stackoverflow.com/questions/5706740/adding-column-to-all-tables-in-a-mysql-database-unknown-table-names

Thank You.

Amar
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ukerandiCommented:
@mysql_query("ALTER TABLE `YourTableName` ADD `timestampA` timestamp") or die(mysql_error());
0
ukerandiCommented:
this will find all the database file and Add another field for each one. this is good example

<?php
$dbname = 'mysql_dbname';

if (!mysql_connect('mysql_host', 'mysql_user', 'mysql_password')) {
    echo 'Could not connect to mysql';
    exit;
}

$sql = "SHOW TABLES FROM $dbname";
$result = mysql_query($sql);

if (!$result) {
    echo "DB Error, could not list tables\n";
    echo 'MySQL Error: ' . mysql_error();
    exit;
}
$i=1;
while ($row = mysql_fetch_row($result)) {
   

@mysql_query("ALTER TABLE `$row[$i]` ADD `timestampA` timestamp") or die(mysql_error()); 

$i++;
}

mysql_free_result($result);
?>

Open in new window

0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

ukerandiCommented:
sorry , $i should be initialized,not $i=1
$i=0;
0
Ray PaseurCommented:
You can use ALTER TABLE, however you cannot use the script posted at ID:37037046 because it does not work.  It's always a good idea to test the code that is posted here at EE.  Some of our experts do not test their code before they post it, and you may get yourself in trouble if you rely on untested code.  Back up your data base before you perform any such operation!
0
Ray PaseurCommented:
This will generate the correct query statements (or at least will find the table names).  Add your own information at line 6 and see what it gives you for output.  Once you are satisfied with the look of the queries, you can back up your data base and try adding the TIMESTAMP columns by inserting the appropriate call to mysql_query().

Best of luck with your project, ~Ray
<?php // RAY_temp_teera.php
error_reporting(E_ALL);
echo "<pre>";

// INSERT YOUR LIVE DATABASE CREDENTIALS HERE
require_once('YOUR_DB_CREDENTIALS.php');

// CONNECT TO THE DATA BASE SERVER
if (!$db_connection = mysql_connect("$db_host", "$db_user", "$db_word")) 
{
    $errmsg	= mysql_errno() . ' ' . mysql_error();
    echo "<br/>! db_connection ";
    echo "<br/> $errmsg <br/>";
}

$sql = "SHOW TABLES FROM $db_name";
$res = mysql_query($sql);
while ($row = mysql_fetch_array($res))
{
    $sql = "ALTER TABLE `$row[0]` ADD `timestampA` TIMESTAMP";
    echo PHP_EOL . $sql;
}

Open in new window

0
teeraAuthor Commented:
thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.