SitePoint Sponsor

User Tag List

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

    Chapter 4: Build Your Own Database, By Kevin Yank

    Hi Guys,

    I am attempting to use PHP to start outputting data from MySQL and I am running into the error:

    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
    After searching the web and this forum, the only fix offered was go change "localhost" in line 2 of the below code to 127.0.0.1, which gave me the same error.

    Here is my code, copied directly from this website, any ideas?

    PHP Code:
    <?php
    $link 
    mysqli_connect('localhost''root''password');
    if (!
    $link)
    {
        
    $output 'Unable to connect 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 locate the joke database.';
        include 
    'output.html.php';
        exit();
    }

    $output 'Database connection established.';
    include 
    'output.html.php';
    ?>
    Thanks!

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    This error means the mysqli extension is not installed or enabled on your server. No changing of your code will fix the problem that you can't use something which is not installed.

    http://php.net/manual/en/install.windows.extensions.php

  3. #3
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for the reply.

    After reading your link I have to one possible solution, but I have another question before I act on it.

    It looks as if I need to edit this piece of code within my php.ini file:

    ; Directory in which the loadable extensions (modules) reside.
    ; PHP: Description of core php.ini directives - Manual
    ; extension_dir = "./"
    ; On windows:
    ; extension_dir = "C:\PHP\ext"
    My question is should i edit the first "extension_dir" or the second "extension_dir." In addition to this should I have it point to my ext folder within php?

    Thank you in advance for your quick response!

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You probably shouldn't change that if your code other than database calls is working.

    Is there a line like this (search for 'mysqli')?

    ; extension=php_mysqli_libmysql.dll
    If so, remove the semicolon (that tells PHP to ignore that line, effectively disabling that extension) and restart apache.

  5. #5
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I do have:

    Code:
    extension=php_mysqli.dll
    and per the instructions of the book I already deleted the ";" before it. I have also restarted my computer many times since I made that change.

    I do not have anything with an underscore after mysqli in my php.ini folder.

    Any other help is much appriciated.

    Thanks again.

  6. #6
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Is that file php_mysqli.dll in your extension directory?

  7. #7
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Assuming my extenstion directory is my ext folder, it does contain php_mysqli.dll.

  8. #8
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    In that case, you might as well try uncomminting the ext_dir line and setting it to that directory. I don't know what else to try. I'm just a passer-by...

  9. #9
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well my symptoms have changed with the update to the php.ini file. I am now getting:

    Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'root'@'localhost' (using password: YES) in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2

    Unable to connect to the database server.
    My codes starts like this:

    PHP Code:
    <?php
    $link 
    mysqli_connect('localhost''root''password');
    if (!
    $link)
    {
        
    $output 'Unable to connect to the database server.';
        include 
    'output.html.php';
        exit();
    }
    Should I be defining my localhost, root and password within my code?

    Thanks for all the help so far, I'm sure you are more than just a "passer-by." =)

  10. #10
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Great, that means you connected to the MySQL server but it rejected your username and password pair. You should change them if "root" and "password" are not what they really are.

  11. #11
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much Dan for being very easy to understand and answering questions at such a late hour. With your help my problem was solved. The last thing I needed to do was update my password.

    I now have the expected result after updating my password in addition to the actions previously taken.

    Again, thank you very much and if you see anymore of my questions on this forum, feel free to respond! =)


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
  •