Do i loose speed?

I have public function user_data()

I need to return username, avatar and level so it would be:

$username = $main->user_data($user, "username"));
$avatar = $main->user_data($user, "avatar"));
$avatar = $main->user_data($user, "level"));

or i could use query without function:

$stmt = $main->con->prepare('SELECT username, avatar, level FROM users WHERE id=?');
$stmt->execute([$user]);			
$row = $stmt->fetch();

The question is do i lose time when i select data via function?
I believe that i connect 3 times more if i use function so it is slower?

What results do you get when you test it out? Run the queries a thousand times in each way, maybe with different data in case something is caching the results, and time both for comparison.

I’m not sure what database engine you’re using, but I’ve been doing some stuff with MS SQL Server recently and I’m told that does a thing called “connection pooling” which in theory means that although I’m connecting and disconnecting all over the place, the runtime optimises things.

You don’t connect 3 times, but you’re asking 3 questions where you could have asked one. That’s pretty much always going to be slower.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.