Click here to Skip to main content
13,352,408 members (60,222 online)
Rate this:
Please Sign up or sign in to vote.
See more:
#include <iostream>
#include <mysql.h>

using namespace std;

MYSQL mysql,*connection;
MYSQL_RES result;

char * ip = (char*)"";
char * usr = (char*)"root";
char * pass = (char*)"admin";
char * db = (char*)"vcs";

int query_state;

int main (int argc, char **argv)

	connection = mysql_real_connect(&mysql, ip, usr, pass, db, 0, NULL, 0);

	if (connection==NULL)

		(mysql_query(&mysql, "INSERT into 'vcs'.'users' ('id', 'fname', 'sname') VALUES ('3', 'rana', 'sameer')"));
		if (query_state !=0) {
		cout << mysql_error(connection) << endl;
		return 1;


I am using this code for establish the connection with my phpmyadmin sql
and I get succeed.
but the following data is not entered in my database.
how can I do this???
Posted 29-Feb-12 1:42am
Updated 29-Feb-12 1:45am
Jochen Arndt220.2K
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I'd try to pass connection and not &mysql to the mysql_query function.

Best regards
Espen Harlinn
CPallini 7-Jan-13 4:06am
Espen Harlinn 7-Jan-13 4:11am
Thank you, Carlo - My congratulations for making it to the MVP list this year too :-D
CPallini 7-Jan-13 4:24am
Well, it looks I am in good company! :-D
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

I think it's a lack of commit after insertion. Could you try a querry for creating tables (as creatin tables does not require a commit). if it works that mean that u miss to end your code with a commit querry.
prince_rumeel 29-Feb-12 8:41am
bro it has been done...............
Rate this: bad
Please Sign up or sign in to vote.

Solution 5

Your query is wrong, you wrote your query like below:

INSERT into 'vcs'.'users' ('id', 'fname', 'sname') VALUES ('3', 'rana', 'sameer')

Change your query to below:

INSERT into `vcs`.`users` (`id`, `fname`, `sname`) VALUES ('3', 'rana', 'sameer')

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.180111.1 | Last Updated 7 Jan 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100