Tuesday, April 27, 2010

Last insert id in drupal

db_last_insert_id($table, $field);

where

$table The name of the table you inserted into.

$field The name of the autoincrement field.

Wednesday, August 5, 2009

Fedora Basics

Summary

This page goes over some of the basics of using Linux, and a few basics of using Fedora in particular. It's helpful to know these things before reading the Unofficial FAQ.

Table of Contents

Some Linux Basics

  1. What is a terminal? How to I "open a terminal?" (Updated 11 Feb 2009)
  2. What is root? How do I "become root?"
  3. I installed a program, how do I start it?
  4. What is a runlevel?
  5. How do I start in text-only mode (no graphical environment)?
  6. How do I run something when the computer starts?
  7. How do I reset my root password?

Some Fedora Basics

  1. What is a "service?" How do I manage services in Fedora?
  2. What is rescue mode and how do I boot into it?

The FAQ

Some Linux Basics

  1. Q: What is a terminal? How to I "open a terminal?" (Updated 11 February 2009)
    A: A "terminal" is a way of typing commands to the computer. That may sound very strange, but it's actually really, really nice and easy once you get used to it. You can use Fedora as a totally graphical system, or you can use it totally with the terminal. I like to do both; I use whichever one is easier for the task I'm doing.

    You can either open a terminal inside of your graphical environment, or you can switch your whole screen to a terminal.

    To open a terminal in a graphical environment:

    1. Open up your menu. This is either the "red hat" or "F in a bubble" icon in the tray (at the top or bottom of the screen). (It might also be a little "foot," or possibly a little penguin.)
    2. Under System Tools, click on Terminal. (In some versions of Fedora, it's under Accessories instead of System Tools.)

    To switch your entire screen to a terminal, press Ctrl-Alt-F2. You can then switch between six different terminals, by using Alt-F2 through Alt-F6. Pressing Alt-F1 will bring you back to your graphical environment (or in earlier versions of Fedora, Alt-F7).

  2. Q: What is root? How do I "become root?"
    A: "root" is the name of the user who can control everything on the entire computer. We call this the "super user."

    To become root, first you must open a terminal. Then, you type:

    su -

    Note that the "-" is very important -- it sets things so that you have easy access to all the commands on the computer.

    Then, you have to type in your root password. You set this when you installed Fedora.

    If you're using the "open a terminal" method where you make the whole screen into a terminal, then you just need to put "root" as your "Login:" name, and then enter the correct password.

  3. Q: I installed a program, how do I start it? (Updated 1 June 2007)
    A: First, look around in the "Red Hat" menu in the toolbar. Most new programs installed will add themselves to the menu automatically.

    If you can't find it in the menu, you can use the Terminal, in the menu under "System Tools." Most programs are executed by their name. For example, to launch the web browser, Firefox, you can simply open a terminal and type:

    firefox

    You can also type only part of the command and then press Tab. So you could type:

    fir[Tab]

    And that would type out firefox for you. If there's more than one command that starts with fir, you'll hear a beep. Hit Tab again and you'll see a list of all the programs on your computer that start with those letters.

    If you really can't figure out the name of the command, but you know the name of the package the program came in, try this to list the programs in a package:

    rpm -ql packagename | grep bin

  4. Q: What is a runlevel?
    A: A runlevel is a number which indicates what "mode" you want to computer to boot into. For example, runlevel 5 is graphical mode, where runlevel 3 is text-only mode. Runlevel 1 is "single-user" mode, used for troubleshooting problems.

    There are three ways to change your runlevel:

    • While the Computer is Running:
      1. Open a Terminal.
      2. Become root:

        su -

      3. Type:

        init number

        where number is the runlevel that you want to change to.

      You will then be switched into the new runlevel.

    • While You Are Booting the Computer:
      1. When you first start your computer, the GRUB screen (where you choose your Operating System) appears. Select the Fedora that you want to boot into, but press the a key instead of pressing Enter.
      2. You will see a line somewhat like the following:

        kernel /vmlinuz-2.6.9-1.667 ro root=LABEL=/ acpi=on rhgb quiet

        Add the number of your runlevel to the end of that line, and then press Enter. For example, to boot into text-only mode, the line would look like:

        kernel /vmlinuz-2.6.9-1.667 ro root=LABEL=/ acpi=on rhgb quiet 3

      You will then boot into the new runlevel this time only.

    • Permanently Set a Default Runlevel:
      1. Open a Terminal.
      2. Become root:

        su -

      3. Open the file /etc/inittab in your favorite text editor:

        gedit /etc/inittab

      4. Find the line:

        id:number:initdefault:

        where number is your current default runlevel (probably 5).

      5. Change the number in the middle of the line to the new runlevel that you want your computer to start in by default. For example, if you want to start in text-only mode by default, change it to:

        id:3:initdefault:

      You will then boot into that runlevel every time you start the computer.

    (Thanks to Ilja Kogan for the inspiration to write this question, and some original text.)

  5. Q: How do I start in text-only mode (no graphical environment)?
    A: Text-only mode is runlevel 3. If you want to start in text-only mode, see the instructions in the runlevel question above, and change your runlevel to runlevel 3.
  6. Q: How do I run something when the computer starts?
    A: You have two choices, either you can run something before anybody logs in, or you can run something immediately after you log in.

    To run a command right after you boot, before anybody logs in, add the command to the file /etc/rc.local:

    1. Open a Terminal.
    2. Become root:

      su -

    3. Open the file in your favorite text editor:

      gedit /etc/rc.local

    4. Add the command that you want to run to the end of the file, on its own line.

    If you want to start a program right after you log in:

    1. Log in.
    2. Wait for everything to start, then start only the program that you want to start automatically from now on.
    3. Log out, and put a check in the "Save Settings" box.

    From now on, when you log in, that program will be automatically started. If you want to stop that program from starting automatically, just:

    1. Log in.
    2. Quit the program that you want to no longer automatically start.
    3. Log out, and put a check in the "Save Settings" box.

    The "Save Settings" check box just causes your system to always look, by default, exactly like it does right before you log out.

    (Thanks to Ilja Kogan for the question suggestion and original text.)

  7. Q: How do I reset my root password?
    A: If you've forgotten your root password, and you want to change it, don't worry! It's possible. You need to boot into what's called "single-user mode." You must be in front of the computer to do this -- you can not do it remotely:
    1. Using the instructions in the runlevel question (under the "While You Are Booting the Computer" section), boot into runlevel 1.
    2. Set the new root password with by typing:

      passwd

      And then enter your new root password when asked.

    3. Reboot your machine, and you will now be able to log in as root with the new password that you entered.

    (Thanks to Mark Senn for suggesting that I write this question and giving me some original text.)

Some Fedora Basics

  1. Q: What is a "service?" How do I manage services in Fedora?
    A: A "service" is a program that starts automatically when you start your computer, and runs in the background. For example, the "network" service sets up your connection to the Internet and keeps it running correctly.

    There are two ways to manage services in Fedora, one using the graphical tools, and one using only the command line. If you're not in a graphical environment, use the command line method.

    Using the graphical tool which can be found in the menu, under System Settings - > Server Settings - > Services:

    • Check if a service is running: Select your service in the list, the status is shown in the status section.
    • Starting a service: Select your service in the list and press Start.
    • Stopping a service: Select your service in the list and press Stop.
    • Have a service start automatically at boot: Select your service in the list, check the checkbox next to it.
    • Stop a service from starting automatically at boot: Select your service in the list, uncheck the checkbox next to it.

    Using the command line (replace servicename with the name of the service you want):

    You must be root for this to work.

    • Check if a service is running:

      service servicename status

    • Starting a service:

      service servicename start

    • Stopping a service:

      service servicename stop

    • Have a service start automatically at boot:
      1. Open the ntsysv program:

        ntsysv

      2. Find your service in the list and press space to enable it. Services marked with a * will start automatically at boot.
    • Stop a service from starting automatically at boot:
      1. Open the ntsysv program:

        ntsysv

      2. Find your service in the list and press space to disable it. Services marked with a * will start automatically at boot.

    (Thanks to Sindre for the original text of this question!)

  2. Q: What is rescue mode and how do I boot into it?
    A: Rescue mode provides the ability to boot a small Fedora environment entirely from a CD-ROM or USB drive instead of the system's hard drive. As the name implies, rescue mode is provided to rescue you from something. In rescue-mode you can mount and edit your files, such as configuration files and by doing so solve your problems.

    To boot into rescue mode, you must be able to boot the system using one of the following methods:

    1. By booting the system from an installation boot CD-ROM, or a boot image on a USB disk.
    2. By booting the system from the Fedora CD-ROM #1.

    Once you have booted using one of the described methods, enter the following command at the installation boot prompt:

    linux rescue

Saturday, July 25, 2009

Why choose WordPress as the blogging platform!

When you decide that you want to start a blog, the question which haunts most of the people is that which blogging platform would be the best and the biggest question is this one :

1. Should I go for hosted blogging service like Blogger, Vox, WordPress.com etc. or
2. Should I go for the self-hosted solution like WordPress, Drupal, Expression engine, Movable Type etc. ?


Well, I’ve broken this single question in two points as more and more questions arise when we choose any of these two points. Let’s choose the first one and see what are the points which effect us and what are the PROs of choosing a hosted solution and what are the negatives.

Pros of choosing a hosted solution :

1. Zero tech knowledge is required.
2. It gets as simple as maintaining an email account.
3. No need to worry about the hosting services, charges and downtimes.
4. Most of the services are free or offer slightly pro services for few dollars.

Cons of choosing a hosted solution :

1. None of them offers full control over the blog.
2. Less customization options.
3. Few don’t allow you to earn money out of it and some display ads on your blog.

Here are some PROs of self hosted solution mentioned by Franky Branck in one excellent post aboutvarious hosted solutions :

  • Freedom to switch services or hosting company;
  • SEO advantages;
  • Easy to correctly forward when switching domains and keep traffic;
  • Upload space only limited by hosting plan;
  • Complete backup freedom;
  • Freedom to criticize the platform you use, without having the fear to be shutdown;

Now that we’ve discussed the Pros and Cons of hosted solution of blogging we know that the Cons of hosted solution are the Pros of self-hosted solution and Pros of hosted solution are Cons of any self-solution.

However, as an experienced player in blogging industry and being a person who makes full time living from blogging, I’ll vouch for self-hosted solution and I’ll tell you that why one should go for a self hosted solution and on top of it, why one should choose WordPress as the solution as a blogging platform :

Let’s tackle the Cons of self hosted solution :

1. Tech knowledge related to hosting, domain names is required : Believe me or not, all these terms sounds scary however they are pretty simple in reality. When I started, I didn’t know even a single thing about it. I read a couple of blog posts, a couple of guide and followed what was mentioned in them and I was good to go. I’ll now explain it briefly over here :

a) Book a domain name – You can go ahead and book a domain name from any reputed domain provider. GoDaddy is one of the most popular and reputed domain registrar. So, go ahead and choose the domain name from there.

