Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Location
    Pa
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Error on line of mysqli_connect()

    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:


    Code:
    $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:

    Code:
    	
    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:

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

    Any help would be greatly appreciated!
    Thank you.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,762
    Thanks
    23
    Thanked 548 Times in 547 Posts
    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);

  • #3
    New to the CF scene
    Join Date
    Jul 2011
    Location
    Pa
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Still get an error.

    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?

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by sunfighter View Post
    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.

    Quote Originally Posted by mad5245 View Post
    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.

  • Users who have thanked Fou-Lu for this post:

    mad5245 (07-28-2011)

  • #5
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,762
    Thanks
    23
    Thanked 548 Times in 547 Posts
    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.

  • #6
    New to the CF scene
    Join Date
    Jul 2011
    Location
    Pa
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    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.

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by sunfighter View Post
    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).

    Quote Originally Posted by mad5245 View Post
    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

  • Users who have thanked Fou-Lu for this post:

    sunfighter (07-29-2011)


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •