Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
#include <iostream>
#include <mysql.h>

using namespace std;
 
MYSQL mysql,*connection;
MYSQL_RES result;
MYSQL_ROW row;
 
char * ip = (char*)"192.168.49.131";
char * usr = (char*)"root";
char * pass = (char*)"admin";
char * db = (char*)"vcs";
 
int query_state;
 
int main (int argc, char **argv)
{
	mysql_init(&mysql);
 
	connection = mysql_real_connect(&mysql, ip, usr, pass, db, 0, NULL, 0);
 
	if (connection==NULL)
	{
		cout<<mysql_error(&mysql)<<endl;
	}
 
	else
	{
		(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;
		}
	}
	mysql_close(&mysql);
 
}
 
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
Edited 29-Feb-12 1:45am
v2
Rate this: bad
good
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
  Permalink  
Comments
CPallini at 7-Jan-13 4:06am
   
5.
Espen Harlinn at 7-Jan-13 4:11am
   
Thank you, Carlo - My congratulations for making it to the MVP list this year too :-D
CPallini at 7-Jan-13 4:24am
   
Well, it looks I am in good company! :-D
Rate this: bad
good
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.
  Permalink  
Comments
prince_rumeel at 29-Feb-12 8:41am
   
bro it has been done...............
Rate this: bad
good
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')
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 520
1 Maciej Los 290
2 Richard MacCutchan 265
3 BillWoodruff 265
4 Suraj Sahoo | Coding Passion 155
0 OriginalGriff 8,764
1 Sergey Alexandrovich Kryukov 7,437
2 DamithSL 5,639
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411028.1 | Last Updated 7 Jan 2013
Copyright © CodeProject, 1999-2014
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