NYCPHP Meetup

NYPHP.org

[nycphp-talk] Mysql question!

edward potter edwardpotter at gmail.com
Mon Oct 30 18:52:04 EST 2006


The overhead of a table that you may not use is about zero.  Why not
just create the table and assume it's already there. That way you can
forget the test all together.

Just another crazy idea!  :-)

-ed

On 10/30/06, tuon1 at netzero.net <tuon1 at netzero.net> wrote:
>
>
> Hi, everybody!
>
> I want to ask you all to help me out in solving my database question.
>
> Here is what I want to accomplish:
>
> I want to add my users, one by one, to my Mysql database via a registration
> form.
>
> When a user fills out a registration form, my script should gather all the
> information
>
> and add them to the database. I pretty much got all that part working, but I
> want my
>
> script to check to see whether a table exists or not. If it doesn't exist,
> my script
>
> should create a table and then proceed to add the information to the
> database;
>
> and if it does exist, then it should not create one and proceed to use the
> existed table.
>
> 1) Is there a php function that take care of this job that I can use?
>
> I tried to use: if exists(mytablename)
>
> but, it doesn't work.
>
> Here is my code: (some codes are left out for illustration purpose.)
>
> <?php
> include("dbinfo.inc.php");
>   class TableInfo
>        {
>         function _construct()    //A Constructor
>            {
>             /* Initialize database */
>             mysql_connect($localhost,$username,$password);
>             @mysql_select_db($database) or die( "Unable to select
> database");
>             if exists(!Customer_Info)  //Here it doesn't work, error!!!!
>                {
>                 $query = "CREATE TABLE Customer_Info
>                 (
>                  FirstNameCol VARCHAR(15) NOT NULL,
>                  LastNameCol VARCHAR(20) NOT NULL,
>                  AddressCol VARCHAR(40) NOT NULL,
>                  CityCol VARCHAR(20) NOT NULL,
>                  StateCol VARCHAR(20) NOT NULL,
>                  ZipCodeCol INT(5) NOT NULL,
>                  AreaCodeCol INT(3) NOT NULL,
>                  PhoneCol INT(15) NOT NULL,
>                  EmailCol VARCHAR(30) NOT NULL,
>                  LoginNameCol VARCHAR(20) NOT NULL,
>                  PasswordCol VARCHAR(20) NOT NULL
>                 )";
>                 mysql_query($query);
>                }
>
>         //Add new customer to database
>         function AddNewCustomer($FirstName, $LastName, $Address,
>                                 $City, $State, $ZipCode,
>                                 $AreaCode, $Phone, $Email,
>                                 $WebsiteURL, $LoginName, $Password
>                                )
>            {
>                 $query = 'INSERT INTO Customer_Info (FirstNameCol,
>            LastNameCol, AddressCol, CityCol, StateCol,
>                                 ZipCodeCol, AreaCodeCol, PhoneCol,
>                                 EmailCol, WebsiteURLCol,
>            LoginNameCol, PasswordCol
>                                )
>     VALUES ("'. $FirstName . '", "' . $LastName . '",
>                      "' . $Address . '", "' . $City . '",
>       "' . $State . '", "' . $ZipCode . '",
>       "' . $AreaCode . '", "' . $Phone . '",
>       "' . $Email . '",
>       "' . $WebsiteURL . '", "' . $LoginName . '",
>                      "' . SHA1($Password) . '")';
>   }
>
> Feel free to correct my code and give suggestions for better techniques.
>
> Thanks!
>
> Paul
>
>
> _______________________________________________
> 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
>
>
>


-- 
the Blog: http://www.utopiaparkway.com
the Karma: http://www.coderswithconscience.com
the Projects: http://flickr.com/photos/86842405@N00/
the Store: http://astore.amazon.com/httpwwwutopic-20



More information about the talk mailing list