Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8144355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:21:13+00:00 2026-06-06T13:21:13+00:00

This is a snippit of my c++ code for mysql insertion. I found an

  • 0

This is a snippit of my c++ code for mysql insertion. I found an example of how to do it with mysql.h. Program runs fine until I add in the following for mysql. I am new to c++ and have found the same examples in other code, just can’t pin point the problem I have added mysql/mysql.h instead of just mysql.h and also the -i and -l to compiling as suggested through out the web and still no luck. Any help would be appreciated.

#include    <mysql/mysql.h>


string unknown = "Unknown"

MYSQL *conn;

conn = mysql_init(NULL);
mysql_real_connect(conn, "localhost", "root", "password", "alert", 0, NULL, 0);

mysql_query(conn, "INSERT INTO alert_tbl (alert_srcip, alert_country, alert_destip, alert_desthost, alert_destport, alert_bl) VALUES ('%s','%s','%s','%s','%s','%s')", src_ip,country_code,dest_ip,unknown,dest_prt,blip);

mysql_close(conn);

g++ test.c -o test -lstdc++ -I/usr/include/mysql -L/usr/lib/mysql -lmysqlclient

test.c: error: expected , or ; before MYSQL

test.c: error: conn was not declared in this scope

test.c: error: conn was not declared in this scope

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T13:21:15+00:00Added an answer on June 6, 2026 at 1:21 pm

    Missing semicolon:

    string unknown = "Unknown";
    

    The call to mysql_query has too many parameters; it is not a “printf” style function. You could use sprintf to a separate buffer at the risk of sql injection attack. You should use parameterized queries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a code snippet which connects to a MySQL database like this (not
in the book i'm learning from i came across this code snippit: while (i
I have this snippet of code: var ShopLogicOptions = {}; ShopLogicOptions.params = {orderId: '
I've found this snippet of code on the net. It sets up an NSMutableArray
I have this snippet of code private Templates retrieveFromCache(String name) { TemplatesWrapper t =
if you run this snippet of code(put it in form1) in a fresh new
I have an ancient code snippet I use for copying tables in MySQL. CREATE
I have two concurrent processes: 1.) Writer - inserts new rows into a MySQL
Hi I have this snippet of code : protected void onPostExecute(String response) { String
I have an HTML form that submits to a PHP file for MySQL insertion

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.