How to save it in the mysql database in Drupal?

Posted on 2012-08-15
Last Modified: 2012-08-15
I created a New Module called test and it has two variables firstname, lastname and having validation too...
Now, I need to save it in the mysql database from the code. Could anyone please help me out on this. I'm new to Drupal.
Thanks in advance!
Question by:sharon212
    LVL 12

    Expert Comment

    Drupal uses an abstraction layer so you can use the same code to access any supported (or unsupported, if you want to write your own connector) database.

    For D6, D7, check out:

    The keywords you can use on Google to get quick results are actually "drupal database abstraction layer" -- if you use that phrase you'll get a good number of results.

    I'm  not sure  what  version you are  running, or what exactly you need it to do, but those pages should have some information  that  would be  very useful to anybody who is familiar with using  MySQL with PHP.

    Drupal's database layer is really simple to use, and it takes a lot of the security concerns out when used properly.

    Good  luck!


    Author Comment

    Thank you for your reply.
    Yes, it's simple to use. I googled and tried to insert the form variables into table. And, I'm using Drupal 7.

    Now, I got this error :

    "Recoverable fatal error: Argument 2 passed to db_query() must be of the type array, string given, called in C:\wamp\www\First_Omega\sites\all\modules\registration\registration.module on line 100 and defined in db_query() (line 2310 of C:\wamp\www\First_Omega\includes\database\"
    LVL 12

    Accepted Solution

    Without seeing the code itself I can say that if you are passing arguments to db_query() they must be in array format. Are you using db_insert()?

    After I posted my last post I started looking around for better examples. I found  this one:

    Which is a great explanation of how to  use db_insert(). For SELECT statements check this out:

    BTW, if you're not passing arguments to the query (not likely) you can omit the second parameter[argument] or replace it with "array()"

    Check out that db_insert page. It should be a little  enlightening. Using the abstraction layer is a different  way  of thinking: the underlying code does most of the  work  for you. I  find  myself on a continual basis trying to force my SQL knowledge into a project only to realize that  there is a  simple function that takes  care  of everything for  me. :D


    Author Comment

    Thank you so much for the link. ""
    I was using Drupal 6 for Drupal 7. That's why.
    Now, I could save it in the table.

    Thank you again for your valuable time :-)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now