b) Get web hosting : There are various web hosts which offer no frills web hosting at pretty reasonable prices. WordPress community suggests few web hosts and you may choose any of those. BlueHost, DreamHost are some of the most popular web hosting services. I’m using a little expensive service but one of the most reliable web host around i.e. MediaTemple.

You may choose any of these services and the reason I say that you should choose any of these services is because they are recommended by WordPress community itself, suggested by thousands of ProBloggers and to top it all, they all have one click WordPress installation available. You don’t need to follow the installation procedure of WordPress and installing WordPress gets as simple as installing any software on your computer.

c) Change the nameserver : Once you get the domain name and hosting, you need to change the nameserver in the domain administration panel. Your hosting provider will provide you the nameserver address and you need to specify in the domain administration panel.

d) Install WordPress : The reason why I suggested those webhosts was that they provide simple way of installing the WordPress and you won’t find any problems in installing WordPress on your web host and your blog will get live with your choice of domain name! If you decide to go for any other hosting service, then just email them once or even better, call them and find out if they have quick installation script of WordPress. If they say that they’ve got CPanel with Fantastico then also you are good to go.

2. It gets simple as maintaining an email account : Once WordPress will be installed on the web space, it’ll also be as simple as maintaining an email account. If you think that WordPress.com’s blog admin interface will simpler then I would like to enlighten you with the fact that the self-hosted WordPress blog’s admin interface is almost same.

