Page 1 of 1

SQL Alter table

Posted: Wed Nov 10, 2004 8:24 am
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.

Posted: Mon Nov 22, 2004 9:02 am
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