JDMallion Posted June 28, 2010 Share Posted June 28, 2010 Hi Guys, I am trying to build my application on my local test server (I have tried both WAMP and XAMPP just in case they were the problem) and I just keep getting the following error: Fatal error: Class 'MySQL' not found in C:\xampp\htdocs\webaddress.co.uk\php\core.php on line 44 The class file is being included because if I force an error in the file then it picks it up and displays an error! The code for including the class file is: switch ( database_type ) { case "MySQL": require_once ( core_dir."class.my-sql.php" ); $db = new MySQL( database_host, database_user, database_password, database_name ); $db->setNames( "utf8" ); break; } Really at a loss and any help would be appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/206046-php-class-not-found/ Share on other sites More sharing options...
Mchl Posted June 28, 2010 Share Posted June 28, 2010 Don't you mean mysqli ? Quote Link to comment https://forums.phpfreaks.com/topic/206046-php-class-not-found/#findComment-1078123 Share on other sites More sharing options...
JDMallion Posted June 28, 2010 Author Share Posted June 28, 2010 Nope, I have a class called MySQL. But it is not just an issue with this specific class I just commented out the MySQL class and the smarty class that is being include below throws the same error! :'( require_once ( smarty_dir."Smarty.class.php" ); $tpl = new Smarty(); Quote Link to comment https://forums.phpfreaks.com/topic/206046-php-class-not-found/#findComment-1078125 Share on other sites More sharing options...
trq Posted June 28, 2010 Share Posted June 28, 2010 Set error_reporting to E_ALL and make sure you have display errors on. Obviously your call to require_once is failing and your error reporting is set to low to see any helpful information. Quote Link to comment https://forums.phpfreaks.com/topic/206046-php-class-not-found/#findComment-1078132 Share on other sites More sharing options...
JDMallion Posted June 28, 2010 Author Share Posted June 28, 2010 Error reporting is set to E_ALL and it is still only displaying the Fatal Error message. The files are being included because if I force an error by putting some random letters in there is throws a PHP error......really do not understand what is going on! Quote Link to comment https://forums.phpfreaks.com/topic/206046-php-class-not-found/#findComment-1078135 Share on other sites More sharing options...
Mchl Posted June 28, 2010 Share Posted June 28, 2010 Perhaps show us how the class is being declared in this file? Quote Link to comment https://forums.phpfreaks.com/topic/206046-php-class-not-found/#findComment-1078139 Share on other sites More sharing options...
JDMallion Posted June 28, 2010 Author Share Posted June 28, 2010 Please find the file attached, thanks for your help with this!! [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/206046-php-class-not-found/#findComment-1078142 Share on other sites More sharing options...
travo1992 Posted June 28, 2010 Share Posted June 28, 2010 Just to test, if you instaniate the class inside the file, what happens? Also, the exit($host); in MySQL->MySQL(), is that just you trying to find the error? Quote Link to comment https://forums.phpfreaks.com/topic/206046-php-class-not-found/#findComment-1078262 Share on other sites More sharing options...
JDMallion Posted June 28, 2010 Author Share Posted June 28, 2010 Yep the exit is just me finding the error and if I initiate inside the file then give the same error!! Stupid thing is I just tested it on our live web server and it runs fine so must be something to do with the PHP setup! Thanks again for all the help! Quote Link to comment https://forums.phpfreaks.com/topic/206046-php-class-not-found/#findComment-1078267 Share on other sites More sharing options...
PFMaBiSmAd Posted June 28, 2010 Share Posted June 28, 2010 Is your live server also a Windows server and using the same php version as where your code does not work, because php.net has had a lot of bugs concerning resolving include/require paths and getting the _once versions to see the correct files. Do you have more than one class.my-sql.php file present in other folders? Does this work if you just use require() and not the _once version? What is your core_dir value? Quote Link to comment https://forums.phpfreaks.com/topic/206046-php-class-not-found/#findComment-1078384 Share on other sites More sharing options...
travo1992 Posted June 29, 2010 Share Posted June 29, 2010 Can you please post the results of var_dump(core_dir, is_file(core_dir."class.my-sql.php")); Also try chucking an exit or die before you declare the class, see what you get. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/206046-php-class-not-found/#findComment-1078558 Share on other sites More sharing options...
JDMallion Posted June 29, 2010 Author Share Posted June 29, 2010 The response to the var_dump was: string(45) "http://localhost/webaddress.co.uk/php/" bool(false) and throwing an exit; before the class is declared I get the same message: Fatal error: Class 'MySQL' not found in C:\xampp\htdocs\webaddress.co.uk\php\core.php on line 44 So looks like the class is just not being declared!! For some damn reason! Quote Link to comment https://forums.phpfreaks.com/topic/206046-php-class-not-found/#findComment-1078607 Share on other sites More sharing options...
JDMallion Posted June 29, 2010 Author Share Posted June 29, 2010 Is your live server also a Windows server and using the same php version as where your code does not work, because php.net has had a lot of bugs concerning resolving include/require paths and getting the _once versions to see the correct files. Do you have more than one class.my-sql.php file present in other folders? Does this work if you just use require() and not the _once version? What is your core_dir value? Does not work with require or include, have tried that one Do not have more than one class and my core path is: http://localhost/webaddress.co.uk/php/ Just had a thought the use of a URL could have something to do with it, but I have turned on the setting that allows URLs. Quote Link to comment https://forums.phpfreaks.com/topic/206046-php-class-not-found/#findComment-1078608 Share on other sites More sharing options...
JDMallion Posted June 29, 2010 Author Share Posted June 29, 2010 Ha ha, just tested it with: C:/xampp/htdocs/webaddress.co.uk and is now working, how stupid of me! Thank you everyone for your help, these forums are great! Never would have worked that out! Quote Link to comment https://forums.phpfreaks.com/topic/206046-php-class-not-found/#findComment-1078609 Share on other sites More sharing options...
trq Posted June 29, 2010 Share Posted June 29, 2010 Urls are executed as web pages by the server, hence all you where getting was the output your class.my-sql.php script produced which is likely a blank page. Quote Link to comment https://forums.phpfreaks.com/topic/206046-php-class-not-found/#findComment-1078615 Share on other sites More sharing options...
travo1992 Posted June 29, 2010 Share Posted June 29, 2010 Hehe glad you got it working Quote Link to comment https://forums.phpfreaks.com/topic/206046-php-class-not-found/#findComment-1078638 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.