[nycphp-talk] Creating database tables when deploying products
Paul Houle
paul at devonianfarm.com
Sat Mar 31 22:05:59 EDT 2007
Ben Sgro (ProjectSkyline) wrote:
>
> $sqlStr = "CREATE TABLE admin "
> . " (id int(11) NOT NULL auto_increment,"
> . " username varchar(64) default '',"
> . " password varchar(64) default '',"
> . " last_login int(12) default 0,"
> . " primary key(id, username)"
> . ')';
> DBAS_MySQLQuery($sqlStr, $db);
Not too bad, but PHP isn't Java. you can write multi-line string
literals.
$sqlStr = "
CREATE TABLE admin (id int(11) NOT NULL auto_increment,
username varchar(64) default,
password varchar(64) default ','
last_login int(12) default 0,
primary key(id, username)
)";
More readable, less painful. I'm thinking about this stuff too.
There are lots of people who are addicted to visual tools like the
"Enterprise Manager" that comes with Microsoft SQL Server. These have
their place, but you really should be writing DDL (CREATE TABLE, etc.)
if you want consistent results. Historically, I've written schema
files into *.sql files that can be
* cut and pasted into the MS-SQL "Query Analyser", or
* mysql -uuser -p db_name < load_schema.sql
The cross database thing is making me think about a different
answer. Also lately I've been creating large numbers of repetitive
tables, or groups of tables that all have certain columns (timestamps,
for instance)
When it comes to cross database, however, you ought to think about
the business goal you're after. It's pretty silly to support all 20 or
so relational databases that PHP can connect to. Most organizations,
however, will have a few databases that are reasonable targets:
* Mysql and MS-SQL: the kind of shop that likes to have it both ways
with Microsoft and Open Source. You can ship apps that will keep most
people happy.
* Mysql and Oracle: good for the Unix shop which has both
entrepreneurial projects (install Linux, start coding) and 'enterprise'
systems (ask your boss to ask her boss to ask his boss to ask the DBA to
make you a table)
* Postgresql and MySQL: if you want to please all the open source people
you meet
More information about the talk
mailing list