As above, rather new to all this but have setup MySQL, PHP and Apache and all is working ok with various tests from php.net etc.

I have tried to connect to the test db through PHP function mysqli_connect and am getting the following error:

Fatal error: Call to undefined function mysqli_connect() in C:\Program Files\Apache Group\Apache2\htdocs\db1.php on line 12

The code I am running is:

<?PHP
$username="test";
$password="test";
$database="test";
$link = mysqli_connect("localhost", $username, $password, $database);

/ check connection /
if (!$link) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

printf("Host information: %s\n", mysqli_get_host_info($link));

/ close connection /
mysqli_close($link);
?>

Any ideas why I am getting the error?

Also, just to mention I have tried mysql_connect also! I am using MySQL 4.1.14, PHP 5.05 and Apache 2.0.54.

Many thanks 😃

    Are you sure that PHP has mysql support enabled (I believe you need this for PHP 5, it should say in the php.ini file).

      Thanks, does this answer your question? I'm not sure what's what at the mo!

      [MySQL]
      ; Allow or prevent persistent links.
      mysql.allow_persistent = On

      ; Maximum number of persistent links. -1 means no limit.
      mysql.max_persistent = -1

      ; Maximum number of links (persistent + non-persistent). -1 means no limit.
      mysql.max_links = -1

      ; Default port number for mysql_connect(). If unset, mysql_connect() will use
      ; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
      ; compile-time value defined MYSQL_PORT (in that order). Win32 will only look
      ; at MYSQL_PORT.
      mysql.default_port =

      ; Default socket name for local MySQL connects. If empty, uses the built-in
      ; MySQL defaults.
      mysql.default_socket =

      ; Default host for mysql_connect() (doesn't apply in safe mode).
      mysql.default_host =

      ; Default user for mysql_connect() (doesn't apply in safe mode).
      mysql.default_user =

      ; Default password for mysql_connect() (doesn't apply in safe mode).
      ; Note that this is generally a bad idea to store passwords in this file.
      ; Any user with PHP access can run 'echo get_cfg_var("mysql.default_password")
      ; and reveal this password! And of course, any users with read access to this
      ; file will be able to reveal the password as well.
      mysql.default_password =

      ; Maximum time (in secondes) for connect timeout. -1 means no limit
      mysql.connect_timeout = 60

      ; Trace mode. When trace_mode is active (=On), warnings for table/index scans and
      ; SQL-Errors will be displayed.
      mysql.trace_mode = Off

      [MySQLI]

      ; Maximum number of links. -1 means no limit.
      mysqli.max_links = -1

      ; Default port number for mysqli_connect(). If unset, mysqli_connect() will use
      ; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
      ; compile-time value defined MYSQL_PORT (in that order). Win32 will only look
      ; at MYSQL_PORT.
      mysqli.default_port = 3306

      ; Default socket name for local MySQL connects. If empty, uses the built-in
      ; MySQL defaults.
      mysqli.default_socket =

      ; Default host for mysql_connect() (doesn't apply in safe mode).
      mysqli.default_host =

      ; Default user for mysql_connect() (doesn't apply in safe mode).
      mysqli.default_user =

      ; Default password for mysqli_connect() (doesn't apply in safe mode).
      ; Note that this is generally a bad idea to store passwords in this file.
      ; Any user with PHP access can run 'echo get_cfg_var("mysqli.default_pw")
      ; and reveal this password! And of course, any users with read access to this
      ; file will be able to reveal the password as well.
      mysqli.default_pw =

      ; Allow or prevent reconnect
      mysqli.reconnect = Off

        Database Trouble?
        With MySQL ?

        maybe I should be surprised,
        but I am NOT

        /halojoy - SQLite or FlatFile DB for him
        let them other have their troubles
        :p

          did you compile php yourself? and what os are you on?

            Halojoy....am just using what's free and works with php (I guess in theory!), I work with Oracle Db etc but that's far from free if you intend using it for business!

            Thorpe: I actually did something different to start off with but presumed, being relatively new to PHP, that it was my error. However the code you see above for the mysqli_connect was direct from php.net functions description so I'm guessing it should work! I've just tried various functions but all seem to give me the error!

            Thanks for the help...please do keep it coming as I cannot do anything but play with php and apache at the mo :queasy:

            Cheers

            Dave 😃

              Sorry Thorpe...If you meant did I install PHP on apache then yes, I did do it myself. I'm sure it is something I missed in the setup? PHP and Apache are working fine though thus far...just Db Connection that's giving me hassle.

              Dave

                Try outputting the php_info() function and seeing what it says about mysql.
                Also try (I know this sounds dumb, but it actually fixed it when I had a similar problem a while back) replacing local host with an ip (i.e. 192.168.1.100) or with the server name. Also try taking out the database name in the connection string (one less thing to worry about at the momemnt, once you get it to connect you either put it back in or use the mysql_select_db function.

                  Thanks, I'll give it a go tonight 🙂

                    Aaaaagh, head, wall, banging!

                    I tried everything you suggested and nothing worked! I also outputted phpinfo() to screen but there was no section on MySQL?! Is that correct? Id didn't think the forum would appreciate me doing a print out of it all so I didn't!

                    Interestingly enough I cannot connect to the Db through Dreamweaver MX either...it just says...undefined error when I try...and then it lets me but no tables are shown which is, of course, incorrect.

                    Am I missing something in the php.ini? There must be something somewhere that allows php to talk to mySQL that I'm missing??

                    PLEASE HELP.....I'm reaching for the alcohol already! I even tried looking on the MySQL website for bugs...which was also a waste of time!

                    Dave :bemused:

                      In php.ini you need to uncomment the php_mysql.dll extension and your extensions path needs to be set properly. Also, if you have multiple php.ini files floating around, look at your phpinfo() output for the location of the active php.ini

                        Have you tried connect using just mysql_connect ('localhost', 'mysql_user', 'mysql_password');

                        instead of mysqli_connect?

                          Doug G / Rowman: Thanks very much..a combination of your comments i.e. setting path.ext. and not using the mysqli function worked 😃 Thanks so much, I can now get on and actually do something!!

                          Thanks again

                          Dave 😃

                            You were using the mysqli functionality which has it's own PHP extension. This extension must be added (comment removed) in the php.ini file.

                            'Extension=php_mysqli.dll'

                            Also the only requirement to use mysqli functions is dependant on your version of mysql I think or even your version of PHP not sure which it is.

                              Write a Reply...