Fatal error: Undefined function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sophie_albinson
Forum Newbie
Posts: 1
Joined: Wed Aug 09, 2006 11:46 am

Fatal error: Undefined function

Post 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.
Last edited by sophie_albinson on Wed Aug 09, 2006 12:01 pm, edited 1 time in total.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post 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
Post Reply