Reputation: 16065
I've got a simple question over here but it brings up quite a dilemma in my head right now. I'm saving IPs "the right way" but I'm having a hard time deciding whether I should turn the ip to an integer in PHP or in MySQL. It's probably going to be considered a semantic issue but what I'm looking for here primarily is speed. I personally think it's not MySQL's job to convert data, but I have a feeling MySQL is going to be faster than PHP in doing this. What will you advice me?
INSERT INTO table (ip) VALUES (INET_ATON('127.0.0.1'))
$ip = ip2long('127.0.0.1');
$db->("INSERT INTO table (ip) VALUES ($ip)");
Upvotes: 0
Views: 130
Reputation: 1152
If you are primarily in for the speed, you should benchmark your code. There is no reason why we can do that better than you.
About which would be more logical, I would say the first approach INSERT INTO table (ip) VALUES (INET_ATON('127.0.0.1'))
, because it illustrates what data you are going to store and how you are going to store that data, at the place of the actual storage function. In the second you have to look back what $ip
actually is. It could be a long, a string or whatever (altough if the code is right above it doesn't really matter). But this is all personal opinion and not really suited for SO.
Upvotes: 2