Re: MySql and C

1999-12-06 Thread Shao Zhang
Hi,
Raphaël Barbate [EMAIL PROTECTED] wrote:
   That's why I ask you if you could send me an
 example (.c), which connects to mysql and performs
 some queries.

Here are some examples:

// Extablish a tcp connection with the SQL database
int connectSQL()
{
MYSQL   *tmp;

tmp = mysql_connect(sqlHandle, SQL_HOST, SQL_USER, SQL_PASS);

if (tmp == NULL)
return 0; // failed to establish connection with the SQL server

return (!mysql_select_db(sqlHandle, SQL_DB));
}

// below are for queries
sprintf(query_string,
INSERT INTO tran_request VALUES(\'%16s\', \'%20s\', \'%8s\', \'%1s\', 
\'%4s\', \'%20s\', \
\'%4s\', \'%12s\', SYSDATE()), \
TxnReference, login, ClientID, TransactionType, AccountNumber, \
CardData, CardExpiryDate, TotalAmount);

query = mysql_query(sqlHandle, query_string);
if (query) {
error(query_string, NO_EXIT);
error(Error when updating the database for transaction 
request, \ 
see above query string for deails, EXIT);
}


// using the fetched queries
sqlResult = mysql_store_result(sqlHandle);
sqlRow = mysql_fetch_row(sqlResult);

mysql_free_result(sqlResult);

if (*sqlRow == NULL)
blah and so on

Hope this helps...

Shao.

-- 

Shao Zhang - Running Debian 2.1  ___ _   _
Department of Communications/ __| |_  __ _ ___  |_  / |_  __ _ _ _  __ _ 
University of New South Wales   \__ \ ' \/ _` / _ \  / /| ' \/ _` | ' \/ _` |
Sydney, Australia   |___/_||_\__,_\___/ /___|_||_\__,_|_||_\__, |
Email: [EMAIL PROTECTED]  |___/ 
_


MySql and C

1999-12-05 Thread Raphaël Barbate
Hi!

I'm a student in an engeneer school and I have
to use mysql in C. However, I haven't any sample of
code, just the API, that I don't understand.

That's why I ask you if you could send me an
example (.c), which connects to mysql and performs
some queries.

Thanks

Raphaël Barbate