Jump to content

[SOLVED] I don't understand how to alter a MySQL column with php


bubblybabs

Recommended Posts

I have a table named sentcards with a field called cardid with a current type int...

I wish to change the type int to bigint(30) with an attribute that is unassisgned and a default of 0...

 

This is my code:

"ALTER TABLE ".$tablePrefix."sentcards MODIFY cardid cardid BIGINT(30) UNASSIGNED NOT NULL";

:

 

but it doesn't work which makes me think I have something incorrect in my command...  Could you point me in the right direction?

 

Babs

This query is for http://forum.mysql.com

 

Anyway the query synatx can be found at http://dev.mysql.com/doc/refman/5.0/en/alter-table.html

 

You can use the below command

ALTER TABLE `dbname`.`tablename` MODIFY COLUMN `column` VARCHAR(255)

 

Please add column

 

Bye for now

 

CSJakharia

Since this was asking for coding in php I figured this was the place to go...

 

I changed the coding to this:

"ALTER TABLE databasename gc_sentcards CHANGE cardid cardid BIGINT(30) UNASSIGNED NOT NULL default '0'";

but it still does not work...  (databasename is changed from its correct info)

 

That webpage states I don't need to use the word column but I tried it anyway:

"ALTER TABLE databasename gc_sentcards CHANGE COLUMN cardid cardid BIGINT(30) UNASSIGNED NOT NULL default '0'";

 

Still not working...  Should I go to this other forum to ask for assistance or stay here?

Babs

i did this:

 

<?php
$db = mysql_connect("localhost", "root");
      $connection=mysql_select_db("Help", $db);
     $query = "ALTER TABLE sentcards
MODIFY cardid bigint(30) not null";
      $result=mysql_query($query);

if ($result) {
echo "Success !";
}
else if (!$result) {
echo "Failed !";
}
else {}
?>

 

notice that i removed unassigned and it showed 'success !' means it worked !, just replace the query in your script with this :

 

$query = "ALTER TABLE sentcards
MODIFY cardid bigint(30) not null";

 

tell me wheter it works or not....

 

if sql confuses u , go here http://www.techonthenet.com/sql/index.php...

check this site too...www.w3schools.com

OK, removing unassigned allows this to work (as well as removing the extra cardid - I was following the instructions but mixed up what they meant)...  But this must be unsigned or the mod I'm working on won't work...

 

This worked for me thus far:

"ALTER TABLE ".$tablePrefix."sentcards MODIFY cardid BIGINT(30) NOT NULL default '0'";

 

I'll look at the link you gave me, maybe it'll be clearer...  I have to have it unsigned...

 

And, looking at what I originally post I see I had a spelling error!  It's unsigned not unassigned!  Duh... Once I changed it to this it works:

 

"ALTER TABLE ".$tablePrefix."sentcards MODIFY cardid BIGINT(30) UNSIGNED NOT NULL default '0'";

 

Thanks, I appreciate all of you helping me get this figured out...

Babs

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.