PDA

View Full Version : what did i miss here?



spork
June 9th, 2002, 11:56
iīve gotten rather decent at php lately so i figured it was time to get more educated in handeling mysql databases... unfortunately the progress is slow since i almost never have more than 20 uninterupted minutes to spend on anything... anyway, what did i miss with this simple query? it returns the error "You have an error in your SQL syntax near '' at line 1" but i donīt really know what i missed...

i just tried changing "after" to "first" and then it worked... strange... is after not a valid location for a column?



<?php
$db = "test2";
$dbhost = "localhost";
$dbusername = "";
$dbpassword = "";
$table = "test";
$column = "url";

$conn = mysql_connect("$dbhost", "$dbusername", "$dbpassword") or
die("Count not connect to database");
echo "connected to database.<br>";

mysql_select_db($db) or
die ("Could not select database");
echo "selcted database $db.<br>";


$query = "alter table $table add column $column varchar(40) null after";

mysql_query ($query) or
die (mysql_error());
echo "added column $column";

?>

spec
June 9th, 2002, 12:05
there is no before, since there is no instance where you can use before where after cannot be used. with the exception of putting a column at the top of the table in which you use FIRST. BTW your syntax is a little off



<?
$query = "alter table $table add column $column varchar(40) null after <CoLuMN>";
?>

where <CoLuMN> is the cloumn before where you want the column

spork
June 9th, 2002, 12:12
*smacks head*

heh, of course you need to specify which column you want to add it after, i shouldīve thought of that... thanks