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

  • SEARCH
  • Home
  • 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 9254111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:23:06+00:00 2026-06-18T11:23:06+00:00

I want to insert multiple rows of data in a single column using a

  • 0

I want to insert multiple rows of data in a single column using a single query. This program is for less data. I have another weather monitoring .txt file which had 4000 lines of data. I can insert one data at a time but it becomes tedious for so many data values.

1.     use DBI;
2.     use DBD::mysql;
3.     use warnings;


4.     $connection = ConnectToMySql($database);

5.   # Multiple Data inputs
6.      $myquery = "INSERT INTO data(datatime,battery)
7.           VALUES
8.             (?,?),
9.             ('16.01.2013','6.54'), #data corresponding to date and battery
10.             ('17.01.2013','6.42'),
11.             ('21.01.2013','6.24'),
12.             ('22.01.2013','6.21'),
13.             ('24.01.2013','6.17'),
14.             ('25.01.2013','6.13'),
15.             ('28.01.2013','6.00'),
16.             ('29.01.2013','5.97'),
17.             ('30.01.2013','5.94'),
18.             ('01.02.2013','5.84')";
19.    $statement2 = $connection->prepare($myquery);

20.     $statement2->execute($myquery);

21.    #--- start sub-routine
22.    sub ConnectToMySql {
23.       $database ="xxxx";
24.       $user = "XXXX";
25.       $pass = "XXXX";
26.       $host="XXXX";
27.    my $dbh = DBI->connect("DBI:mysql:$database:$host", $user, $pass);
28.    }

This code is giving me the following errors:

DBD::mysql::st execute failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ” at line 2 at C:/Users/User/workspace/DataBaseEntry/DataEntry.pl line 20.
DBD::mysql::st execute failed: called with 1 bind variables when 2 are needed at C:/Users/User/workspace/DataBaseEntry/DataEntry.pl line 40.

I cannot identify the problem. Is it the placeholder. What can i do to improve it?
I am new to these things. so can you keep it simple.
THANKS

  • 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-18T11:23:07+00:00Added an answer on June 18, 2026 at 11:23 am

    You should be passing the data values which should replace the (?, ?) as parameters to execute. Your code as written only passes a single parameter to execute and that parameter is the SQL text of your query.

    Try this instead:

    $myquery = "INSERT INTO data(datatime,battery) VALUES (?,?)";
    my $sth = $connection->prepare($myquery);
    
    $sth->execute('16.01.2013','6.54');
    $sth->execute('17.01.2013','6.42');
    $sth->execute('21.01.2013','6.24');
    $sth->execute('22.01.2013','6.21');
    $sth->execute('24.01.2013','6.17');
    $sth->execute('25.01.2013','6.13');
    $sth->execute('28.01.2013','6.00');
    $sth->execute('29.01.2013','5.97');
    $sth->execute('30.01.2013','5.94');
    $sth->execute('01.02.2013','5.84');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL query where I want to insert multiple rows in single
I want to insert multiple rows into a DB2 table. I have a query
so I'm having trouble properly creating this query. Basically, I want to insert multiple
i want to insert multiple rows in a loop using doctrine 2.. i usually
I want to insert mutiple rows in mysql table using php. Data is in
I have a JavaScript object with multiple rows of data and I want to
I want to insert multiple rows of data into a MySQL database, but only
I'm trying to insert multiple rows using SqlCommand from C# to SQL Server. I'm
I want to insert multiple rows into different tables in my database. The statements
I want to insert this XML data into SQL Server 2008 <rewriteMap name=OldStaticUrl> <add

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.