3. No need to worry about downtime, hosting charges : The reason why i suggested you to go for those reliable hosting services was that they guarantee 99% above up time. As they have shared hosting, you don’t need to worry about maintaining the server at all.

4. Most of the services are free : The benefit of the hosted solution is that they offer free solution and unfortunately hosting doesn’t come for free. However one of the PRO of self hosted solution is that it’s powerful and secondly you have the chance of earning money from various ways which are taught by many bloggers : Make Money Online and I’m sure that with regular posting, you can certainly get the money back and cover the hosting charges.

I’m still not convinced :

Well, it really depends on what exactly you want to believe. With my experience in blogging, I can always say that it makes more and more sense to go for the hosted solution and nothing can beat the experience. When I started with the things, I didn’t know anything from hosting the site and DNS servers and all those words which give you headache, however a little research and by spending around 5-10 hrs. I had pretty good idea about the things.

Why choose WordPress, when we have other blogging platforms ?

I live and love WordPress, when it comes to blogging and here are some of the reason because of which I suggest everyone to use WordPress and I hope that they’ll be good enough for you to choose my choice :

1. I make living out of it by creating the themes.

2. It’s the simplest blogging software. Very easy to install, configure and easy to work on.

3. It’s got the best support team in the form of thousands of volunteers, who dedicate their time and energy in helping the users of WordPress. You can get support from the WordPress IRC channel & WordPress forum quite easily.

4. It’s got great help section too and mostly answers all the queries. I’ll even say that it’s one of best documentation you’ll ever see of any software on the internet.

5. There are many blogs which write dedicatedly about WordPress and even extend their hands to help you with any issues with WordPress.

6. It’s pretty extendable with the help of thousands and thousands of themes and plugins available for free.

7. You can use it to create static websites too.

8. It’s SEO friendly (well, the architecture of WordPress allows to create SEO friendly themes and most of them are pretty SEO freindly, thus I came up with such a statement).

