Connection to MySQL Database & to another Database to Login

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cecilchampenois
Forum Commoner
Posts: 47
Joined: Thu Nov 06, 2014 10:29 am
Location: Gilbert, Arizona
Contact:

Connection to MySQL Database & to another Database to Login

Post by cecilchampenois »

So, as a new PHP Developer, I am trying to sort things out in my head and I need to try to make sense. If someone can guide me, I would surely appreciate it.

In my company's case, we have a web page called Login_Page.php that POSTs the "username" and "password" to the next web page which is the Check_Login.php page. We have an include() statement at the beginning of the check_login.php page that takes care of the connection to the MySQL database.

(1) Login_Page.php - Calls Check_Login.php
(2) Check_Login.php - includes dbConnect.php

Check_Login runs a SQL statement and looks for the username and password from a different database called "claimsweb".
dbConnect.php maintains the connection to the MySQL database and sets up the webpage's appearance.

Question # 1:
I do not understand the constant need for the statement, include("dbConnect.php"); to be included on every web page. Is this a necessary thing since there is no persistent database connection?

Question # 2:
The previous developer puts the username and password in for access to the MySQL database into the code. Isn't this wrong to do this? I mean, anyone reading the code can see these things.
Cecil Champenois
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Connection to MySQL Database & to another Database to Lo

Post by Celauran »

cecilchampenois wrote:Question # 1:
I do not understand the constant need for the statement, include("dbConnect.php"); to be included on every web page. Is this a necessary thing since there is no persistent database connection?
Not because there's no persistent DB connection, but because of how PHP works; it completes its request and dies. Rather than having include statements all over the place, you can use a front controller pattern that will handle bootstrapping your application so the DB connection only needs to be established in a single place.
cecilchampenois wrote:Question # 2:
The previous developer puts the username and password in for access to the MySQL database into the code. Isn't this wrong to do this? I mean, anyone reading the code can see these things.
You have to put it somewhere. So long as it's not in version control, I wouldn't worry too much about it. Keeping it out of the document root is also a good idea.
cecilchampenois
Forum Commoner
Posts: 47
Joined: Thu Nov 06, 2014 10:29 am
Location: Gilbert, Arizona
Contact:

Re: Connection to MySQL Database & to another Database to Lo

Post by cecilchampenois »

How do you do that?

"front controller pattern that will handle bootstrapping your application"

Is that any different than using the include statement?
Cecil Champenois
cecilchampenois
Forum Commoner
Posts: 47
Joined: Thu Nov 06, 2014 10:29 am
Location: Gilbert, Arizona
Contact:

Re: Connection to MySQL Database & to another Database to Lo

Post by cecilchampenois »

Interesting concept.

Merci,
Cecil Champenois
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Connection to MySQL Database & to another Database to Lo

Post by Christopher »

Given your comments, I would recommend using a framework. They have done all the computer science, leaving you to be productively focused on building your application.
(#10850)
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Connection to MySQL Database & to another Database to Lo

Post by Celauran »

Agreed. If/when you're ready to start refactoring/rewriting the codebase, definitely look at using a framework.
Post Reply