Developer Forums | About Us | Site Map
Search  
HOME > TUTORIALS > DATABASES > MYSQL TUTORIALS > EXECUTING SQL STATEMENTS IN MYSQL DATABASES USING C


Sponsors





Useful Lists

Web Host
site hosted by netplex

Online Manuals

Executing SQL statements in MySQL databases using C
By Neil Matthew & Richard Stones - 2004-02-06 Page:  1 2 3 4 5

Excerpt from Professional Linux Programming

Like PostgreSQL, MySQL can be accessed from many different languages, including C, C++, Java and Perl. Using the comprehensive C interface of MySQL, Neil Matthew and Richard Stones show us how to execute SQL statements in MySQL databases in the following sections from Chapter 5 on MySQL from Professional Linux Programming. They will look at both statements that return data, such as INSERT, and those that don't, such as UPDATE and DELETE. They will then write a simple program that retrieves data from the database.

Executing SQL statements

Now we have a connection, and know how to handle errors, it's time to look at doing some real work with our database. The principal keyword for executing SQL statements of all types is mysql_query:

int mysql_query(MYSQL *connection, const char *query)

As you can see, there is very little to it. It takes a pointer to a connection structure and a text string containing the SQL to be executed; unlike the command line tool, no terminating semicolon should be used. On success, zero is returned. In the special case that you need to include binary data, you can use a related function, mysql_real_query . For the purposes of this chapter though, we only need to look at mysql_query.



View Executing SQL statements in MySQL databases using C Discussion

Page:  1 2 3 4 5 Next Page: SQL statements that return no data

First published by IBM developerWorks


Copyright 2004-2017 GrindingGears.com. All rights reserved.
Article copyright and all rights retained by the author.