2

I am currently running a script that pulls back transaction data (one line for each transaction) from a database with the following SQL script, which is being run in MySQL Workbench.

SELECT 
id,
merchant_id, 
affiliate_id, 
date, 
sale_amount, 
commission, 
ip

FROM transactions.transaction201505  

One of the columns in the table t.transactions is IP address. Is there a way to embed this PHP script (or a function to this effect) within an SQL script: php function geoip_country_name_by_addr http://php.net/manual/en/function.geoip-country-code-by-name.php

I have seen many examples of adding MySQL to PHP but would like to essentially add in Country/ City of sale to my data the other way around, so that the result could look like the sample below, which could be run off a tool such as MySQL Workbench. I don't have access to run PHP scripts on this database, and therefore need a solution with SQL.

Thanks in advance for any help you can offer on this.

Jamie

enter image description here

1 Answer 1

1

No, this is not directly possible. You could write a UDF (user define function) in an exteranl module (e.g. a .DLL, .so or .dylib) but using PHP in such a module is probably not possible either (because PHP is a scripting language and you would need to compile your UDF into binary code). However, MySQL has a number of built-in functions (https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html). Even though not what you want here.

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

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.