seany123 Posted November 9, 2009 Share Posted November 9, 2009 Why am i getting this fatal error? Fatal error: Call to a member function fetchrow() on a non-object function getUsersName( $id ) { global $config_server, $config_database, $config_username, $config_password; $db = new DB( $config_server, $config_username, $config_password, $config_database ); $player2 = $db->searchQuery( "SELECT * FROM players WHERE id = '" . $id . "'" ); $name = $player2->fetchrow(); $exists = $player2->recordcount(); if ($exists == 1){ return $player2[0][ 'username' ]; } else{ return $player->username; } } // ends function... anyone know? thanks Quote Link to comment https://forums.phpfreaks.com/topic/180857-help-me-please-with-fatal-error/ Share on other sites More sharing options...
ToonMariner Posted November 9, 2009 Share Posted November 9, 2009 means the query didn't return anything. Either print the error or echo out the query and copy it to your db admin app and run the query - it will tell you what is wrong. Quote Link to comment https://forums.phpfreaks.com/topic/180857-help-me-please-with-fatal-error/#findComment-954108 Share on other sites More sharing options...
Adam Posted November 9, 2009 Share Posted November 9, 2009 Can't see your code so can't say for sure, but shouldn't it be something more like: $name = $db->fetchrow($player2); Quote Link to comment https://forums.phpfreaks.com/topic/180857-help-me-please-with-fatal-error/#findComment-954109 Share on other sites More sharing options...
seany123 Posted November 9, 2009 Author Share Posted November 9, 2009 Can't see your code so can't say for sure, but shouldn't it be something more like: $name = $db->fetchrow($player2); that just gave this error: Fatal error: Call to undefined method DB::fetchrow() Quote Link to comment https://forums.phpfreaks.com/topic/180857-help-me-please-with-fatal-error/#findComment-954111 Share on other sites More sharing options...
Adam Posted November 9, 2009 Share Posted November 9, 2009 Clue's in the error. Where exactly is the "fetchrow()" method contained? Is it spelled right / correct grammar? Quote Link to comment https://forums.phpfreaks.com/topic/180857-help-me-please-with-fatal-error/#findComment-954113 Share on other sites More sharing options...
ToonMariner Posted November 9, 2009 Share Posted November 9, 2009 the clue IS in the error - 'on a non-object'... the query returns an object that can be traversed - as the query failed no object was returned hance when you try to do anything with said object you get an error Quote Link to comment https://forums.phpfreaks.com/topic/180857-help-me-please-with-fatal-error/#findComment-954115 Share on other sites More sharing options...
seany123 Posted November 9, 2009 Author Share Posted November 9, 2009 edit: there are no spelling mistakes i dont know what else to do. Quote Link to comment https://forums.phpfreaks.com/topic/180857-help-me-please-with-fatal-error/#findComment-954118 Share on other sites More sharing options...
PFMaBiSmAd Posted November 9, 2009 Share Posted November 9, 2009 There is no point in randomly trying code or guessing what the code should be. What database class are you using so that someone could tell you how to do some error checking, error reporting, and error recovery to get it to tell you why the query is failing? Quote Link to comment https://forums.phpfreaks.com/topic/180857-help-me-please-with-fatal-error/#findComment-954119 Share on other sites More sharing options...
seany123 Posted November 9, 2009 Author Share Posted November 9, 2009 what do you mean what class am i using? Quote Link to comment https://forums.phpfreaks.com/topic/180857-help-me-please-with-fatal-error/#findComment-954121 Share on other sites More sharing options...
ToonMariner Posted November 9, 2009 Share Posted November 9, 2009 new DB is that the pear DB class? which database - mysql, mssql db2 oracle? fact is your query fails that is why you have no results to loop over... Quote Link to comment https://forums.phpfreaks.com/topic/180857-help-me-please-with-fatal-error/#findComment-954144 Share on other sites More sharing options...
seany123 Posted November 9, 2009 Author Share Posted November 9, 2009 im using mysql database. Quote Link to comment https://forums.phpfreaks.com/topic/180857-help-me-please-with-fatal-error/#findComment-954259 Share on other sites More sharing options...
seany123 Posted November 9, 2009 Author Share Posted November 9, 2009 i tried editing the code a little and now im getting this error: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1 function getUsersName( $id ) { global $config_server, $config_database, $config_username, $config_password; $db = new DB( $config_server, $config_username, $config_password, $config_database ); $player2 = $db->searchquery('select * from `players` where `id`=?', array($id)); $name = $player2->fetchrow(); $exist = $player2->recordcount(); if ($exist == 1){ return $player2[0][ 'username' ]; } else if($exist <= 0){ return $player->username; } } // ends function... Quote Link to comment https://forums.phpfreaks.com/topic/180857-help-me-please-with-fatal-error/#findComment-954267 Share on other sites More sharing options...
mikesta707 Posted November 9, 2009 Share Posted November 9, 2009 you need to tell us what Database class you are using. or at least show the searchquery method. Without that information, any advice we could give would be shots in the dark. by the way you only need to use backticks when you are using reserved words in mysql Quote Link to comment https://forums.phpfreaks.com/topic/180857-help-me-please-with-fatal-error/#findComment-954268 Share on other sites More sharing options...
seany123 Posted November 9, 2009 Author Share Posted November 9, 2009 you need to tell us what Database class you are using. or at least show the searchquery method. Without that information, any advice we could give would be shots in the dark. by the way you only need to use backticks when you are using reserved words in mysql okay i removed the backticks... here is the function for the searchQuery: public function searchQuery( $sql ) { $query = $this->query( $sql ); return $this->returnArray( $query ); } // ends method... code im using now and still getting same error: function getUsersName( $id ) { global $config_server, $config_database, $config_username, $config_password; $db = new DB( $config_server, $config_username, $config_password, $config_database ); $player2 = $db->searchQuery("select * from players where id=?", array($id)); $name = $player2->fetchrow(); $exist = $player2->recordcount(); if ($exist == 1){ return $player2[0][ 'username' ]; } else if($exist <= 0){ return $player->username; } } // ends function... Quote Link to comment https://forums.phpfreaks.com/topic/180857-help-me-please-with-fatal-error/#findComment-954271 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.