bdmovies Posted March 26, 2009 Share Posted March 26, 2009 Hello, I have a class that interacts with my database (simple enough) but for this particular class, the only input it is taking will be whole numbers, so I thought perhaps doing this word work: <?php class myClass extends database { function myClass($whole_num) { number validation here... if number return true if not number return "Error" } function getSomeValueFromDatabase($whole_num) { interact with database here... } } ?> However this did not work, I received a "No Database Selected" error. Besides from writing an entire validation class, is there any way to get this job done using the basic idea laid out above? Quote Link to comment Share on other sites More sharing options...
9three Posted March 26, 2009 Share Posted March 26, 2009 I cannot assist you without the code. Quote Link to comment Share on other sites More sharing options...
bdmovies Posted March 26, 2009 Author Share Posted March 26, 2009 <?php require_once ('database.class.php'); class serviceInformation extends database { function serviceInformation($serviceID) { if(!is_numeric($serviceID)) { return "Error"; } else { return true; } } function getServiceInformation($serviceID) { if(!is_numeric($serviceID)) { return "Error"; } $sql = "SELECT * FROM serviceInformation WHERE serviceID = '$serviceID'"; $result = $db->query($sql); } function getManner($serviceID) { $sql = "SELECT serviceType FROM serviceInformation WHERE serviceID = '$serviceID'"; $result = $this->query($sql); $row = $this->fetchAssoc($result); $serviceType = $row['serviceType']; $sql = "SELECT * FROM manners WHERE id = '$serviceType'"; $result = $this->query($sql); $row = $this->fetchAssoc($result); $manner = $row['manner']; return $manner; } } ?> Returns: No database selected Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /Applications/MAMP/htdocs/Zend_Workspace/Fusion/classes/database.class.php on line 57 Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /Applications/MAMP/htdocs/Zend_Workspace/Fusion/classes/database.class.php on line 57 Quote Link to comment Share on other sites More sharing options...
9three Posted March 26, 2009 Share Posted March 26, 2009 . Quote Link to comment Share on other sites More sharing options...
9three Posted March 26, 2009 Share Posted March 26, 2009 Are you connected to a database? That error is popping up because... you haven't selected a database. The problem might be in your parent class. Quote Link to comment Share on other sites More sharing options...
bdmovies Posted March 26, 2009 Author Share Posted March 26, 2009 When I take out the serviceInformation function it works. So, I'm thinking when the class gets initiated that function runs...and somehow that throws it, but I don't see why. My parent class is my Database class, which is working fine. Quote Link to comment Share on other sites More sharing options...
9three Posted March 26, 2009 Share Posted March 26, 2009 Post your objects in use Quote Link to comment Share on other sites More sharing options...
bdmovies Posted March 26, 2009 Author Share Posted March 26, 2009 <?php /* Test */ error_reporting(E_ALL); require 'classes/serviceInformation.class.php'; $serviceID = "62"; $service = new serviceInformation($serviceID); $manner = $service->getManner($serviceID); echo $manner; ?> Quote Link to comment Share on other sites More sharing options...
9three Posted March 26, 2009 Share Posted March 26, 2009 Remove the " " 62 is being treated as a string instead of an integer. Quote Link to comment Share on other sites More sharing options...
bdmovies Posted March 26, 2009 Author Share Posted March 26, 2009 That doesn't change anything. <?php $test = "52"; $test2 = 52; if(is_numeric($test)) { echo "It's a number - 1"; } if(is_numeric($test2)) { echo "It's a number - 2"; }?> Both echo the respected sentence. Quote Link to comment Share on other sites More sharing options...
9three Posted March 26, 2009 Share Posted March 26, 2009 Took a 2nd look at your objects and you arent connecting to a database. Quote Link to comment Share on other sites More sharing options...
bdmovies Posted March 26, 2009 Author Share Posted March 26, 2009 My database class is working fine, every other aspect of the program is connecting the way it should. I've found the problem, it's in the constructor function. Now my question is why would that happen? Quote Link to comment 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.