Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Problem with connection "class"

Codes here !

Moderators: macek, egami, gesf

Problem with connection "class"

Postby MacRaider » Wed Aug 08, 2012 7:01 am

I'm adding a new page to my site and running into a problem with connecting to my database. I'm using the same code I use in 6 other pages with the difference being this page has a few more includes.

Code: Select all
require_once( "DataObject.class.php" );
require_once( "common.inc.php" );
require_once( "Calendar.class.php" );

//Further down in a function
$conn = parent::connect();


This is in DataObject.class.php:

abstract class DataObject {
--bunch of other stuff--

Code: Select all
protected function connect() {
//echo "<p>In DataObject/connect</p>";
try {
   $conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
   $conn->setAttribute( PDO::ATTR_PERSISTENT, true);
   $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
} catch ( PDOException $e ) {
   die( "Connection failed: " . $e->getMessage() );
}
return $conn;
}


Where it "works" the only include for the page is the DataObject.class.php

I'm sure it's something stupid that I'm overlooking and thanks in advance!
MacRaider
New php-forum User
New php-forum User
 
Posts: 2
Joined: Wed Aug 08, 2012 6:53 am

Re: Problem with connection "class"

Postby MacRaider » Wed Aug 08, 2012 9:07 am

Ok so after some "fighting" with my code I have it kinda working, though not exactly how I want to. I moved my DefaultCalendar function to the calendar class file, created a class in that file called Calendar and "extended" DataObject and called the new class with a object from the original file. Does that make sense?
MacRaider
New php-forum User
New php-forum User
 
Posts: 2
Joined: Wed Aug 08, 2012 6:53 am

Re: Problem with connection "class"

Postby johnj » Thu Aug 09, 2012 9:39 am

...Where it "works" the only include for the page is the DataObject.class.php....


Make sure all the three files are in the same directory. Next, check if there is an error in DataObject.class.php.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.