Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //c201050
- //AYAT ULLAH
- #include <iostream>
- #include<bits/stdc++.h>
- #include <Windows.h>
- #include <mysql.h>
- #include <iomanip>
- #include <stdlib.h>
- #include <sstream>
- #include <stdio.h>
- using namespace std;
- class Shop{
- MYSQL* conn;
- MYSQL_ROW row;
- MYSQL_RES * res;
- int qstate;
- public:
- Shop(){
- conn = mysql_init(0);
- conn = mysql_real_connect(conn, "localhost", "root", "", "data", 0, NULL, 0);
- if(conn)
- {
- }else
- {
- cout <<" Connection failure"<<endl;
- }
- }
- string additem(string itemid,string itemname,string itemprice,string itemstock){
- int state = 0;
- stringstream ss;
- ss<<"INSERT INTO data(id,name,price,stock) values ('" << itemid<<"','" << itemname<<" ','" <<itemprice<<" ','" <<itemstock<<"')";
- string query = ss.str();
- const char * q = query.c_str();
- qstate = mysql_query(conn, q);
- if (qstate == 0)
- {
- cout <<" Record inserted successfully ..."<<endl;
- }
- else
- {
- cout <<" Error, data not inserted..."<<endl;
- }
- }
- void showitems(){
- qstate = mysql_query(conn,"SELECT * from data");
- if(!qstate){
- res = mysql_store_result(conn);
- cout<<endl;
- cout<<"id name price stock"<<endl;
- while(row = mysql_fetch_row(res)){
- cout<<row[0]<<"| "<<row[1]<<"| "<<row[2]<<"| "<<row[3]<<endl;
- }
- }
- }
- void searchitem(string name){
- string query ="SELECT * FROM data WHERE name='"+name+"'";
- const char * q = query.c_str();
- qstate = mysql_query(conn, q);
- if(!qstate){
- int c=0;
- res = mysql_store_result(conn);
- cout<<endl;
- cout<<"id name price stock"<<endl;
- while(row = mysql_fetch_row(res)){
- c++;
- cout<<row[0]<<"| "<<row[1]<<"| "<<row[2]<<"| "<<row[3]<<endl;
- }
- cout<<endl;
- cout<<"Result: total "<<c<<" data founded"<<endl;
- }
- else{
- cout<<"Error"<<endl;
- }
- }
- void editeitem(string id,string newname){
- string query ="UPDATE data set name='"+newname+"' where id ='"+id+"'";
- const char * q = query.c_str();
- qstate = mysql_query(conn,q);
- if(!qstate){
- cout<<"Updated"<<endl;
- }else{
- cout<<"Error"<<endl;
- }
- }
- void deleteitem(string id){
- string query ="DELETE from data where id ='"+id+"'";
- const char * q = query.c_str();
- qstate = mysql_query(conn,q);
- if(!qstate){
- cout<<"Deleted"<<endl;
- }else{
- cout<<"Error"<<endl;
- }
- }
- };
- using namespace std;
- int main()
- {
- Shop iiuc;
- //iiuc.additem("c201033","ayat","120","1");
- //iiuc.showitems();
- //iiuc.searchitem("MANO");
- //iiuc.editeitem("C201050","ayat");
- // iiuc.deleteitem("C201050");
- return 0;
- }
Add Comment
Please, Sign In to add comment