I had been trying to find hooking up to database from C program. However I thought the ODBC connections, logon and all sorts of take some libraries. Also I'm getting a small compiler like Small C Compiler which becomes manifest pretty quickly. I don't want to make use of any ODBC logic etc which is required to connect and query the database.

And So I am utilizing a method that is the following.

I personally use a bteq script (teradata) that will have login, query, logoff instructions for the reason that. (FYI bteq is really a command line database utility. Technology-not only much like mysql.exe in command prompt by visiting the road from the exe. You are able to replace bteq with mysql.exe etc). And That I use

system("bteq <myscript.txt >out.txt");

myscript.txt is going to be such as the following..

.logon boxname/user,password;
select date;

The above mentioned script will logon towards the database and query date (you are able to alter the query and write script based on your database engine as well as your needs) and provide output into out.txt.

Now I'll parse the out.txt for that row X column I would like using fgetc,fscanf or fgets. And employ the information for checking and send a mail using PHP on any server

system("c:/server/php/php.exe sendmail.php");.

We are able to perform the same for a lot of a database engines like mysql, .. etc via a simple C program.

Now my real question is Can there be any flaw within the above method. If it's then how do i overcome it. I'm asking this because I believe this process is unconventional. Please give your thinking about this method. I do not stress about time required for execution, RAM used, performance issues etc.I understand system() fuction 's time consuming which isn't my concern anyway. I additionally developed specific functions to gain access to query results (much like being able to access a set file). Please let me know for those who have any enhancements for this method. Should you become familiar with associated with a defects within this please tell me. A myriad of suggestions are welcome.

My atmosphere is : teradata bteq on home windows with Small C Compiler

This can be a perfectly fine means to access an exterior database, as lengthy as the needs are pretty straight forward. If you know concerning the performance and memory implications to do this, plus there is very little more to express.

I would not recommend this in case your calling code is running setuid or setgid, but for the reason that situation you could utilize among the exec() functions rather. (You will find a couple of other factors you may decide to consider, all detailed in man 3 system.)

The technique is okay: it is good to decouple the db subsystem and also the parser subsystem by applying them within an appropriate language.

There's this small little factor - however i might be mistaken because I am unfamiliar with bteq: this program will require a bteq script set up in the execution folder this script will contain account information. If individuals aren't encripted in some manner, there can be a burglar flaw.