[PHP-DB] CREATE TABLE $phpVariable_for_tableName --- help please!
i cant get this to work right, im building a comments for my blog. im pretty knowledgeable about php code and i am willing to listen, even though im still learning. my code in the php doc is as follows: 1 //select the db 2 $db = mysql_select_db($mydb) or die(db connect error); 3 $newTable = $entryNum + _comms; 4 5 //if posting a comment do this: 6 if ($comms==true) { 7 8 //define a table name based on main Post number 9 10 11 //create a table 12 $sql = 'CREATE TABLE $newTable ( `daUser` VARCHAR( 255 ) NOT NULL ,' 13. ' `entryNumb` INT NOT NULL ,' 14. ' `priv` VARCHAR( 1 ) NOT NULL ,' 15. ' `comm` BLOB NOT NULL ,' 16. ' PRIMARY KEY ( `entryNumb` ) )'; 17 18 19 $resulter = mysql_query($sql) or die(There has been an error creating table: $newTable); 20 21 ---end on line 12 is where ive narrowed the error to. i know that the table name is what is supposed to be there but im trying to create this based on a post entry number and then adding _comms to the name.. so the comments table for post number 1 would be named: 1_comms im also having an issue with line 3, creating that name please help me :) thanks -AJ seelund -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] CREATE TABLE $phpVariable_for_tableName --- help please!
On Wednesday 10 March 2004 15:11, AJ Seelund wrote: 11 //create a table 12 $sql = 'CREATE TABLE $newTable ( `daUser` VARCHAR( 255 ) NOT NULL ,' 13. ' `entryNumb` INT NOT NULL ,' 14. ' `priv` VARCHAR( 1 ) NOT NULL ,' 15. ' `comm` BLOB NOT NULL ,' 16. ' PRIMARY KEY ( `entryNumb` ) )'; 17 18 19 $resulter = mysql_query($sql) or die(There has been an error creating table: $newTable); on line 12 is where ive narrowed the error to. i know that the table name is what is supposed to be there but im trying to create this based on a post entry number and then adding _comms to the name.. Right so echo($sql) to find your error. so the comments table for post number 1 would be named: 1_comms im also having an issue with line 3, creating that name Use the concatenation operator, which is a period (.), a + is the mathematical addition operator. Also, always use mysql_error(). -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-db -- /* Every journalist has a novel in him, which is an excellent place for it. */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] CREATE TABLE problem
Actually, it's more of an order problem: I fixed the SQL already. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, January 22, 2004 4:47 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: RE: [PHP-DB] CREATE TABLE problem I have had similar problems before. I have just created your table in MySQL. Seems you can't have an AUTO_INCREMENT column that is UNSIGNED. Doesn't mention this in the manual though. Neil Morgan -Original Message- From: js [mailto:[EMAIL PROTECTED] Sent: 21 January 2004 22:34 To: [EMAIL PROTECTED] Subject: [PHP-DB] CREATE TABLE problem ok im making this page and every single time i try to execute it, it tells me it was not successful. the database name, user,pw,and local host are all correct. i have no idea what do do, and i have 2 more tables besides this one i wanted to create but this was kind of my template for it and i cant even get it to work. im still really bad with this kind of stuff so any help i could get from you is really appreciated. thanks. here is the code: html head titleUntitled Document/title /head body ?php $host = localhost; $user = user; $password = ; $dbname = swwdb; $link = mysql_connect($host,$user,$password); $query = CREATE TABLE staff ( staffid INT(3) UNSIGNED NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL, login VARCHAR(10) NOT NULL, password VARCHAR(8) NOT NULL, picaddy VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, staffbio TEXT NOT NULL, createdate DATE NOT NULL, tagline VARCHAR(255) NOT NULL, PRIMARY KEY(staffid,login) ); if (mysql_db_query ($dbname,$query,$link)) { print (the query was successfull); } else { print (the query was NOT success); } mysql_close($link); ? /body /html -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.557 / Virus Database: 349 - Release Date: 12/30/2003 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] CREATE TABLE problem
If you're using MySQL, change to this: staffid int(3) unsigned not null auto_increment, The order of the attribute description is important in MySQL. -Original Message- From: js [mailto:[EMAIL PROTECTED] Sent: Thursday, January 22, 2004 6:34 AM To: [EMAIL PROTECTED] Subject: [PHP-DB] CREATE TABLE problem ok im making this page and every single time i try to execute it, it tells me it was not successful. the database name, user,pw,and local host are all correct. i have no idea what do do, and i have 2 more tables besides this one i wanted to create but this was kind of my template for it and i cant even get it to work. im still really bad with this kind of stuff so any help i could get from you is really appreciated. thanks. here is the code: html head titleUntitled Document/title /head body ?php $host = localhost; $user = user; $password = ; $dbname = swwdb; $link = mysql_connect($host,$user,$password); $query = CREATE TABLE staff ( staffid INT(3) NOT NULL AUTO_INCREMENT UNSIGNED, name VARCHAR(255) NOT NULL, login VARCHAR(10) NOT NULL, password VARCHAR(8) NOT NULL, picaddy VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, staffbio TEXT NOT NULL, createdate DATE NOT NULL, tagline VARCHAR(255) NOT NULL, PRIMARY KEY(staffid,login) ); if (mysql_db_query ($dbname,$query,$link)) { print (the query was successfull); } else { print (the query was NOT success); } mysql_close($link); ? /body /html -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] CREATE TABLE problem
I have had similar problems before. I have just created your table in MySQL. Seems you can't have an AUTO_INCREMENT column that is UNSIGNED. Doesn't mention this in the manual though. Neil Morgan -Original Message- From: js [mailto:[EMAIL PROTECTED] Sent: 21 January 2004 22:34 To: [EMAIL PROTECTED] Subject: [PHP-DB] CREATE TABLE problem ok im making this page and every single time i try to execute it, it tells me it was not successful. the database name, user,pw,and local host are all correct. i have no idea what do do, and i have 2 more tables besides this one i wanted to create but this was kind of my template for it and i cant even get it to work. im still really bad with this kind of stuff so any help i could get from you is really appreciated. thanks. here is the code: html head titleUntitled Document/title /head body ?php $host = localhost; $user = user; $password = ; $dbname = swwdb; $link = mysql_connect($host,$user,$password); $query = CREATE TABLE staff ( staffid INT(3) NOT NULL AUTO_INCREMENT UNSIGNED, name VARCHAR(255) NOT NULL, login VARCHAR(10) NOT NULL, password VARCHAR(8) NOT NULL, picaddy VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, staffbio TEXT NOT NULL, createdate DATE NOT NULL, tagline VARCHAR(255) NOT NULL, PRIMARY KEY(staffid,login) ); if (mysql_db_query ($dbname,$query,$link)) { print (the query was successfull); } else { print (the query was NOT success); } mysql_close($link); ? /body /html -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] CREATE TABLE problem
Regarding... -- $query = CREATE TABLE staff ( -- staffid INT(3) NOT NULL AUTO_INCREMENT UNSIGNED, -- name VARCHAR(255) NOT NULL, -- login VARCHAR(10) NOT NULL, -- password VARCHAR(8) NOT NULL, -- picaddy VARCHAR(255) NOT NULL, -- email VARCHAR(255) NOT NULL, -- staffbio TEXT NOT NULL, -- createdate DATE NOT NULL, -- tagline VARCHAR(255) NOT NULL, -- PRIMARY KEY(staffid,login) ); The problem with the above create table query is the _placement_ of the UNSIGNED keyword. Rather than: staffid INT(3) NOT NULL AUTO_INCREMENT UNSIGNED, try: staffid INT(3) UNSIGNED NOT NULL AUTO_INCREMENT, The second worked for me while the first threw the previously reported SQL Syntax error. HTH, David
Re: [PHP-DB] CREATE TABLE problem
hmm ... I have unsigned auto_increment fields in all my tables that use unique field IDs... But i use very long counter fields as it's pretty big tables I have (or gonna be once I get them finished)... FWIW Rene Fate would have it, that on Thu, 22 Jan 2004 08:47:01 -, [EMAIL PROTECTED] wrote: I have had similar problems before. I have just created your table in MySQL. Seems you can't have an AUTO_INCREMENT column that is UNSIGNED. Doesn't mention this in the manual though. Neil Morgan Rene Brehmer aka Metalbunny http://metalbunny.net/ References, tools, and other useful stuff... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] CREATE TABLE problem
ok im making this page and every single time i try to execute it, it tells me it was not successful. the database name, user,pw,and local host are all correct. i have no idea what do do, and i have 2 more tables besides this one i wanted to create but this was kind of my template for it and i cant even get it to work. im still really bad with this kind of stuff so any help i could get from you is really appreciated. thanks. here is the code: html head titleUntitled Document/title /head body ?php $host = localhost; $user = user; $password = ; $dbname = swwdb; $link = mysql_connect($host,$user,$password); $query = CREATE TABLE staff ( staffid INT(3) NOT NULL AUTO_INCREMENT UNSIGNED, name VARCHAR(255) NOT NULL, login VARCHAR(10) NOT NULL, password VARCHAR(8) NOT NULL, picaddy VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, staffbio TEXT NOT NULL, createdate DATE NOT NULL, tagline VARCHAR(255) NOT NULL, PRIMARY KEY(staffid,login) ); if (mysql_db_query ($dbname,$query,$link)) { print (the query was successfull); } else { print (the query was NOT success); } mysql_close($link); ? /body /html
Re: [PHP-DB] CREATE TABLE problem
mysql_db_query ($dbname,$query,$link) or die(myself_error()); will help you more than your if/then statement.. change that, and check out the error message. On Wed January 21 2004 2:33 pm, js wrote: ok im making this page and every single time i try to execute it, it tells me it was not successful. the database name, user,pw,and local host are all correct. i have no idea what do do, and i have 2 more tables besides this one i wanted to create but this was kind of my template for it and i cant even get it to work. im still really bad with this kind of stuff so any help i could get from you is really appreciated. thanks. here is the code: html head titleUntitled Document/title /head body ?php $host = localhost; $user = user; $password = ; $dbname = swwdb; $link = mysql_connect($host,$user,$password); $query = CREATE TABLE staff ( staffid INT(3) NOT NULL AUTO_INCREMENT UNSIGNED, name VARCHAR(255) NOT NULL, login VARCHAR(10) NOT NULL, password VARCHAR(8) NOT NULL, picaddy VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, staffbio TEXT NOT NULL, createdate DATE NOT NULL, tagline VARCHAR(255) NOT NULL, PRIMARY KEY(staffid,login) ); if (mysql_db_query ($dbname,$query,$link)) { print (the query was successfull); } else { print (the query was NOT success); } mysql_close($link); ? /body /html -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] CREATE TABLE problem redefined
ok i did the mysql_error DIE thing, and now it tells me this: You have an error in your SQL syntax near 'UNSIGNED, name VARCHAR(255) NOT NULL, login VARCHAR(10) NOT NULL, password' at line 2 i have no idea what it means. i dont think any of those are taken or reserved by PHP or mySQL. any further help would be great. thank you. -james
Re: [PHP-DB] CREATE TABLE problem redefined
js wrote: You have an error in your SQL syntax near 'UNSIGNED, name VARCHAR(255) NOT NULL, login VARCHAR(10) NOT NULL, password' at line 2 Print (echo) out your entire query. You have a syntax error before the point the error message mentions. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] CREATE TABLE LIKE, error
I cannot use this query CREATE TABLE table LIKE other_table; , which is supposed to create an empty clone of the other_table named table. Was it added in some later MySQL version? It's in the manual on mysql.com, bo no version info available. -- Seks, seksi, seksolatki... news:pl.soc.seks.moderowana http://hyperreal.info { iWanToDie } WiNoNa) ( http://szatanowskie-ladacznice.0-700.pl foReVeR( * ) Poznaj jej zwiewne ksztaty... http://www.opera.com 007 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] CREATE TABLE LIKE, error
Try: CREATE table new_table SELECT * from old_table limit 1; delete from new_table; This will give you the same structure in both tables, and the deletion will make the new_table empty. -Original Message- From: Adam i Agnieszka Gasiorowski FNORD [mailto:[EMAIL PROTECTED] Sent: Monday, December 15, 2003 10:28 AM To: Lista PHP DB Subject: [PHP-DB] CREATE TABLE LIKE, error I cannot use this query CREATE TABLE table LIKE other_table; , which is supposed to create an empty clone of the other_table named table. Was it added in some later MySQL version? It's in the manual on mysql.com, bo no version info available. -- Seks, seksi, seksolatki... news:pl.soc.seks.moderowana http://hyperreal.info { iWanToDie } WiNoNa) ( http://szatanowskie-ladacznice.0-700.pl foReVeR( * ) Poznaj jej zwiewne ksztaty... http://www.opera.com 007 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] CREATE TABLE LIKE, error
From: Adam i Agnieszka Gasiorowski FNORD [EMAIL PROTECTED] I cannot use this query CREATE TABLE table LIKE other_table; , which is supposed to create an empty clone of the other_table named table. Was it added in some later MySQL version? It's in the manual on mysql.com, bo no version info available. Sure there is, you just had to keep reading. Quote: In MySQL 4.1, you can also use LIKE to create a table based on the definition of another table, including any column attributes and indexes the original table has: CREATE TABLE new_tbl LIKE orig_tbl; CREATE TABLE ... LIKE does not copy any DATA DIRECTORY or INDEX DIRECTORY table options that were specified for the original table. Since this is a PHP list, an alternative, two-step method is to issue a SHOW CREATE TABLE Table_Name query, retrieve the results, and use them to create your second table (replacing the table name, of course). ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] CREATE TABLE LIKE, error
From: Gary Every [EMAIL PROTECTED] Try: CREATE table new_table SELECT * from old_table limit 1; delete from new_table; This will give you the same structure in both tables, and the deletion will make the new_table empty. Not quite the same as it will not copy indexes/keys... ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] CREATE TABLE LIKE, error
CPT John W. Holmes wrote: From: Adam i Agnieszka Gasiorowski FNORD [EMAIL PROTECTED] I cannot use this query CREATE TABLE table LIKE other_table; , which is supposed to create an empty clone of the other_table named table. Was it added in some later MySQL version? It's in the manual on mysql.com, bo no version info available. Sure there is, you just had to keep reading. Quote: In MySQL 4.1, you can also use LIKE to create a table based on the definition of another table, including any column attributes and indexes the original table has: Ah, I missed it. Do you know what is an estimate for 4.1 to go stable? CREATE TABLE new_tbl LIKE orig_tbl; CREATE TABLE ... LIKE does not copy any DATA DIRECTORY or INDEX DIRECTORY table options that were specified for the original table. Since this is a PHP list, an alternative, two-step method is to issue a SHOW CREATE TABLE Table_Name query, retrieve the results, and use them to create your second table (replacing the table name, of course). Thank you very much. -- Seks, seksi, seksolatki... news:pl.soc.seks.moderowana http://hyperreal.info { iWanToDie } WiNoNa) ( http://szatanowskie-ladacznice.0-700.pl foReVeR( * ) Poznaj jej zwiewne ksztaty... http://www.opera.com 007 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Create table
I am trying to use PHP to create a table ( 5 wide by X long ) , with pictures in a directory, and have not been able to find this information. There are about 33 picture in a specific directory, and I would like to just read them in and create a table when the link is click. Can someone point me in the right direction ? Larry Sandwick Sarreid, Ltd. Network/System Administrator phone: (252) 291-1414 x223 fax : (252) 237-1592
[PHP-DB] Create table example
Good afternoon!! I have several (50+) tables I have to create in MySql. Is there a good PHP example on creating a table via PHP?? I will probably do all of the initial INSERTS that way, too. Thanks!! Robin Kopetzky Black Mesa Computer/Internet Services www.blackmesa-isp.net
RE: [PHP-DB] Create table example
I have several (50+) tables I have to create in MySql. Is there a good PHP example on creating a table via PHP?? I will probably do all of the initial INSERTS that way, too. You don't create a table via PHP, you simply pass a query through the mysql_query() function. If that query is a CREATE TABLE, then a table will be created. It can also be a INSERT, SELECT, SHOW, UPDATE, etc... All you're doing is passing a string through mysql_query() that MySQL is going to attempt to run as a query. So, for you, you'd need to use: Mysql_query(CREATE TABLE ... ); Mysql_query(INSERT INTO ... VALUES ... ); Fill in the blanks... Now, if you have all of these queries in a file, there may be an easier way to automate all of this, but you'll be doing the same thing, essentially. You can only pass one query at a time with mysql_query(). ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] CREATE TABLE QUERY PHP/MySQL
answers inline Ignatius - Original Message - From: Jonathan [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, December 06, 2002 10:39 PM Subject: RE: [PHP-DB] CREATE TABLE QUERY PHP/MySQL Granting access makes sense. Now what is the difference between the user information I put into the mysql_connect function and PHP user? one and same thing. If there is a difference , how would I grant the access via a query and how would it affect the new users who will use the application when it is given to my client? Also, a preview reply mentioned mysql_error(). How would I use function to verify that the table was created? Do I simply write If (mysql_error() != ) Return false A typical way to use it is mysql_***( *** ) or die( mysql_error() ) ; -Original Message- From: Ignatius Reilly [mailto:[EMAIL PROTECTED]] Sent: Friday, December 06, 2002 3:34 PM To: [EMAIL PROTECTED] Subject: Re: [PHP-DB] CREATE TABLE QUERY PHP/MySQL Very likely you have to GRANT the CREATE permission to your PHP user account. Also investigate the CREATE TEMPORARY TABLE grant status available since version 4+. Very convenient. Ignatius - Original Message - From: Jonathan [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, December 06, 2002 10:00 PM Subject: [PHP-DB] CREATE TABLE QUERY PHP/MySQL 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 === -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] CREATE TABLE QUERY PHP/MySQL
On Saturday 07 December 2002 05:00, Jonathan wrote: 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. mysql_error() to see what the problem is. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* ...and the fully armed nuclear warheads, are, of course, merely a courtesy detail. */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] CREATE TABLE QUERY PHP/MySQL
Very likely you have to GRANT the CREATE permission to your PHP user account. Also investigate the CREATE TEMPORARY TABLE grant status available since version 4+. Very convenient. Ignatius - Original Message - From: Jonathan [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, December 06, 2002 10:00 PM Subject: [PHP-DB] CREATE TABLE QUERY PHP/MySQL 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 === -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] CREATE TABLE QUERY PHP/MySQL
Granting access makes sense. Now what is the difference between the user information I put into the mysql_connect function and PHP user? If there is a difference , how would I grant the access via a query and how would it affect the new users who will use the application when it is given to my client? Also, a preview reply mentioned mysql_error(). How would I use function to verify that the table was created? Do I simply write If (mysql_error() != ) Return false -Original Message- From: Ignatius Reilly [mailto:[EMAIL PROTECTED]] Sent: Friday, December 06, 2002 3:34 PM To: [EMAIL PROTECTED] Subject: Re: [PHP-DB] CREATE TABLE QUERY PHP/MySQL Very likely you have to GRANT the CREATE permission to your PHP user account. Also investigate the CREATE TEMPORARY TABLE grant status available since version 4+. Very convenient. Ignatius - Original Message - From: Jonathan [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, December 06, 2002 10:00 PM Subject: [PHP-DB] CREATE TABLE QUERY PHP/MySQL 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 === -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Create Table with AutoIncrement-field in M$ AccessDB
I try to make a new table using PHP4 M$ Access (via ADODB). This is the code I use: //begin DB-connection to create table $db_connection = new COM(ADODB.Connection); $db_connstr = driver={Microsoft Access Driver (*.mdb)}; DBQ=. realpath(database.mdb) . ;DefaultDir=. realpath(); $db_connection-open($db_connstr); $table = CREATE TABLE $pad (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, name TEXT(30), email TEXT(30), http TEXT(30), icq TEXT(15), message MEMO, adddate TEXT(15), ip TEXT(15), location TEXT(35), browser TEXT(55), comment TEXT(255), rating INT NOT NULL ); $result = $db_connection-execute($table); $db_connection-Close(); //end DB-connection to create table when I delete the AUTO_INCREMENT-part, the table is created properly, exept for the fact that the 'id' is NOT autoincrement. Does anyone have a solution (or workaround) Tnanx Aikie -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Create Table from a file in php
Dave, From the MySLQ manual : DROP TABLE [IF EXISTS] tbl_name [, tbl_name,...] [RESTRICT | CASCADE], but I don't know if it would work in a mysql_query(). Alternately, use mysql_tables() and mysql_tablename, and parse the results to determine if the table exists. If it does, use ALTER TABLE I guess. I've had the luxury of being able to do this at the console, not through a script. Not exactly nuggets, but hope it's helpful - Miles At 09:15 AM 1/12/2002 +, Dave Carrera wrote: Miles You got me thinking so of i went and produced this working block of code. ?include('./i_inc/dbcon.php'); // db connection file location $sqlfile = ./i_inc/members.php; // location of sql file $readsql =@fopen($sqlfile, r) or die (SQL file dosn't excist); $sqlsql = fread($readsql,filesize($sqlfile)); mysql_query($sqlsql) or die (members not created or already excists); fclose($readsql); ? This works perfectly but i have one thing i have been trying to solve for the last two days. Some kind of if table excist loop is required. For the life of me i can't seem to get this info any where. 5 Books, 20+ websites and no closer:-( Can you throw some nugets of wisdom this way. Please. Thanks for the help and i hope the included code sample can help someone else. Thanks Dave C -Original Message- From: Miles Thompson [mailto:[EMAIL PROTECTED]] Sent: 11 January 2002 18:49 To: Dave Carrera; [EMAIL PROTECTED] Subject: Re: [PHP-DB] Create Table from a file in php I don't know how you would do it from a file off the top of my head, so let's invent it, in pseudocode, anyway. The important thing to remember is that all of the commands to create or alter tables / databases are SQL queries. So the mysql_query() function is used to do most of the work. Assumptions: We have the database We have a connection to it We have the proper user/password for creation rights. We have a file with the necessary SQL to create a tablle : CREATE TABLE . etc., with no trailing semi-colon. pseudo code .. Open the file get the file handle Read it all as one chunk, assigning it to a variable, say $sql. If the SQL is broken into lines the file will have to be read and concatenated to the variable. Use the variable in a mysql_query, testing for success. Issue a mysql_list_tables to see that you have the new tables, if that's successful a list_fields for the new table. Refinements . things to check ... 1. Maybe check for the existence of the table and drop it before you create it. That can be done as a mysql_query. 2. You may need to add an opening double-quote and a closing double-quote to what you are assigning to $sql. Offhand, I think not. Alternate approach, although you probably don't have the necessary permission on the server would be to exec( mysql database_name file_containing_table_creation_code); I hope you find this helpful - Miles Thompson At 10:57 AM 1/11/2002 +, Dave Carrera wrote: Hi All I want to create a table from a file that contains the sql to create the table. I have checked Mysql.com and have seen how to do it from telnet, but i want to do it from a php script. Can anyone please help. Thanks in Advance Dave C The two rules for success are: 1. Never tell them everything you know. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Create Table from a file in php
Hi All I want to create a table from a file that contains the sql to create the table. I have checked Mysql.com and have seen how to do it from telnet, but i want to do it from a php script. Can anyone please help. Thanks in Advance Dave C The two rules for success are: 1. Never tell them everything you know. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Create Table from a file in php
I don't know how you would do it from a file off the top of my head, so let's invent it, in pseudocode, anyway. The important thing to remember is that all of the commands to create or alter tables / databases are SQL queries. So the mysql_query() function is used to do most of the work. Assumptions: We have the database We have a connection to it We have the proper user/password for creation rights. We have a file with the necessary SQL to create a tablle : CREATE TABLE . etc., with no trailing semi-colon. pseudo code .. Open the file get the file handle Read it all as one chunk, assigning it to a variable, say $sql. If the SQL is broken into lines the file will have to be read and concatenated to the variable. Use the variable in a mysql_query, testing for success. Issue a mysql_list_tables to see that you have the new tables, if that's successful a list_fields for the new table. Refinements . things to check ... 1. Maybe check for the existence of the table and drop it before you create it. That can be done as a mysql_query. 2. You may need to add an opening double-quote and a closing double-quote to what you are assigning to $sql. Offhand, I think not. Alternate approach, although you probably don't have the necessary permission on the server would be to exec( mysql database_name file_containing_table_creation_code); I hope you find this helpful - Miles Thompson At 10:57 AM 1/11/2002 +, Dave Carrera wrote: Hi All I want to create a table from a file that contains the sql to create the table. I have checked Mysql.com and have seen how to do it from telnet, but i want to do it from a php script. Can anyone please help. Thanks in Advance Dave C The two rules for success are: 1. Never tell them everything you know. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] create table with php -whats wrong?
Hello all. I am trying to create simple test table with php, but I get: Parse error: parse error in /home/vanesaw/public_html/create.php on line 5 Line 5 is command to create table (see code below). Whats wrong with it? Thanks. ? $sql = mysql_connect(host, login, pass); mysql_select_db(dbname); CREATE TABLE test (id TINYINT not null AUTO_INCREMENT, process LONGTEXT not null , title LONGTEXT not null , description LONGTEXT not null , PRIMARY KEY (id)); ? done -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] create table with php -whats wrong?
Hello all. I am trying to create simple test table with php, but I get: Parse error: parse error in /home/vanesaw/public_html/create.php on line 5 Line 5 is command to create table (see code below). Whats wrong with it? Thanks. ? $sql = mysql_connect(host, login, pass); mysql_select_db(dbname); CREATE TABLE test (id TINYINT not null AUTO_INCREMENT, process LONGTEXT not null , title LONGTEXT not null , description LONGTEXT not null , PRIMARY KEY (id)); ? done Saulius, http://www.php.net/manual/en/function.mysql-query.php =dn -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] create table with php -whats wrong?
Place your query in a string variable, like $sSql, and use the mysql_query command to execute the query. For example: $sSql=CREATE TABLE test (id TINYINT not null AUTO_INCREMENT, process LONGTEXT not null , title LONGTEXT not null , description LONGTEXT not null , PRIMARY KEY (id)); if (!mysql_query($sSql)) die (Could not create table); At 02:57 PM 10/28/2001, Saulius Jankauskas wrote: Hello all. I am trying to create simple test table with php, but I get: Parse error: parse error in /home/vanesaw/public_html/create.php on line 5 Line 5 is command to create table (see code below). Whats wrong with it? Thanks. ? $sql = mysql_connect(host, login, pass); mysql_select_db(dbname); CREATE TABLE test (id TINYINT not null AUTO_INCREMENT, process LONGTEXT not null , title LONGTEXT not null , description LONGTEXT not null , PRIMARY KEY (id)); ? done -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] Sliante, Richard S. Crawford http://www.mossroot.com mailto:[EMAIL PROTECTED] AIM: Buffalo2K ICQ: 11646404 Y!: rscrawford It is only with the heart that we see rightly; what is essential is invisible to the eye. --Antoine de Saint Exupéry Push the button, Max! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]