Page 1 of 1

After Switching to mysqli...Failing to Connect to MySQL

Posted: Fri Jan 09, 2015 8:53 am
by cecilchampenois
The $conn connection handler variable is showing nothing, so I know it is not connecting. Why? I don't know. When I was using mysql_pconnect($host, $user, $pass); this was working, until I did some update in Linux Ubuntu. Anyway, I want to proceed with moving over to mysqli extensions now and make this all work. Got any ideas on what is going wrong here? I used a few print statements to try to debug this.

Code: Select all

<?php
$lDebug = TRUE;
$host = "localhost";
$user = "web_user";
$pass = "bubbagumpfakepassword";
$db   = "mysql";
$conn = "";

echo "{$user}";
echo "<br />";
$today = strtotime(date("Y-m-d"));
echo "Time is: $today";

// This part sets up the connection to the
// database (so you don't need to reopen the connection
// again on the same page).
// 01/08/2015 Cecil Champenois. Apache 2 PHP code has deprecated mysql_pconnect. Use mysqli_connect() instead.
//$ms = mysql_pconnect($host, $user, $pass);
$conn = mysqli_connect($host, $user, $pass, $db);	// 01/08/2015 Cecil.
print("<br/>");
print("This is the connection handler: " . $conn);

// Check Connection.
if (mysqli_connect_errno())
{
	echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

Re: After Switching to mysqli...Failing to Connect to MySQL

Posted: Fri Jan 09, 2015 9:30 am
by Weirdan
So what does it output?

Re: After Switching to mysqli...Failing to Connect to MySQL

Posted: Fri Jan 09, 2015 10:07 am
by cecilchampenois
I am seeing part of the problem. I thought that the user's name was in another database, but it is in the "mysql" database in the USER table. I have taken over the website, and have little PHP/MySQL knowledge, so I am stepping around in the dark.

It still isn't working even though I made the correction.

It shows that it fails at the connection point with mysqli_connect().

Re: After Switching to mysqli...Failing to Connect to MySQL

Posted: Fri Jan 09, 2015 11:54 am
by Weirdan
Can you post what you're getting (with sensitive data removed, of course)?

Re: After Switching to mysqli...Failing to Connect to MySQL

Posted: Fri Jan 09, 2015 12:14 pm
by cecilchampenois
I think part of the issue is that there are too many things I don't know.

Here's how the web pages go:

(1) login_page.php - The user types in his/her login_id and password only and hits the submit button. This is mostly HTML, but has a little php to include a page called dbConnect.php which establishes a connection to the "mysql" database. login_page.php calls check_login.php.
[text]
<form name="form1" method="post" action="check_login.php">
[/text]
(2) check_login.php has an include statement for the dbConnect.php file again. check_login runs a SQL statement to get the user's information and puts that info into $_SESSION variables.

So, there are two database connections going on here, one to the "mysql" database and one to our proprietary database. Every web page appears to include dbConnect.php.

I am now connecting to the "mysql" database just fine, but not to the proprietary database with the user's login credentials. However, the username is going along fine in check_login.php until it hits the mysqli_real_esape_string() function. After it hits this function, nothing comes out. The value is suddenly gone.