#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0

    Php not recognizing mysqli_connect


    Hello,

    I'm having a frustrating time trying to find out why php is not connecting to MySQL. Here's what I did;

    * installed Apache Web server on a laptop. This is up and running.

    * Installed php on the laptop and this is running and configured to Apache. I can bring up a dev website running php.

    * installed MySQL database and created tables.

    Now I'm trying to connect php to the database and php does not seem to be recognizing mysqli_connect.

    I have the following within a php file.

    <?php
    $link = mysql_connect('localhost', 'root', 'password');
    ?>

    If I view the source code after the page comes up it seems as if the webpage hits this piece of code and stops creating the rest of the page.

    Any ideas;

    You help is appreciated.
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    are you talking about mysqli_connect (with an "i") or mysql_connect? Those are two completely different extensions. The first one is the current PHP extension for MySQL, the last one is obsolete.

    In any case:

    Turn on your error messages with
    PHP Code:
    error_reporting(-1); 
    or in the php.ini

    And then check the exact error message. Maybe you don't have the extension activated.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0

    update


    I tried both mysqli_connect and mysql_connect. The error_reporting in the php.ini file was set tol

    error_reporting = E_ALL;

    I tried setting it to

    error_reporting(-1);

    However after I did that I stopped and tried to start apache. Apache wouldn't start as it couldn't parse error_reporting(-1); I do suspect as you indicate though that the mysqli_connect is not being recognized. How do I fix that?
  6. #4
  7. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7170
    In your php.ini file, look for the extension line that enables the mysql or mysqli extensions and uncomment it (if it's commented out). I don't recall exactly what it looks like, but it will say something like "extension=mysqli.dll".

    Setting error_reporting alone isn't always enough to see error messages. You also need to enable display_errors. Entry #30 in the FAQ goes into depth on how to do this.

    The error_reporting(-1) syntax would be something you would use in your actual php file, rather than in your php.ini file.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  8. #5
  9. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Originally Posted by cteagle5
    error_reporting = E_ALL;

    I tried setting it to

    error_reporting(-1);
    No, check the syntax of the default configuration. It's
    Code:
    error_reporting = -1


    Originally Posted by cteagle5
    I do suspect as you indicate though that the mysqli_connect is not being recognized. How do I fix that?
    http://www.php.net/manual/en/mysqli.installation.php

    But before you change anything, check the actual error.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo