SQL Alter table

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Niko
Forum Newbie
Posts: 9
Joined: Tue Apr 20, 2004 6:17 am

SQL Alter table

Post by Niko »

basically all i need to do is insert a php varible as field in mysql database.

To test it i used a static string, the function is as follows:

mysql_select_db($tNG->databasename, $tNG->connection);
mysql_query("ALTER TABLE tbl_subscribed ADD newField_sbd VARCHAR(255)");


It works once, then then mysql needs to restart before you can make any changes.

Any ideas.
User avatar
bluenote
Forum Commoner
Posts: 93
Joined: Sat Mar 01, 2003 4:59 am
Location: Heidelberg, Germany

Post by bluenote »

8O Can you describe your problem a liite more detailled? Have you done a mysql_connect BEFORE doing the mysql_select_db??

perhaps it helps if you modify your code like this:

Code: Select all

<?php

$hostname = "your_host";
global $hostname;

$username = "your_mysql_userl";
global $username;

$password = "your_mysql_passwd";
global $password;

$dbName = "your_default_db";
global $dbName;

$userstable = "your_default_table";
global $userstable;

MYSQL_CONNECT($hostname,$username,$password) OR DIE("Database connection failed.");

@mysql_select_db("$dbName") or die("Database not found.");

$query = "ALTER TABLE tbl_subscribed ADD newField_sbd VARCHAR(255)";
$erg = mysql_query($query) or die(mysql_error());

?>
This should give you the reason-of-error, if there is some.

Greez,
- bluenote
Post Reply