An Oracle blog about NetBeans for PHP

Database Code Snippets in the NetBeans PHP editor

Guest Author

One of my favorite features in NetBeans is the ability to quickly generate Java code. By invoking the Insert Code [Alt+Insert] action you can generate a large variety of pieces of  Java code: constructors, getters, setters, properties, and so on.

Until yesterday, this feature was only available in the Java editor. But now you can invoke the Insert Code action in the PHP editor too. Two code snippets are available: to generate code which connects to a MySQL database, and to display a database table.

The Connection to Database snippet generates code to connect to the database using the MySQLi extension. After invoking it, you can use the generated connection variable to execute queries, or you can invoke the second snippet, Database Table. This snippet generates PHP code which executes a SELECT statement for a table you specify and displays its results.

These snippets are available in the daily builds and will of course also be in NetBeans 6.5 M1.

Join the discussion

Comments ( 3 )
  • Azrael Valedhel Tuesday, July 29, 2008

    Is there a way for the user to write custom snippets?

  • Petr Tuesday, July 29, 2008

    Not exactly snippets, but you can write code templates (Options -> Editor -> Code Templates). We want to support code snippets in the next version.



  • guest Saturday, August 8, 2009


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.