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.
Connection to MySQL Database & to another Database to Login
Moderator: General Moderators
-
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
Cecil Champenois
Re: Connection to MySQL Database & to another Database to Lo
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 # 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?
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 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.
-
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
How do you do that?
"front controller pattern that will handle bootstrapping your application"
Is that any different than using the include statement?
"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
Interesting concept.
Merci,
Merci,
Cecil Champenois
- 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
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)
Re: Connection to MySQL Database & to another Database to Lo
Agreed. If/when you're ready to start refactoring/rewriting the codebase, definitely look at using a framework.