SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problems connecting PHP to MYSQL

    I am brand new at learning PHP and am using Kevin Yank's book "Build your own database driven websites using PHP and MYSQL".

    I am now at the section of the book that explains how to connect MYSQL to PHP and am stuck at the mysqli_connect function.

    I receive the following message when trying to execute the PHP file:

    Fatal error: Call to undefined function mysqli_connect() in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2.

    I've doubled check the php.ini configuration and it all *appears* correct.

    Here's my code specifically

    PHP Code:
    <?php 
            $link 
    mysqli_connect('localhost''root''mypassword');
            if (!
    $link)
            {
                
    $output 'Unable to connnect to the database server.';
                include 
    'output.html.php';
                exit();
            }
            if (!
    mysqli_set_charset($link'utf8'))
            {
                
    $output 'Unable to set database connection encoding.';
                include 
    'output.html.php';
                exit();
            }
            
            if (!
    mysqli_select_db($link'ijdb'))
            {
                
    $output 'Unable to set database connection encoding.';
                include 
    'output.html.php';
                exit();
            }
            
        
            
    $output 'Database connection established.';
            include 
    'output.html.php';    
            
    ?>
    Any help would be much appreciated.

    Thanks!
    Last edited by SpacePhoenix; Nov 14, 2011 at 13:12. Reason: put php tags around php code

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    Your server does not have the mysqli extension enabled. Either adjust your configuration to enable that extension, or use the base mysql extension instead.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply. I checked the configuration of the extensions and it appears that I do have the mysqli extension enabled. Here is exactly what it looks like:

    ;extension=php_bz2.dll
    ;extension=php_curl.dll
    ;extension=php_dba.dll
    ;extension=php_dbase.dll
    ;extension=php_fdf.dll
    ;extension=php_gd2.dll
    ;extension=php_gettext.dll
    ;extension=php_gmp.dll
    ;extension=php_ifx.dll
    ;extension=php_imap.dll
    ;extension=php_interbase.dll
    ;extension=php_ldap.dll
    ;extension=php_mbstring.dll
    ;extension=php_exif.dll
    ;extension=php_mcrypt.dll
    ;extension=php_mhash.dll
    ;extension=php_mime_magic.dll
    ;extension=php_ming.dll
    ;extension=php_msql.dll
    ;extension=php_mssql.dll
    ;extension=php_mysql.dll
    extension=php_mysqli.dll
    ;extension=php_oci8.dll
    ;extension=php_openssl.dll
    ;extension=php_pdo.dll
    ;extension=php_pdo_firebird.dll
    ;extension=php_pdo_mssql.dll
    ;extension=php_pdo_mysql.dll
    ;extension=php_pdo_oci.dll
    ;extension=php_pdo_oci8.dll
    ;extension=php_pdo_odbc.dll
    ;extension=php_pdo_pgsql.dll
    ;extension=php_pdo_sqlite.dll
    ;extension=php_pgsql.dll
    ;extension=php_pspell.dll
    ;extension=php_shmop.dll
    ;extension=php_snmp.dll
    ;extension=php_soap.dll
    ;extension=php_sockets.dll
    ;extension=php_sqlite.dll
    ;extension=php_sybase_ct.dll
    ;extension=php_tidy.dll
    ;extension=php_xmlrpc.dll
    ;extension=php_xsl.dll
    ;extension=php_zip.dll

    Thanks for your help.

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    Have you restarted the web server since you made that change? (Hint: you should.)
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  5. #5
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My original settings had the mysqli extension enabled already so there was really no need to restart the server, but I tired it anyway. Unfortunately, it didn't work. What should my next step be? Reinstall PHP?

    Thanks

  6. #6
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    create a new PHP file.
    Inside that file, write:
    <?php phpinfo(); ?>

    and view that file. Check and see if there is a section in there on mysqli.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  7. #7
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, i viewed and searched that PHPinfo doc for mysqli and did not find any reference to it. In the process I realized that I had an extra directory in my file structure so there were a bunch of broken references. My php.ini was not in C:\php but rather in C:\PHP\ another directory. I ended up redoing the directory structure so that everything would match the config file, I also reconfigured apache to reflect the new structure. I rebooted apache when I was done with all this. I then tested several PHP scripts (including the PHPinfo file) to ensure that everything was still working properly. It was.

    After all that, I tried running the connection script again. I did not receive the fatal error message, however the page was just blank.

  8. #8
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    4,998
    Mentioned
    100 Post(s)
    Tagged
    0 Thread(s)
    It's possible that you looked at the wrong php.ini file, php.ini files seem to spring up like rabbits. When you view the output of the phpinfo() as suggested by StarLion (post #6) have a look for the "Loaded Configuration File", that is the location of the php.ini which php is actually using.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  9. #9
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have confirmed that the right php.ini is being referenced. The loaded file is in C:\PHP and the php.ini file in that directory has been configured to enable mysqli.

    What should I do next? Reinstall?

  10. #10
    SitePoint Zealot mixDev's Avatar
    Join Date
    Mar 2004
    Location
    B'lore
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is this the same PHP.ini file path mentioned in your phpinfo output?

    If yea, there may be some issues in the extension itself. are the versions, threadsafe etc correct?
    HostAccord - Cheap RAID 10 Webhosting

  11. #11
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Same story as howl9k: newbie using Yank's book. Separate install of Apache, MySQL and PHP on Windows 7. Followed book's instructions to install PHP binaries for Windows - chose VC6 x86 Thread Safe (2011-Mar-22 13:29:30) from PHP.org site.

    Triple checked setup per Yank's instructions. Receive error message: "Call to undefined function mysqli_connect() in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2." Line 2 in script is as Yank prescribes: $link = mysqli_connect('localhost', 'root', 'mypassword');

    Checked my configuration per advice in earlier posts, and everything checked out as expected. One odd finding in the PHPinfo() list is: Configuration File (php.ini) Path C:\Windows. This seems strange because there is no php.ini file in the Windows directory. This is in the list just above: Loaded Configuration File C:\PHP\php.ini

    Thanks for any help.

  12. #12
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Jbrowne - I ended up reinstalling PHP, and instead of using V6 as is recommended by Yank, I used VC9 x86 Thread Safe. I went through the same config steps for the php.ini file and everything appears to be working. You may want to give it a shot.

  13. #13
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    You -should- run the latest version of any software, even if it means your book is slightly out of date. Better to have to ask for a correction and get the up to date information than to learn something that may be obsolete.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  14. #14
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, howl9k. Replaced with VC9 x86 Thread Safe and config per Yank's instructions. No luck for me, same error message and inability to move forward with PHP learning in book.

    Glad this worked for you.

    Lots of Googling and reading of PHP.net and Apache guidance, but no help. Yank's config instructions for manual install are confirmed in several online guides. I may next try installing PHP with the .msi version in hopes that the install wizard does better. If not, then may abandon Apache and go with Microsoft Internet Information server (IIS).

  15. #15
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    If it doesnt work, go with a bundled setup - XAMPP or WAMP, for example. I personally run XAMPP on localhost for development purposes.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  16. #16
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've been searching for an answer and this thread has come close to solving the problem. However, it has not completely unraveled the errors.

    My database connect error is:
    Fatal error: Call to undefined function mysqli_connect() in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2.

    I have followed along this thread and have completed all recommendation. However, after creating the <?php phpinfo(); ?> file, I notice the 'loaded configuration file' is blank!

    I installed mysql php on my D: but made sure to point to all the correct locations in php.ini & httpd.conf

    Should I do this all on the C: / try wamp instead?

  17. #17
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good advice, StartLion. I installed WAMP 2. Now to get on with learning php programming. Some day I may try a la carte installs again and figure out what kept PHP from functioning for me. I usually can figure software out, but not this time.


Bookmarks

Posting Permissions

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