logo
g Text Version
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Sports
Travel & Culture
TV & Movies

dailyclick
Bored? Games!
Nutrition
Postcards
Take a Quiz
Rate My Photo

new
European Travel
Action Movies
Bible Basics
Houseplants
Romance Movies
Creativity
Family Travel


dailyclick
All times in EST

Full Schedule
g
g PHP Site

BellaOnline's PHP Editor

g

Personal Activities Calendar Program Use the strtotime and mysql_select_db Functions - 2

Guest Author - Diane Cipollo

Connect to Database

In a previous tutorial, you learned how to create a customized config.php3 file which contained four pieces of information (name of your host server, your username, your password and the name of your database). Remember that we initialized the $host, $username, $password and $name_of_database variables in this config.php3 file. You have probably noticed that the config.php3 file is called into the program at the top of the ActivityEntry.php3 script with the require_once statement.

require_once('config.php3');

Now that we have those variables initialized and feed into the program, we need to identify our ActivityEntry.php3 script to the MySQL server. You learned how to do this with the @mysql_connect( ) function in another previous tutorial. We used the variables from the config file in the @mysql_connect statement.

$connection =
@mysql_connect("$host", "$username", "$password")
or die ("Could not connect to the database
at this time. Please try later.");
Note--The arrow indicates that the code is wrapped to a second line and should really be all on one line.

Now we will add something new. We will add another function statement that will tell the MySQL server which database we wish to use. This second statement is the mysql_select_db( ) function.

$db =
@mysql_select_db($name_of_database, $connection)
or die("Could not connect to the database
at this time. Please try later.");
Note--The arrow indicates that the code is wrapped to a second line and should really be all on one line.

As you can see this statement uses two variables ($name_of_database and $connection). We initialized the $name_of_database variable to "calendar" in the config.php3 file. The $connection variable was created in the mysql_connect( ) statement above it. Also, we reused some of the things you learned in the previous tutorial. The mysql_select_db( ) function uses the @ to suppress the default error message and the die( ) statement to customized an error message for the possibility that we cannot connect to the database.

Take a look at the finished changes to the ActivityEntry.php3 script. Now we are ready to work on the INSERT statement in the next tutorial.

Note--The purpose of this tutorial is to build a Personal Activities Calendar Program for personal use and teach the basics of PHP and MySQL databases. I have not included any security features such as preventing malicious input data. That would make this tutorial too complicated for the novice. If you were creating a program for the web, you would want to include such security in your program code.

← Back




      A Custom Configuration File For PHP Programs
      How to Connect to the MySQL Server with the PHP mysql_connect Function

      The PHP Strtotime Function

This site needs an editor - click to learn more!

Add Personal+Activities+Calendar+Program+%96+Use+the+strtotime+and+mysql%5Fselect%5Fdb+Functions+%2D+2 to Twitter Add Personal+Activities+Calendar+Program+%96+Use+the+strtotime+and+mysql%5Fselect%5Fdb+Functions+%2D+2 to Facebook Add Personal+Activities+Calendar+Program+%96+Use+the+strtotime+and+mysql%5Fselect%5Fdb+Functions+%2D+2 to MySpace Add Personal+Activities+Calendar+Program+%96+Use+the+strtotime+and+mysql%5Fselect%5Fdb+Functions+%2D+2 to Del.icio.us Digg Personal+Activities+Calendar+Program+%96+Use+the+strtotime+and+mysql%5Fselect%5Fdb+Functions+%2D+2 Add Personal+Activities+Calendar+Program+%96+Use+the+strtotime+and+mysql%5Fselect%5Fdb+Functions+%2D+2 to Yahoo My Web Add Personal+Activities+Calendar+Program+%96+Use+the+strtotime+and+mysql%5Fselect%5Fdb+Functions+%2D+2 to Google Bookmarks Add Personal+Activities+Calendar+Program+%96+Use+the+strtotime+and+mysql%5Fselect%5Fdb+Functions+%2D+2 to Stumbleupon Add Personal+Activities+Calendar+Program+%96+Use+the+strtotime+and+mysql%5Fselect%5Fdb+Functions+%2D+2 to Reddit




RSS | Related Articles | Editor's Picks Articles | Top Ten Articles | Previous Features | Site Map


For FREE email updates, subscribe to the PHP Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor


Content copyright © 2014 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.

g


g features
Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Poetry
Daily
Weekly
Monthly
Less than Monthly



BellaOnline on Facebook
g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2014 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor