Throwing mysqli result object into massive practice?

I was wondering if I have some code like:

$result = $db->query($sql); // dont worry, its escaped
$myData = (array)$result->fetch_assoc();  

      

Where

$result->fetch_assoc();

      

returns mysqli result object.

Is this exactly the case? I would assume that this is an expensive call - is it true?

It's pretty sure it's convenient to use right after the request for it, but I want to make sure I'm not doing anything bad.

Thanks for any input,

0


a source to share


2 answers


According to mysqli documentation , it returns an array anyway ...



+7


a source


If there is no more result, it will return NULL. In this case, (array) null might make some sense.



It is really better to check for special cases in a separate place instead of type casting

0


a source







All Articles