Welcome Guest, Not a member yet? Register   Sign In
DataMapper - Using INET_NTOA/INET_ATON?
#1

[eluser]sorenchr[/eluser]
I recently started using DataMapper, great tool. I'm trying to use MySQL's INET_ATON to store a users IP (in a numerical value), and then retrieve the IP using INET_NTOA, however I don't know if DataMapper even supports these the use of these functions. Anyone with some DMZ experience who knows if this can be done?

MySQL documentation on INET_NTOA/INET_ATON:
http://dev.mysql.com/doc/refman/5.0/en/m..._inet-aton

Thanks for your time!
#2

[eluser]Basketcasesoftware[/eluser]
DataMapper allows direct access to ALL of MySQL's functions. Let see if I can find the part in the manual again.
#3

[eluser]Basketcasesoftware[/eluser]
use the func method on your data object. It allows you to call any mySQL function, built in or user. Look under SQL Functions.
#4

[eluser]sorenchr[/eluser]
Do you know how to set it up if I want to save to the db using INET_ATON? Something like:
I've set the users ip to:

Code:
$user->last_ip = $_SERVER['REMOTE_ADDR'];

But adding something like:

Code:
$user->func('INET_ATON', '@last_ip');

doesn't work. Any ideas?
#5

[eluser]Basketcasesoftware[/eluser]
[quote author="sorenchr" date="1297839898"]Do you know how to set it up if I want to save to the db using INET_ATON? Something like:
I've set the users ip to:

Code:
$user->last_ip = $_SERVER['REMOTE_ADDR'];

But adding something like:

Code:
$user->func('INET_ATON', '@last_ip');

doesn't work. Any ideas?[/quote]

I admit I'm not familiar with the '@varible' argument type. Actually I've been exposed to it but don't remember details.

What kind of arguments is INET_ATON requiring?
#6

[eluser]KarlBallard[/eluser]
INET_ATON()
- Return the numeric value of an IP address

INET_NTOA()
- Return the IP address from a numeric value
#7

[eluser]Basketcasesoftware[/eluser]
Ok, that's what it does, but under the hood what is an 'IP address' to mySQL? 4 bytes?
I mean, all he might require is
Code:
$user->last_ip = $_SERVER['REMOTE_ADDR'];  
$user->func('INET_ATON', $user->last_ip);

It depends a lot on what $_SERVER['REMOTE_ADDR'] is.
#8

[eluser]sorenchr[/eluser]
[quote author="Basketcasesoftware" date="1297847405"]Ok, that's what it does, but under the hood what is an 'IP address' to mySQL? 4 bytes?
I mean, all he might require is
Code:
$user->last_ip = $_SERVER['REMOTE_ADDR'];  
$user->func('INET_ATON', $user->last_ip);

It depends a lot on what $_SERVER['REMOTE_ADDR'] is.[/quote]

$_SERVER['REMOTE_ADDR'] contains the visitors IP-address in it's normal form, for example: 175.142.012.121.

I tried the sample you provided, it didn't work. I think the DMZ documentation lacks some clarity on this part, I absolutely cannot figure out how to do this.
#9

[eluser]Basketcasesoftware[/eluser]
You're just trying to record an IP address, right? CodeIgniter has some helper functions for that. All you have to do is record whatever they spit out in your database. You don't need any special function for that as far as I know.
#10

[eluser]sorenchr[/eluser]
Well, I want to use the MySQL functions because they are easy and allows you to store an IP-address as an integer. Surely there must be someone on this forum who knows how to use DMZ's func methods.




Theme © iAndrew 2016 - Forum software by © MyBB