By Andrei Badea on Jun 10, 2008
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.