NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page __construct() problem - php

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Reply
 
LinkBack Thread Tools
Old 11-10-2009, 07:13 AM THREAD STARTER               #1 (permalink)
NamePros Regular
 
pixelhero's Avatar
Join Date: May 2008
Location: England
Posts: 771
pixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to all
 


Help The Homeless - Holiday 2009

__construct() problem - php


Hey,

Been a year since I did OO php. Last time I used this I remember it working fine.. but..

My index.php
PHP Code:
<?php 

include("includes/dbcon.php");

$connection = new connection();

?>

....
My dbcon.php
PHP Code:
<?php

class connection {


     
/*    Main function 
        Connects to database
        Die with error if fails to connect */

    
function __construct(){
        
/*     Database Connection Varaiables */
        
$usrnme "user";
        
$psswrd "pass";
        
$servhst "local";
        
$dbnme "db";

        
$con mysql_connect($servhst$usrnme$psswrd);
        if (!
$con)
         {
             die(
'Failed to connect: ' mysql_error());
????: NamePros.com http://www.namepros.com/programming/622201-__construct-problem-php.html
         }

        
mysql_select_db($dbnme$con);

    }

}

?>
Now, last I checked, php is meant to automatically run __construct() when a new class is created. I created a new class of connection in the index file, but it does not run the __construct()
????: NamePros.com http://www.namepros.com/showthread.php?t=622201

However, it works if I add: $connection->__construct(); to the index.php

Has something changed regarding this? Or am I being blind and missed something completely? o_O
pixelhero is offline   Reply With Quote
Old 11-10-2009, 07:51 AM   #2 (permalink)
Tech Support
Join Date: Mar 2005
Posts: 4,944
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Which PHP version are you using?
Eric is offline   Reply With Quote
Old 11-10-2009, 07:53 AM THREAD STARTER               #3 (permalink)
NamePros Regular
 
pixelhero's Avatar
Join Date: May 2008
Location: England
Posts: 771
pixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to all
 


Help The Homeless - Holiday 2009
Host has 5.x.x

Think it defaults to php4, so i have used .php5 file ext and same problem occurs.
pixelhero is offline   Reply With Quote
Old 11-10-2009, 08:23 AM   #4 (permalink)
Tech Support
Join Date: Mar 2005
Posts: 4,944
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
I don't think the server is parsing PHP properly. PHP 5 *will* automatically run __construct.

.htaccess
Code:
AddType application/x-httpd-php .php .php5
EDIT: however, taking another look - the extension of your include file is .php which you say may default to PHP4 - try changing it to PHP5 as well?
Last edited by Eric; 11-10-2009 at 08:28 AM.
Eric is offline   Reply With Quote
Old 11-10-2009, 08:27 AM THREAD STARTER               #5 (permalink)
NamePros Regular
 
pixelhero's Avatar
Join Date: May 2008
Location: England
Posts: 771
pixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to all
 


Help The Homeless - Holiday 2009
Still not working.

Thanks though.

I'll get in touch with my host, see if they will change default php to 5 instead of 4.


RE: your edit; I did edit the file ext in all combinations
Last edited by pixelhero; 11-10-2009 at 08:49 AM.
pixelhero is offline   Reply With Quote
Old 11-11-2009, 02:43 AM   #6 (permalink)
NamePros Member
Join Date: Nov 2009
Location: Christchurch, New Zealand
Posts: 27
Mr Spy is an unknown quantity at this point
 




I'd agree with Eric...BUT:
Try
Code:
$connection = new connection;
?
__________________
Caleb (Spy) Isaacs: Web Designer, Developer and soon-to-be domainer!
Game Sector Network | Mind Tyrant Creative (soon!) | Kiwi Dynamic (For sale)
Mr Spy is offline   Reply With Quote
Old 11-11-2009, 02:53 AM   #7 (permalink)
NamePros Regular
 
qbert220's Avatar
Join Date: Jul 2007
Location: UK
Posts: 394
qbert220 is a splendid one to beholdqbert220 is a splendid one to beholdqbert220 is a splendid one to beholdqbert220 is a splendid one to beholdqbert220 is a splendid one to beholdqbert220 is a splendid one to beholdqbert220 is a splendid one to behold
 


Protect Our Planet
Use:

PHP Code:
echo 'PHP Version: ' phpversion()."\n"
????: NamePros.com http://www.namepros.com/showthread.php?t=622201
in your script to check whether you are actually running under PHP5.

The extension of the include files shouldn't matter (they don't even have to end with ".php").
qbert220 is offline   Reply With Quote
Old 11-11-2009, 05:17 AM THREAD STARTER               #8 (permalink)
NamePros Regular
 
pixelhero's Avatar
Join Date: May 2008
Location: England
Posts: 771
pixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to all
 


Help The Homeless - Holiday 2009
The problem has been solved.

Eric already spoke to me, i've updated php as my host had an old version installed.
pixelhero is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 02:33 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger