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 6175795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:59:10+00:00 2026-05-23T23:59:10+00:00

i am trying to insert data to database but it removing braces'{}’ while inserting

  • 0

i am trying to insert data to database but it removing braces'{}’ while inserting i am using this code.

<pre><code>
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
$aa['alt']="happy alt";
$aa['title']="happy title";
$sldata=serialize($aa);
$sql="Insert into test(pval) values('".$sldata."')";
echo $sql;
db_query($sql);    
</pre></code>

my db structure is as

<pre><code>
CREATE TABLE IF NOT EXISTS `test` (
  `sl` int(11) NOT NULL AUTO_INCREMENT,
  `pval` text NOT NULL,
  PRIMARY KEY (`sl`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1
</pre></code>

suggest me what is wrong here..

  • 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-05-23T23:59:11+00:00Added an answer on May 23, 2026 at 11:59 pm

    Drupal uses {} arround the tables names, to be able to do some manipulations on those names — like prefix them, if you have configured it to do so.

    So, you must not use {} in your query — except arround tables names, of course.

    Instead of brutaly injecting your serialized-string into the SQL query, you must use place-holders in it — and pass the corresponding values to db_query(), which will take care of escaping what has to be :

    $sldata = serialize($aa);
    $sql = "insert into {test} (pval) values('%s')";
    db_query($sql, $sldata);
    

    Here :

    • As the pval field is a string in database, I used a %s place-holder
    • And the first value passed to db_query() (after the SQL query itself, of course) will be injected by drupal, to replace that first (and only, here) placeholder.

    And, for more informations, you might want to take a look at Database abstraction layer.

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

Sidebar

Related Questions

i'm trying to insert some data on a database using this code: -(void)insertLocationOnDatabase:(LocationType *)aLocation
I'm trying to insert registration data into a database but my php code isn't
I'm trying to insert data into my SQlite3 database (this works via the command
im trying to insert data into a particular row in the database, but i
I was trying to insert new data into an existing XML file, but it's
While trying to bulk insert 3M records from CSV file to SQLExpress database the
Trying to insert values with Unicode Chars into a MySQL-database using Delphi 2010 and
i'm trying to insert multiple data using a query, i've tried the implode function,
I'm using Ocilib to perform a bulk insert on a Oracle database but I'm
I'm trying to get started with Hibernate, but can't insert data, for some reason.

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.