mjahkoh Posted October 25, 2007 Share Posted October 25, 2007 just trying to start off. Got this class 2 connect to a db but thinks arent working.The classes php file <?php function connect() { $this->log .= "connect() called<br />"; switch($this->cnn_id) { /* You can define all the database connections you need in this switch statement. */ case 0: $this->db_type = "mysql"; $this->server = "Localhost"; $user = "havesters"; $pwd = "Ndege19qwangu76"; $this->db = "havesters"; break; case 1: $this->db_type = "mysql"; $this->server = ""; $user = ""; $pwd = ""; $this->db = ""; break; case 2: $this->db_type = "postgres"; $this->server = ""; $user = ""; $pwd = ""; $this->db = ""; break; case 3: $this->db_type = "mssql"; $this->server = ""; $user = ""; $pwd = ""; $this->db = ""; break; } } ?> when i call it as thus <?php require_once('classes/common.php'); $d = new db(0); ?> is I get the error Fatal error: Class 'db' not found in C:\xampp\htdocs\phptrysite\Databases.php on line 3 Quote Link to comment https://forums.phpfreaks.com/topic/74705-cant-connect-to-database/ Share on other sites More sharing options...
adam291086 Posted October 25, 2007 Share Posted October 25, 2007 try include_once instead. I am new and its only a suggestion as i know it works. Quote Link to comment https://forums.phpfreaks.com/topic/74705-cant-connect-to-database/#findComment-377671 Share on other sites More sharing options...
Wuhtzu Posted October 25, 2007 Share Posted October 25, 2007 Please use [ code][ /code] tags when you post code. You have only showed the code for the function connect() and the bit where you attempt to create a new instance of the class... what about the class it self? <?php class db { public $conn_id; function connect() { function code..... } } ?> Something like the above code is missing or at least you did not post it. Quote Link to comment https://forums.phpfreaks.com/topic/74705-cant-connect-to-database/#findComment-377672 Share on other sites More sharing options...
Wuhtzu Posted October 25, 2007 Share Posted October 25, 2007 Another think, you can't do this: $d = new db(0); In relation to the code i posted in my previous answer you should do something like this: $d = new db(); $d->conn_id = 0; d->connect(); First you create an instance of the class, then you define conn_id to 0 for that instance and then you call connect() for that instance. Quote Link to comment https://forums.phpfreaks.com/topic/74705-cant-connect-to-database/#findComment-377680 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.