CREATE TABLE QUERY PHP/MySQL
| From: | Jonathan | Date: | Fri, 06 Dec 2002 21:00:40 +0000 |
| Subject: | CREATE TABLE QUERY PHP/MySQL | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-23887@lists.php.net to get a copy of this message | ||
This is the first time I am trying to create a table in MySQL based on
user input.
Here is the scenario,
The user will enter in the name of a stage, e.g. Harley Davidson.
I then look for the first space (to indicate the first word), make it
into lower case and then do the following:
$new_stage_name = "stage_".$var;
This will give $new_stage_name the value of "stage_harley".
That works fine.
Now I want to run the following query:
$SQL = "CREATE TABLE ".$new_stage_name." (set values and their
properties)";
If I run this query using PHPMyAdmin, minus the var of course, the table
is created.
When I run it in my code, nothing happens. I do a die($SQL) to see the
final outcome of the query and it's correct and is what I am using to
run the query in PHPMyAdmin.
This is what my code is doing:
I have class RecordSet which makes the db connection and its constructor
takes the $SQL as an arg.
So, $SQL = "what is listed above";
$objRecordSet = new RecordSet($SQL);
//I used this all the time with all kinds of other Select, Insert,
Update, and Delete queries and it works perfect.
For one, I don't know how to test whether the table has been created or
not. I know I could probably do some sort of mysql_list_tables and look
for it or whatever but I was looking for something similar to
If (mysql_affected_rows() == -1)
Because that is very easy.
And ideas as to why the table is not being created.
===================
Jonathan Villa
Application Developer
IS Design & Development
www.isdesigndev.com
414.429.0327
===================