SitePoint Sponsor

User Tag List

Results 1 to 21 of 21
  1. #1
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Build your own Database Driven Webiste, Chapter 4

    I'm in Chapter 4 (page 121, 4th edition). I am trying to connect to my database for the first time through my webbrowser/php.

    I receive the following error when I try to connect my page with my jokes database:


    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 tried manually creating the code and also copying the provided code from the text book. Any advice at all regarding this matter would be great!

    Thank you

  2. #2
    SitePoint Zealot j3ph's Avatar
    Join Date
    Jan 2006
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might verify you have the mysqli library compiled into php. Another option would be to use mysql_connect instead of mysqli.

    Good Luck

  3. #3
    SitePoint Zealot atetlaw's Avatar
    Join Date
    Feb 2007
    Location
    Melbourne, Australia
    Posts
    171
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Since that function is part of PHP5, could it be possible that you have php4 and 5 installed and Apache is running your script with PHP4?

    Have you taken a look at your phpinfo output? Create a php file with

    Code:
    <?php phpinfo(); ?>
    and take a look at the output. Or even post it here.

  4. #4
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Alex Pugmire View Post
    I'm in Chapter 4 (page 121, 4th edition). I am trying to connect to my database for the first time through my webbrowser/php.

    I receive the following error when I try to connect my page with my jokes database:


    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 tried manually creating the code and also copying the provided code from the text book. Any advice at all regarding this matter would be great!

    Thank you
    Quote Originally Posted by atetlaw View Post
    Since that function is part of PHP5, could it be possible that you have php4 and 5 installed and Apache is running your script with PHP4?

    Have you taken a look at your phpinfo output? Create a php file with

    Code:
    <?php phpinfo(); ?>
    and take a look at the output. Or even post it here.
    Hi guys I'm having the same problem as Alex unfortunately I am a real beginner so not sure what your talking about in your replies I am assuming that for the mysqli_connect you need to change the code on the index.php file within the connect folder tried that and it didn't work I changed the password to the password i created in mysqladmin still getting error message any ideas please would be gratefully received.

  5. #5
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,023
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by atetlaw View Post
    Since that function is part of PHP5, could it be possible that you have php4 and 5 installed and Apache is running your script with PHP4?

    Have you taken a look at your phpinfo output? Create a php file with

    Code:
    <?php phpinfo(); ?>
    and take a look at the output. Or even post it here.
    Do that then:


    1. Make a note of the value given for "Loaded Configuration File"
    2. Open that file up in Notepad.
    3. Scrolls down the file until you see a line with "extension=php_mysqli.dll"
    4. If that line has a semi-colon at the start of it, remove the ;
    5. Save the file don't use "Save As" use "Save"
    6. Restart the server.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  6. #6
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Space Phoenix, thanks for the quick response I'm not sure how I'm supposed to run that php script I assumed you put it into an html page and got nothing back, when I check my apache server is says its running and it shows on the bottom Apache/2.2.13(win32) PHP/5.3.0 realise that perhaps someone so thick shouldn't be trying to write database driven websites but I love a challenge. once again thanks for the help any ideas on where to go from here (please don't suggest Siberia! I hate the cold.)

  7. #7
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,023
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    PHP scripts need to be in files with the extension .php
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  8. #8
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi SpacePhoenix
    thanks again for the prompt reply didn't spot my obvious mistake changed the page to php and I get a page that shows PHP Version 5.3.0 with a big list of what is enabled etc then below that configuration with apache2handler followed by lots of other bits and pieces. once again thanks for the reply

  9. #9
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm having the same issue as the other challenged folks here. I have followed the suggestion from SpacePhoenix and there was no change needed (that part was configured correctly during setup).

    I'm on a Windows Vista 64 bit machine and I have setup up MySql, Apache, and Windows according to the book referenced.

    I've output phpinfo() and everything is as current as possible.

    Is there something else to look at or is there a particular syntax for the following:
    $link = mysqli_connect('localhost', 'root', 'password');

    The above leads me to believe that all I need to do is enter my password.

    Am I missing something?

    Thanks for your help in advance.

  10. #10
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Fortunately I am running a mac as well as windows machine and managed to get MAMP up and running which made the whole process a lot simpler, I found a good PHP text editor which is free for windows and mac called komodo it highlights the code for you and if you get wamp up and running you can use it to follow the course. Hope this.

  11. #11
    SitePoint Zealot
    Join Date
    Jan 2010
    Posts
    140
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I'm having the same issue here

    my php version is current. extension=php_mysqli.dll is not commented in php.ini.

    but I am still getting the

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

    with the code when I paste it from the book.

    was this ever solved? would love to move on.

  12. #12
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,023
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by oknow View Post
    I'm having the same issue here

    my php version is current. extension=php_mysqli.dll is not commented in php.ini.

    but I am still getting the

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

    with the code when I paste it from the book.

    was this ever solved? would love to move on.
    Is it uncommented in the correct php.ini file? The correct one can be identifed in php info as "Loaded Configuration File"
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  13. #13
    SitePoint Zealot
    Join Date
    Jan 2010
    Posts
    140
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SpacePhoenix View Post
    Is it uncommented in the correct php.ini file? The correct one can be identifed in php info as "Loaded Configuration File"
    yep it is, I just did a reboot and now I have a different error:

    "Warning: mysqli_connect() [function.mysqli-connect]: (/838860800): in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2
    Unable to connect to the database server."

    which I am guessing just means my password is wrong, had trouble with that cmd in the book too.. hmm

    final edit: yep, 'Database connection established.'

    reboot and a change of the pw in my code did it. thanks!

  14. #14
    SitePoint Member
    Join Date
    May 2010
    Location
    Boynton Beach, FL
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi all,

    I had the same issue as above, 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 updated PHP as suggested and it seemed to solve the problem one time. I now get a 500 error on the web page. It doesn't happen instantly it seems to take a minute or so. I know that the localhost, user name, and password are correct.

    Error: The website cannot display the page
    HTTP 500
    Most likely causes:
    •The website is under maintenance.
    •The website has a programming error.

    What you can try:
    Refresh the page.

    Go back to the previous page.

    More information

    I am on a Windows 7 box, using Apache 2.2, PHP Version 5.3.2, MySQL 5.1.
    I used php-5.3.2-Win32-VC6-x86 for Apache.

    Any ideas? Anything more I can provide?

  15. #15
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,169
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    Hi gtopple, welcome to the forums,

    Did you install the Thread Safe version of PHP? http://www.sitepoint.com/books/phpmysql4/errata.php

  16. #16
    SitePoint Member
    Join Date
    May 2010
    Location
    Boynton Beach, FL
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    New information back to old error?

    I did install the Thread Safe version of PHP

    I just got:
    Warning: mysqli_connect() [function.mysqli-connect]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306) in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2

    Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2

    Fatal error: Maximum execution time of 30 seconds exceeded in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2
    Last edited by gtopple; May 6, 2010 at 12:05. Reason: New information

  17. #17
    SitePoint Member
    Join Date
    May 2010
    Location
    Boynton Beach, FL
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mittineague, I found the answer on a database thread. Thanks for trying to help.

    The solution was to change 'localhost' to '127.0.0.1'

    I am sure I will be on the boards a lot now!

  18. #18
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,169
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    Glad you got things so you can work with them.

    I had to use 127.0.0.1 before too. Then I changed something in a configuration file somewhere (sorry, I don't remember what I did now) so that "localhost" would "map" to the 127.0.0.1 IP

    Aaarrrggghhh!!! Installation is NOT my favorite thing.

  19. #19
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,023
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague View Post
    Glad you got things so you can work with them.

    I had to use 127.0.0.1 before too. Then I changed something in a configuration file somewhere (sorry, I don't remember what I did now) so that "localhost" would "map" to the 127.0.0.1 IP

    Aaarrrggghhh!!! Installation is NOT my favorite thing.
    Mittineague, I think the configuration file your refering to is the HOSTS file.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  20. #20
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,169
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    Thanks, yes that was the one. With a name like that I don't know how I could've forgotten. :d'oh:

    ?self preservation through purposeful forgetting?

  21. #21
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I had the same problem in Windows 7. The error message began "Warning: mysql_connect() [function.mysql-connect]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306)"

    I only found the solution by reading various snippets of advice in different places. Here is the way to fix this problem, all in one place:

    First, close all open programs. I stopped the Apache service and the mysql service using Windows Task Manager (click on the services tab and then on the services button in the lower right corner. Find the services in the list and select and stop each in turn.)

    Next, run Notepad as administrator. To do that, find Notepad in the Windows Start menu, right click the icon and select Run as Administrator. Now, navigate to C:\Windows\System32\drivers\etc and find and open the hosts file.

    Find the line that looks like this:

    # 127.0.0.1 localhost

    Uncomment that line by removing the # from the line and then save the hosts file. Close Notepad and then restart Windows.

    This worked for me. Good luck. Thanks to Patrício dos Santos in the mysql forums for most of this.

    jburns57


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
  •