TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-05-2008, 12:48 PM   #1 (permalink)
The Wanderer
 
paulOr's Avatar
 
Join Date: Nov 2007
Location: Edinburgh
Posts: 21
Thanks: 1
paulOr is on a distinguished road
Default Text -> SQL parser

Im looking for a way to enter information into a text box like this:

Code:
table: users {
   user:VARCHAR;255;
   passwd:VARCHAR;255;
   url:VARCHAR;35;
}
and it will spit out IN TEXT ONLY, NO DATABASE INTERACTION AT ALL. the following:

Code:
CREATE TABLE `users` (
`user` VARCHAR( 255 ) NOT NULL ,
`pass` VARCHAR( 255 ) NOT NULL ,
`url` VARCHAR( 32 ) NOT NULL ,
) ENGINE = MYISAM
anyone know of a class that does this or knows of a simple way to do it ?
paulOr is offline  
Reply With Quote
Old 03-05-2008, 02:18 PM   #2 (permalink)
The Acquainted
 
Join Date: Nov 2007
Posts: 154
Thanks: 31
SOCK is on a distinguished road
Default

The only thing that comes to mind is the PEAR SQL_Parser package, and it looks like the documentation is so sparse I can't tell if it comes close to doing what you're looking for.
__________________
I reject your reality, and substitute my own.
SOCK is offline  
Reply With Quote
Old 03-05-2008, 03:07 PM   #3 (permalink)
The Contributor
 
abiko's Avatar
 
Join Date: Feb 2008
Location: Croatia
Posts: 90
Thanks: 4
abiko is on a distinguished road
Default

Here is a snippet that would use your purpose, but in different format..
So your table data would look like this
Code:
table:users|user:VARCHAR;255;NOT NULL,passwd:VARCHAR;128;NOT NULL
:/
PHP Code:
<?php

$t 
"table:users|user:VARCHAR;255;NOT NULL,passwd:VARCHAR;128;NOT NULL";

$d    =    explode'|'$t );

$_table    =    explode':'$d['0']);
$tableName    =    $_table['1'];

$sql    =    "CREATE TABLE ".$tableName." ( \n";

$rows     =    explode','$d['1']);

$c count$rows)-1;
$count 0;
foreach( 
$rows as $_n => $row ) {
        
        
$sql .= "\t";
        
$_ro =    explode':'$row);
        
$fieldName    =    $_ro['0'];
        
$fieldOpt        =    $_ro['1'];        
        
$fields    =    explode';'$fieldOpt);
        
$sql .= "".$fieldName." ".$fields['0']." (".$fields['1']." ) ".$fields['2'];        
        if ( 
$count $c ) {
            
$sql .= ",";
        }    
        
$sql .= "\n";
        
$count++;
}
$sql .= ")ENGINE = MYISAM;";

echo 
$sql;

?>
Outputs:
Code:
CREATE TABLE users ( 
	user VARCHAR (255 ) NOT NULL,
	passwd VARCHAR (128 ) NOT NULL
)ENGINE = MYISAM;
__________________
Back from sysadmins to the programmers.
Send a message via ICQ to abiko Send a message via MSN to abiko
abiko is offline  
Reply With Quote
Old 03-05-2008, 03:25 PM   #4 (permalink)
The Acquainted
 
Gareth's Avatar
 
Join Date: Jan 2008
Posts: 136
Thanks: 4
Gareth is on a distinguished road
Default

As abiko says; one has to realise that php doesn't worry about whitespace. Therefore, if you use something (other than a ,) to seperate the different parts of the string you can then use explode and echo them out.
Gareth is offline  
Reply With Quote
Old 03-05-2008, 04:42 PM   #5 (permalink)
The Contributor
 
DeMo's Avatar
 
Join Date: Jan 2008
Location: Brazil
Posts: 77
Thanks: 14
DeMo is on a distinguished road
Default

You could use XML too.. makes it a lot easier to parse.

Code:
<table name="users">
  <column name="user" type="VARCHAR" size="255" />
  <column name="passwd" type="VARCHAR" size="255" />
  <column name="url" type="VARCHAR" size="35" />
</table>
Send a message via ICQ to DeMo Send a message via MSN to DeMo Send a message via Skype™ to DeMo
DeMo is offline  
Reply With Quote
Old 03-05-2008, 04:44 PM   #6 (permalink)
The Contributor
 
abiko's Avatar
 
Join Date: Feb 2008
Location: Croatia
Posts: 90
Thanks: 4
abiko is on a distinguished road
Default

DeMo you are right, XML is a better solution :)
Simpler parsing, especially if you are using PHP5 (simpleXML) so no hassle there :)
__________________
Back from sysadmins to the programmers.
Send a message via ICQ to abiko Send a message via MSN to abiko
abiko is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 09:11 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design