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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.