0

tI'm almost there in getting MySQL to do a geoip lookup in the locally stored maxmind database. Instructions I've been following work when using the command line mysql > syntax for retrieving records. such as:

mysql> SELECT   glc.*
   FROM     geoip_blocks gbl
            JOIN geoip_locations glc
            ON       glc.glc_id = gbl.gbl_glc_id
   WHERE    gbl_block_start <= INET_ATON('149.156.1.4')
   ORDER BY gbl_block_start DESC
   LIMIT    1\G  

However, I am having difficulty translating this to a mysql query in a php script.

I've tried:

`Select glc.* from geoip_blocks gbl JOIN geoip_locations glc ON glc.glc_id = gbl.gbl_glc_id WHERE    gbl_block_start <= INET_ATON('149.156.1.4') ORDER BY gbl_block_start DESC LIMIT 1\G` 

But this doesn't work. I'm sure this is an easy fix but I'm stumped.

0

2 Answers 2

1

The mysql command-line has a \G macro, but no such thing exists in raw SQL. Leave that out. It's not necessary to include a ; either.

Sign up to request clarification or add additional context in comments.

Comments

0

Your php script should look something like this:

//set connection up
$mysql = new mysqli('mysql_server', 'mysql_user_name', 'mysql_password','mysql_DB');

//query
$sql = "SELECT glc.*
        FROM geoip_blocks gbl
        JOIN geoip_locations glc ON glc.glc_id = gbl.gbl_glc_id
        WHERE gbl_block_start <= INET_ATON('149.156.1.4')
        ORDER BY gbl_block_start DESC
        LIMIT 1";  

//run query & store result
$result = $mysql->query($sql);

//take a look at the results
if($result){
    while($row = $result->fetch_assoc()){

        var_dump($row);

    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.