Is this even possible, does my title of this question makes sense?
I am struggling and trying to figure out the way to get all from database table
, but I need to run a function wether SQL or PHP.
So real short example would be:
SELECT * FROM `table` WHERE `ip` = '$this->ip'
However I am using INET_ATON()
to store the IP
and INET_NTOA()
to retrieve it back. I could've also use PHP's function ip2long()
and long2ip()
, but still I don't know how would I accomplish such a thing using the same query?
SELECT `id`, INET_NTOA(`ip`) as `ip`, `points`
FROM `table` WHERE `ip` = INET_ATON('$this->ip')
Those are all table columns
defined manually to get to the point of what I need to do exactly. But... For this simple project it seems alright to do it this way, but what if I had more columns and only some of them or one of them require some converting?
So how can I accomplish something like... (I know that this is invalid)
SELECT * FROM `table` WHERE `ip` = '$this->ip` BUT INET_NTOA(`ip`) as `ip`
Beside this question, I also wonder is INET_ATON() & INET_NTOA()
only MySQL function
or SQL
function. Because I am planning to rewrite my project to use PDO
instead of MySQLi
and I am unsure wether those functions will work or I should rely on PHP's built-in same functionality.