...

View Full Version : Error on line of mysqli_connect()



mad5245
07-26-2011, 06:39 PM
I am implementing a log-in system in an existing website using the JPMaster log-in script (if anyone is familiar). I have the code all written out and it seems correct but when I open it in the browser I get the following error:

"Call to undefined function mysql_connect() in c:/BLAH on line 24"

Line 24 in the file mentioned is as follows:



$this->link = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);

I also tried this with the constants put right in instead of the variables with no avail. I am sure the constants are correct because I can access the database with MySQL Front using the same constants.

I am fairly new to PHP and MySQL but have experience in java. Below I will post some sections of code from my project.

dbcontroller.php:



public function __construct(){
/*mb_internal_encoding("UTF-8");
mb_regex_encoding("UTF-8");*/
$this->link = mysqli_connect(
DB_SERVER,
DB_USER,
DB_PASS,
DB_NAME);
if (mysqli_connect_errno()) {
exit();
}


constants.php:



define("DB_SERVER", "localhost");
define("DB_USER", "root");
define("DB_PASS", "********");
define("DB_NAME", "login");


Any help would be greatly appreciated!
Thank you.

sunfighter
07-27-2011, 06:26 PM
The line
$this->link = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);

should be
$link = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);

mad5245
07-27-2011, 10:10 PM
After changing that I still get this when I try to run it:

Call to undefined function mysqli_connect() in C:\....\dbcontroller.php on line 16

Line 16 is what I changed:
$link = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);

Is it possible that I might have something set wrong in my php.ini file?

Fou-Lu
07-28-2011, 01:20 AM
The line
$this->link = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);

should be
$link = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);

No, this is in the context of an object. $this is required.


After changing that I still get this when I try to run it:

Call to undefined function mysqli_connect() in C:\....\dbcontroller.php on line 16

Line 16 is what I changed:
$link = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);

Is it possible that I might have something set wrong in my php.ini file?

Nothing you change will make a difference. According to this error you do not have the mysqli library available for use. You may either link it in, or choose the mysql or PDO libraries as alternatives.

sunfighter
07-28-2011, 07:02 PM
I am going to apologize here. I thought you were using mysql_connect which I use all the time and so the solution seemed obvious. But you were using mysqli_connect which I have never used and guess I don't understand.

@Fou-Lu could you explain why someone would use the mysqli_connect instead of a straight forward mysql_connect. What would be the advantage.

mad5245
07-28-2011, 08:19 PM
No, this is in the context of an object. $this is required.



Nothing you change will make a difference. According to this error you do not have the mysqli library available for use. You may either link it in, or choose the mysql or PDO libraries as alternatives.

How exactly do I link the library in? Sorry to bother but I am very new to all of this.

Fou-Lu
07-28-2011, 09:15 PM
I am going to apologize here. I thought you were using mysql_connect which I use all the time and so the solution seemed obvious. But you were using mysqli_connect which I have never used and guess I don't understand.

@Fou-Lu could you explain why someone would use the mysqli_connect instead of a straight forward mysql_connect. What would be the advantage.

MySQLi library is the improved and supported version of MySQL in PHP. It features more options such as prepared statements and OO context as well as procedural. MySQL and MySQLi themselves do not share much in common, but SQL itself is a standardized syntax, so no actual query operations would change (unless you choose to use prepared statements where you would replace parameters).


How exactly do I link the library in? Sorry to bother but I am very new to all of this.

Follow the installation guide. If you're on a windows system with 5.3+, it will be the easiest to configure: http://php.net/manual/en/mysqli.installation.php



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum