SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unable to connect to mysql using php. Fatal error: Call to undefined function mysqli_

    Hi guys,
    I am new to php and am learning it from "Build Your Own database driven web site using Php and MySql".

    I get the following error when i run the below code.
    $link = mysqli_connect('127.0.0.1', 'root', 'mypassword');

    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 am using apache http server 2.2 and php 5.4.11 and operating system is Windows 7. (I have installed php and mysql separately and not used Wamp server). I am able to connect to mysql from command prompt.

    I have read enormous number of threads related to the same error(some on this very site). Still am unable to successfully run the code.
    I have checked the following points:
    File - php.ini
    i) doc_root = C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs
    ii) extension_dir = "C:\php\ext"
    iii) extension=php_mysqli.dll (uncommented)

    In the file - C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf i have added
    LoadModule php5_module "C:/PHP/php5apache2_2.dll"
    AddType application/x-httpd-php .php
    PHPIniDir "C:/PHP"


    Also i have learned that php 5.3+ does not need extra setup configurations with mysql due to Mysql native driver(mysqlnd). Yet however i have added the path of directory containing libmysql.dll and the directory containing php.ini in the System Path and restarted the computer.

    I have also run the command phpinfo(INFO_MODULES) and I find mysqlnd enabled but there is no mention of mysqli. I have also confirmed that i am editing the correct php.ini file. What am I actually missing?

    Any help/ guidance appreciated
    Thanks
    Mitesh

  2. #2
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,053
    Mentioned
    66 Post(s)
    Tagged
    0 Thread(s)
    Create a script to echo out the phpinfo

    <?php echo phpinfo() ?>

    I'm going to hazard a guess that mysqli hasn't been compiled into your PHP installation.

    Also, you'd be better served to learn how to access the database using the PDO library, unless your needing to learn mysqli to deal with legacy systems.

  3. #3
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    996
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    Firstly, well asked question! It's nice to see someone who's clearly looked around and tried all the common fixes then come here and said what they'd tried.

    Run Michael's script and check the top for "Configuration File (php.ini) Path" and make sure it is reading the one from c:\php\php.ini

  4. #4
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Michael,
    Thanks for such a quick reply . I didn't expect such a quick response from a forum.
    However I am not sure I have understood what you have mentioned.
    I had extracted a zip file downloaded from the site http://php.net/downloads.php to folder c:\php and I have the file C:\php\ext\php_mysqli.dll present. Were you referring to this file when you meant mysqli hasn't been compiled into the PHP installation?

    Anyways i will be exploring the PDO library which you have mentioned. I am finding getting a start point into PHP very tough (with some many frameworks and content management systems). Hence I had decided to go with whatever is mentioned in the book.

  5. #5
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,053
    Mentioned
    66 Post(s)
    Tagged
    0 Thread(s)
    It sounds like you are putting your dev environment together from scratch. I'd recommend using XAMPP while learning. It has almost any module you're likely to encounter in a tutorial already setup, and if you run into trouble its general architecture is familiar to a wide swath of people so it will be easier to find help if you do hit a config error. For the most part a XAMPP installation on your desktop is self contained.

    Keep in mind it isn't that secure out of the box - it wasn't designed to be. It's designed for experimentation and skill development, not production.

    XAMPP has mysqli inbuilt and has MySQL included out of the box, further it comes with phpMyAdmin which is useful for setting up tables.

  6. #6
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot will install XAMPP then.

  7. #7
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Truthfully i also wanted to learn how the actual setup works in the deployment environment but i think i better learn using XAMPP first

  8. #8
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)
    While XAMPP is an awesome rapid deployment option, I'd recommend, if at all possible, to make your dev environment as close to your prod environment. For me, this means compiling apache and php from scratch, and saving the ./configure arguments for both. You can painfully find out that running a WAMP server (windows apache mysql php) can be very different from a LAMP server (linux).

    EDIT: For a small deployment though, you should be fine. I love setting up a virtual box (https://www.virtualbox.org/) with a LAMP server for development.


Tags for this Thread

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
  •