YourNameHere Posted October 24, 2009 Share Posted October 24, 2009 I have a select query. Then I have a that query populate a mysql_fetch_object(). I realized that the fetch object wasn't being populated. So I echoed it out and here are the results: Catchable fatal error: Object of class stdClass could not be converted to string in... Here is the relevant code: $link = mysql_connect($server, $db_user, $db_pass); mysql_select_db($db); $cname = "Cody"; $getSkills = "Select * FROM skills where cname = '$cname'"; $b = mysql_query($getSkills); $a = mysql_fetch_object($b); ... echo $a; I know that stdClass is the base class that all other classes extend in php. This is a new error that I haven't seen before. Quote Link to comment https://forums.phpfreaks.com/topic/178810-solved-catchable-error/ Share on other sites More sharing options...
trq Posted October 24, 2009 Share Posted October 24, 2009 You cannot echo an object. Simple. And mysql_fetch_object always returns a stdClass unless you pass it a class via its second arg. You need to debug your call to mysql_query. Quote Link to comment https://forums.phpfreaks.com/topic/178810-solved-catchable-error/#findComment-943301 Share on other sites More sharing options...
YourNameHere Posted October 24, 2009 Author Share Posted October 24, 2009 You cannot echo an object. Simple. And mysql_fetch_object always returns a stdClass unless you pass it a class via its second arg. You need to debug your call to mysql_query. So, you're saying that the query isn't returning any results and the is why the fetch_object is returning an object instead of an array (which I would be able to echo)? Quote Link to comment https://forums.phpfreaks.com/topic/178810-solved-catchable-error/#findComment-943312 Share on other sites More sharing options...
trq Posted October 24, 2009 Share Posted October 24, 2009 So, you're saying that the query isn't returning any results and the is why the fetch_object is returning an object instead of an array (which I would be able to echo)? No. As the name suggests mysql_fetch_object returns an object, mysql_fetch_array returns an array. Either way, you cannot simply echo an array either. You can either use print_r to view the objects (or arrays) contents, or loop through its properties / indexes. Quote Link to comment https://forums.phpfreaks.com/topic/178810-solved-catchable-error/#findComment-943315 Share on other sites More sharing options...
YourNameHere Posted October 25, 2009 Author Share Posted October 25, 2009 Then how would I reference a column from the result if I use fetch_array? $a->columnName ? Because that isn't working. Quote Link to comment https://forums.phpfreaks.com/topic/178810-solved-catchable-error/#findComment-943825 Share on other sites More sharing options...
trq Posted October 25, 2009 Share Posted October 25, 2009 Then how would I reference a column from the result if I use fetch_array? $a->columnName ? Because that isn't working. Because array indexes are referenced via [], you access an objects properties using -> $a['columnName'] This really is beginners stuff and should probably be learnt well before trying to deal with databases. Quote Link to comment https://forums.phpfreaks.com/topic/178810-solved-catchable-error/#findComment-943831 Share on other sites More sharing options...
YourNameHere Posted October 25, 2009 Author Share Posted October 25, 2009 I know it's beginner stuff and I am just having a momentary lapse of intelligence (I knew all this at one point). Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/178810-solved-catchable-error/#findComment-943860 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.