I would like some advice about what would be the best practice from a design perspective when tackling this problem:
I need to: 1) somehow call this C program, or preferably a function inside this program (my_program.c) from the PHP code, 2) Access the MySQL database via the C program, and perform some calculations that would ultimately render the image desired 3) Return the results of this process (the image that was generated) to the PHP program so that it can be displayed in the browser.
Any tips would be appreciated.. Thanks.
Put the compiled program in your /cgi-bin folder and pass parameters from PHP via the query string. Make sure that your code sends out at least a Content-Type HTTP header before any image data (e.g., printf("Content-Type: image/png\r\n\r\n");
)
Use the MySQL C API.
You probably don't need to return anything to PHP. Just embed a link to the CGI application in the HTML code, e.g.,
<img src="http://example.com/cgi-bin/my-map-tool?lat=+42.5;long=-0.5" />