NYCPHP Meetup

NYPHP.org

[nycphp-talk] Database creation (YAML VS hard coded PHP)

Ben Sgro (ProjectSkyLine) ben at projectskyline.com
Mon Oct 29 08:47:44 EDT 2007


Hello PJ,

It is, only because I may not have CL access to certain hosts.

I've thought about using a sql file and a few people have mentioned
that too me as well.

I guess I need to have flexiblity.

- Ben

Ben Sgro, President
ProjectSkyLine - Defining New Horizons
+1 718.487.9368 (N.Y. Office)

Our company: www.projectskyline.com
Our products: www.project-contact.com

This e-mail is confidential information intended only for the use of the 
individual to whom it is addressed.
----- Original Message ----- 
From: "P. Ju (朱漢璇)" <pjlists at pobox.com>
To: "NYPHP Talk" <talk at lists.nyphp.org>
Sent: Sunday, October 28, 2007 12:13 PM
Subject: Re: [nycphp-talk] Database creation (YAML VS hard coded PHP)


> Hi Ben,
>
> Is it a requirement that you use PHP? MySQL database
> creation/modification can be scripted by running mysql with the -e
> switch and passing it a file containing SQL commands. I also add -vvv
> to give me verbose output.
>
> PJ
>
> On 10/28/07, Ben Sgro (ProjectSkyLine) <ben at projectskyline.com> wrote:
>>
>>
>> Hello all,
>>
>>
>> #1 Thanks for the ideas on CSS (my last question). I still haven't been 
>> able
>> to invest the type of time
>> I would like to play around with the code, but I will. I got the CSS 
>> Mastery
>> book and I've got an APress
>> book on HTML/CSS design patterns. Both look promising.
>>
>> I started off doing db deployment code in a seperate file, say 
>> createdb.php
>> that I would run from
>> the URL.
>>
>> include ('PROS.php');
>>     include ('../LIBRARY/DBAS.php');
>>
>>     DBAS_InitDBHandle(PROS_SQLInfo( ), 'PROS.php', $db);
>>     DBAS_MySQLUseDB(constPROSDBStr, $db);
>>
>>     $tableSet = DBAS_FetchTables(constPROSDBStr, $db);
>>     if ( @ !$tableSet[constContentStr])
>>     {
>>         error_log("createdb.php: creating 'content' table");
>>         $sqlStr = "CREATE TABLE content "
>>                 . "(id int(11) NOT NULL auto_increment,"
>>                 . " display_on    int(11) default 0,"
>>                 . " title         varchar(64)   default '',"
>>                 . " body          text(8192) default '',"
>>                 . " thumb_img     varchar(64)   default '',"
>>                 . " page_img_1    varchar(64)   default '',"
>>                 . " page_img_2    varchar(64)   default '',"
>>                 . " img_1_caption  varchar(64)   default '',"
>>                 . " img_2_caption  varchar(64)   default '',"
>>                 . " img_1_alt      varchar(64)   default '',"
>>                 . " img_2_alt      varchar(64)   default '',"
>>                 . " page_position varchar(32)   default '',"
>>                 . " link          varchar(64)   default '',"
>>                 . " primary key(id)"
>>                 . ')';
>>         DBAS_MySQLQuery($sqlStr, $db);
>>     }
>>
>> After a while, that was kinda of a pain and I moved to something internal 
>> to
>> the index.php?action=create_database file
>> and cleaned up my database object code.
>>
>>         /* Comments table. */
>>
>> $dbObject->DatabaseCreateTable(DATABASE_TABLE_COMMENTS);
>>         $dbObject->DatabaseCreateField('comment_id',
>> 'int(11)', 'NOT NULL',
>>                                        'auto_increment');
>>         $dbObject->DatabaseCreateField('video_id',
>> 'int(11)',     DEF_0);
>>         $dbObject->DatabaseCreateField('posted_time',
>> 'varchar(32)', DEF_0);
>>         $dbObject->DatabaseCreateField('posted_by',   $v64,
>>          $defE);
>>         $dbObject->DatabaseCreateField('comment',
>> 'varchar(512)',$defE);
>>         $dbObject->DatabaseCreateField('primary',
>> 'key(comment_id)');
>>         $dbObject->DatabaseCreateCommit(LOG_LEVEL_DEBUG);
>>
>> Which I used for a while and I liked it. Except its a lot to type for 
>> larger
>> databases.
>> So I started messing with YAML and I've got my code down to this:
>>
>> emails:
>>     id:
>>         type:    int(11)
>>         default: not null
>>         extra:   auto_increment
>>     email:
>>         type:    varchar(255)
>>         default: default 0
>>         extra:
>>     contacted:
>>         type:    tinyint(1)
>>         default: default 0
>>         extra:
>>     primary:
>>         type:    key(id, email)
>>         default: ""
>>         extra:
>>
>> Which I just feed into a method that creates the table. I have this code
>> only execute
>> when I pass a command line switch in, say php index.php -f db.yaml. If I
>> don't have
>> CL access then I'd have to move it to the URL.
>>
>> Do you all think agree this is a better direction ? What are some 
>> pitfalls I
>> could run into
>> doing db's this way?
>>
>> Thanks so much!
>>
>> - Ben
>>
>> Ben Sgro, President
>> ProjectSkyLine - Defining New Horizons
>> +1 718.487.9368 (N.Y. Office)
>>
>> Our company: www.projectskyline.com
>> Our products: www.project-contact.com
>>
>> This e-mail is confidential information intended only for the use of the
>> individual to whom it is addressed.
>> _______________________________________________
>> New York PHP Community Talk Mailing List
>> http://lists.nyphp.org/mailman/listinfo/talk
>>
>> NYPHPCon 2006 Presentations Online
>> http://www.nyphpcon.com
>>
>> Show Your Participation in New York PHP
>> http://www.nyphp.org/show_participation.php
>>
>
>
> -- 
> Patricia Ju
> phj at pobox.com
> +1-646-717-3871
>
> success = fn(perseverance)
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php 




More information about the talk mailing list