Name

mysql_query —

Synopsis

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

Executes the SQL query given in the second argument. If the query contains any binary data (particularly the null character), this function cannot be used, and mysql_real_query should be used instead. The function returns 0 if the query was successful and nonzero in the case of an error.

Once a query has been executed using this function, the result set can be retrieved using the mysql_store_result or mysql_use_result function.

Example

error = mysql_query(&mysql, "SELECT * FROM people WHERE name like 'Bill%'");
if (error) { 
     printf("Error with query!\n"); 
     exit(1);
}

Get Managing & Using MySQL, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.