Page 1 of 1

Fatal error: Undefined function

Posted: Wed Aug 09, 2006 11:55 am
by sophie_albinson
Hi I'm very new to PHP and am trying to get an example Web App to work. However when I try to run the code in my browser I get the following error message:
Fatal error: Call to undefined function: mysqli_connect() in /a/pollux.jour.city.ac.uk/export/JOUR-1/students/m2005/abbf950/web/ecomm/functions_main.inc on line 10
Is this because function mysqli_connect() is a PHP5 function? My server runs PHP4.x.
If so is there a work around? The example is perfect for my needs and would be gutted if this 'glitch' prevented me from using it.

Here's the code from the include:

Code: Select all

<?php
 /*  Function:  Connect_to_db
  *  Desc:      Connects to a MySQL database. The name of
  *             a file containing the database variables
  *             is passed to the function.
*/
  function Connect_to_db($filename)
  {
      include($filename);
      $cxn = mysqli_connect($host, $user,$passwd) 
               or die ("Couldn't connect to server.");
      $db = mysqli_select_db($cxn,$database)
               or die ("Couldn't select database.");
      return $cxn;     
  }
?>
I would be unbelievably grateful for any help you might be able to give.

Sophie xx.

Note: I am using a University server and so cannot make changes to the PHP running on iit.

Posted: Wed Aug 09, 2006 12:00 pm
by infolock
yes, mysqli is a php 5 function. use mysql_connect instead of mysqli_connect.

for that matter, use any mysql function as mysql_functionnamehere instead of mysqli_functionnamehere