How It Works Every PHP script that needs (Web hosting providers)
How It Works Every PHP script that needs to access your database on the MySQL server will include config.php. These constants will be used in your scripts to gain access to your database. By putting them here, in one file, you can change the values any time you move servers, change the name of the database, or change your username or password. Any time you have information or code that will be used in more than one PHP script, you should include it in a separate file. That way, you ll only need to make your changes in one location. define( SQL_HOST , localhost ); define( SQL_USER , bp5am ); define( SQL_PASS , bp5ampass ); define( SQL_DB , comicsite ); The make_tables.php file is a one-time script: You should never have to run it again, unless you needed to drop all of your tables and re-create them. So, rather than explain all of the code in the page, we ll just look at one of the SQL statements: CREATE TABLE IF NOT EXISTS char_main ( id int(11) NOT NULL auto_increment, alias varchar(40) NOT NULL default , real_name varchar(80) NOT NULL default , lair_id int(11) NOT NULL default 0, align enum( good , evil ) NOT NULL default good , PRIMARY KEY (id) ) The syntax for creating a table in MySQL is the following: CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,…)] [table_options] [select_statement] Obviously, you are not using the TEMPORARY keyword, because you want this table to be permanent and exist after your connection with the database. You are using the IF NOT EXISTS keyword, but only if this page is loaded twice. If you attempt to load the page again, MySQL will not attempt to re-create the tables and will not generate an error. The table name in this case is char_main. The columns the script creates are id, alias, real_name, lair_id, and alias, which are the names we came up with earlier. Let s look at each column: . id int(11) NOT NULL auto_increment: The id column is set as an integer, with 11 maximum places. An integer datatype can contain the values -2147483648 to 2147483648. A sharp observer would note that the max value is only 10 digits. The eleventh digit is for negative values. NOT NULL will force a value into the column. With some exceptions, numeric columns will default to 0, and string columns will default to an empty string ( ). Very rarely will you allow a column to carry a NULL value. 288 Chapter 10
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.