9. Gets updated frequently, thus ensuring that any security hole gets fixed pretty fast and ensures that your website/blog isn’t part of the targets of the hackers.

Well, there are thousands of other points (big/small) on which I can brag about WordPress and still if you don’t want to believe me, then do a little search using “reasons I like WordPress” and you’ll understand that why I support WordPress so much

How to install WordPress

Let’s start with installation of WordPress :

There are two ways of installing WordPress; automatic & manual (hah! you thought there was something else too?) Well, I’ll cover both of them to ensure that you get to understand each and every bit of it. Needless to say that automatic way is far simpler than the manual way, however manual way isn’t difficult too -

Automatic installation of WordPress -

a) Installation through CPanel : Many web hosts come with a web space management tool called Cpanel, which also has a module called Fantastico. If a web host provides Fantastico then you are game as it allows you to install WordPress in a matter of 2 minutes.

b) Installation scripts of web hosts : Few web hosts provide automatic installation scripts like fantastico. MediaTemple (MT) is one popular web host and provides such a script. Note 1 : Our blog is hosted on MediaTemple.

Note 2: Generally the auto-installer scripts install the older version of WordPress. It happens because WordPress is actively developed software and they release updated version frequently and webhosts generally update their auto installers a bit late. So check that which version is installed by the auto-installer script and that which one is the current available version.

Note 3 : You can also take the services of Install4Free, a group which does the WordPress installation for you and that too without charging you a cent. We can also help you in doing so, feel free to contact us (fill out the contact us form).

Manual Installation of WordPress -

I’ll write down a step by step guide to ensure that you don’t miss any point at all and that it becomes fairly simple for you to understand the installation too.

  1. Download the latest release of WordPress from here.
  2. Extract the files using Winzip or any other compression program.
  3. Rename wp-config-sample.php to wp-config.php
  4. Create a new database and username for database management and give it the complete rights for that database.
  5. Edit the wp-config.php and make the necessary changes related to the database username, password and database name.
  6. Upload the files to your desired location on the webserver (using any FTP program, I prefer Filezilla). If you want the blog on root level then put it in the folder called public_html (its not necessary that you’ll have public_html folder, however normally that’s what you get. If you don’t know that which is the public folder of your web hosting account then you’ll need to ask your web host). If you want the blog address as http://yourdomain.com/blog/ then create a new folder in public_html folder called blogand upload all the files in it.
  7. Run the installation script by accessing the installation URL from your favorite web browser. If you uploaded the wordpress files on the root then point your browser to the following url : http://yourdomain.com/wp-admin/install.php
  8. Follow the 2 step wizard and you’ll be done.
  9. Don’t forget to delete or rename the install.php file after you’ve finished the installation. That’s advisable for security purposes.

Trust me all these steps won’t take more than 5 minutes of yours. If at all you get stuck at any point of time, don’t worry as we are always there to help you or drop your questions at wordpress forums.

Wednesday, July 22, 2009

Free ExpertsExchange Account

Dear Friends,

As a programmer, my number one tool for getting out of a tough bind is a quick google search.

Developers are chatty, and we have about a million different forums, blogs, wikis, example sites, source projects, etc. When I'm having a problem with my code, chances are that there have been many other programmers that have already found a solution, and some of them probably posted answers online somewhere.

But, in any given search, you are bound to get at least a few links to this place called "Experts Exchange".

It'll just have a reasonable title and an excerpt that suggests it as a good place to look.
So I click the link.

And then I see the Experts Exchange page.

But you see like this

Sign up now to view this solution
All comments and solutions are available to Premium Service Members only. Sign-up to view the solution to this question.
Already a member? Login to view this solution.


The idea of Experts Exchange itself isn't so bad. A subscription based community of IT professionals working together to create a database of answers to IT related issues.

Now I found out a solution for this,, there is a way to get an ExpertsExchange Account Free Without Creditcard ..

Experts-exchange.com is one of best forum on internet to get solution of your computer related problems and issue. Millions of technical experts from respective domain are ready to answer questions on expert-exchange.com forum.I myself have landed to experts-exchange.com while googling for any PHP related issue and I am sure many users would have landed to experts-change.com page looking for a possible solution to the problem.

In order to register an account on experts-exchange.com you need to pay minimum 5.95$which is for one month subscription.

Well here is trick to get Free Account on Experts-exchange.com without paying a single penny or creditcard..

Use this Registration link to create account on experts-exchange which will not ask for any payment or credit card details.

http://www.experts-exchange.com/registerFree2.jsp

Update: It seems the account created with this registration link is actually limited access account which lets you to view solution of all questions, answer questions and gain points. But cannot ask as many questions as a premium member asks.

I have created the account.. and it is working for me.
if you find any problem on registering, post a comment here.. I'll help you