Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Class import problem 1

Status
Not open for further replies.

gregmosu

Programmer
Joined
Jul 8, 2002
Messages
117
Location
US
My Class, called dbconn.php:
<?php
class dbconn {

var $db_host;
var $db_name;
var $db_user;
var $db_pass;
var $conn;
var $qstring;
var $qlimit;
var $qoffset;
var $qhandle;
var $table_name;
var $pkey_field_name;
}
//Connect to database
function db_connect(){
$this->conn=@mysql_pconnect($this->db_host,$this->db_user,$this->db_pass);
}
?>
The page I'm using this class in:

<?
//Import
//require_once 'dbconn.php';
include &quot;dbconn.php&quot;;

$dbConn2 = new dbconn();

$dbConn2->db_host='localhost';
$dbConn2->db_name='Greg';
$dbConn2->db_user='sa';
$dbConn2->db_pass='';

$dbConn2->db_connect();
?>

Heres the error message I'm getting when I run the page:
Fatal error: Call to undefined function: db_connect() in c:\program files\apache group\apache\html\db_test2.php on line 13

Both files are in the same directory. Is there any reason why it cant see this function??

Thanks,
Greg
 
It's because you have not defined the function inside the class definition. Correctly, dbconn->db_connect() does not exist. db_connect() as a standalone function does.

Move the closing brace of your class definition down the file to encompass the function definition.

Want the best answers? Ask the best questions: TANSTAAFL!
 
I cant believe I missed that!!!!
thanks sleipnir214!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top