Re: DB Create Table help - using Pear DB

From: Date: Wed, 12 Jul 2006 02:09:52 +0000
Subject: Re: DB Create Table help - using Pear DB
References: 1 2  Groups: php.general php.general 
Request: Send a blank email to php-general+get-239334@lists.php.net to get a copy of this message
Jochem Maas wrote:
Scott Heinrichs wrote:
Hello all, This is the first time I have posted an issue to this forum, so please excuse in noob questions or statement. I am trying to create a table from a string that created by a DESCRIBE TABLE query... this is the generated string: CREATE TABLE 'users' ( 'username' varchar(120) NOT NULL primary key, 'password' varchar(64) NOT NULL, 'level' int(11) NOT NULL DEFAULT '0' ) then I use the statement: $db is a PEAR DB object that has been set up with my database access info and connects to MYSQL. $stmt = above create string. $db->query ( $stmt ); for some reason it is not creating the desired table.
    
Im sure the $db object has some error related methods that will give some information as to the problem. some ideas: 1. your using transaction and not commiting after the query 2. the user you connect as doesn't have 'create table' permissions 3. $stmt doesn't contain what you think it does. 4. the SQL is invalid (doesn't look like it though.) no.2 seems most likely.
Can anyone give me a solution or a reason why the above situation would not work. Just to clarify that my Database info is correct I was able to generate the create string from a DESCRIBE TABLE query so the connection works and is valid and I have CREATE rights.
    
Ok... I can log in to the mysql padmin and create a table using the same connection info. I am assuming this would mean that I should have create rights when I connect through my script. I am not 100% on this and I am unable to find out what my GRANT rights are at least not in a timely fashion. My script currently checks for errors and it is not generating any....
$result = $this->db->query( $stmt );
       unset( $stmt );
       if ( PEAR::isError($result) )
       {
           $this->hasError = true;
           $this->errorCount++;
           array_push ( $this->errorMessage, "Error: Unable to create Table in Database" );
           return false;
       }
This is a snippet from my code.... It should catch the error. When I run the script no error is generated. Is there a better or more reliable way to write SQL syntax for creating a table then the one I am using... here it is again: CREATE TABLE 'users' ( 'username' varchar(120) NOT NULL primary key, 'password' varchar(64) NOT NULL, 'level' int(11) NOT NULL DEFAULT '0' ) The above line was captured from an ECHO of the $stmt variable so I know the $stmt is what I expect it to be. I know that I am not using transactions.

« previous php.general (#239334) next »