• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1363
  • Last Modified:

How to save it in the mysql database in Drupal?

Hi,
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!
0
sharon212
Asked:
sharon212
  • 2
  • 2
1 Solution
 
junipllcCommented:
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:

http://api.drupalize.me/api/drupal/group/database/6
http://public-action.org/content/drupal-7-drupal-7-database-abstraction-layer

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!

Mike
0
 
sharon212Author Commented:
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\database.inc)."
0
 
junipllcCommented:
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:

http://drupal.org/node/310079

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

http://api.drupal.org/api/drupal/includes%21database%21database.inc/function/db_query/7#comment-7019

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

Mike
0
 
sharon212Author Commented:
Thank you so much for the link. "http://drupal.org/node/310079"
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 :-)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now