homepage Welcome to WebmasterWorld Guest from 54.166.84.82
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Mysqli fetch object issue
Matthew1980

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4668455 posted 9:29 pm on May 4, 2014 (gmt 0)

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!

Cheers,
MRb

 

Readie

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4668455 posted 12:03 pm on May 6, 2014 (gmt 0)

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.

So.

$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;

Matthew1980

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4668455 posted 12:13 pm on May 10, 2014 (gmt 0)

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.

Cheerio.
MRb

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved