Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Mysqli fetch object issue



9:29 pm on May 4, 2014 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

Hi there Guru's of php!

I've not posted on here for ages, and now in the midst of a project that I need advise on.

echo mysqli_fetch_object(Mysqli_Query("Select * FROM Somedb where ID = 1 LIMIT 1"))->FieldReturned;

Why doesn't this work? In know as it's not the best practice to have no error catching on there, but for now that's not my concern - I can't understand why nested functions don't work like this anymore.

I've a feeling as it's because it needs to be iterated through? Because the nature of the return data of this function is that it's in array format (index/relational), so potentially I could get this going by doing:-

while ($got = Mysqli_fetch_object("something to query")) $got->FieldReturned;

Any thought's on this?

Been so long since I've written php now too, just a bit rusty - still got the graphical skills to shame my little bro!



12:03 pm on May 6, 2014 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

Hey Matt, good to see you again :)

mysqli_query, when used in the procedural style as above, its first parameter should be the database connection.


$link = mysqli_connect(...
echo mysql_fetch_object(mysqli_query($link, 'select...

Method chaining does still work as long as each method returns a valid object.

Personally, I'd recommend switching to the OO style:

$db = new mysqli(...
$result = $db->query('select...
echo $result->fetch_object()->column_name;


12:13 pm on May 10, 2014 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

Hi there Readie,

That's made me smile seeing as you're still being the helpful soul that I remember! Yes been a while, but been really engrossed in a .net project - I digress.

I see that going from Mysql_ to Mysqli_ means that they've swapped the parameters around - gee, thanks guys!

Well, curiously I'm just proving a method that I'm then going to pop into a class, so the OOp method is the one I'm trying to get sorted.

I might send you my starting file to see if I'm going the right way, I mean 4 years off, I'm quite rusty and would appreciate the pointer.

For now, thanks for the advise. I'll DM you this week at somepoint.


Featured Threads

Hot Threads This Week

Hot Threads This Month