Creating A Database Driven Application With PHP
Creating A Database Driven Application With PHP
Creating A Database Driven Application With PHP
1 of 9
https://netbeans.org/kb/docs/php/wish-list-lesson1.html
NetBeans IDE
NetBeans Platform
Enterprise
Plugins
Docs & Support
Community
HOME / Docs & Support
Tutorial contents:
Java Programming
Language
Oracle Development
Tools Support Offering
for NetBeans IDE
Documentation
General Java
Development
External Tools and
Services
Java GUI Applications
Java EE & Java Web
Development
Web Services
Applications
NetBeans Platform
(RCP) and Module
Development
PHP and HTML5
Applications
C/C++ Applications
Mobile Applications
2014-09-16 3:55 PM
2 of 9
https://netbeans.org/kb/docs/php/wish-list-lesson1.html
This lesson describes the last preliminary step in developing the Wish List application, that of creating
a sample database with test data. To complete the steps in this tutorial, you will need a database in
which to store data of wishers. With the NetBeans IDE you can perform all these activities through the
IDE interface.
Before starting, see the tutorial requirements described in Creating a CRUD Application with PHP Main page.
The current document is a part of the Creating a CRUD Application in the NetBeans IDE for PHP
tutorial.
Sample Applications
Demos and Screencasts
More
FAQs
Contribute
Documentation!
Docs for Earlier Releases
1. Start the IDE, switch to the Services window (Ctrl-5), and expand the Databases node.
2. To connect to the MySQL database server, navigate to the MySQL Server node and from the
context menu choose Connect.
3. The NetBeans IDE connects to the MySQL server, checks for the databases available through the
server, detects the system mysql database, and adds the corresponding new node mysql to the
Databases tree.
2014-09-16 3:55 PM
3 of 9
https://netbeans.org/kb/docs/php/wish-list-lesson1.html
4. To execute an SQL command, you need to be connected to a database. Because only the MySQL
system is available, you need to connect to it. To connect to the system database, navigate to the
mysql node and from the context menu choose Connect. If a connection does not already exist,
the New Database Connection dialog box appears. The User Name field is by default filled in
with root. In the Password field, enter the root user's password.
Note: If you have connected to the mysql database before, this dialog does not appear. Instead,
the new connection node simply appears in the tree.
The New Database Connection dialog box shows the message "Connection established." Click
OK. A new node named jdbc:mysql://localhost:3306/mysql is added to the Databases tree.
5. Navigate to the jdbc:mysql://localhost:3306/mysql node and from the context menu choose
Execute Command.
An SQL Command window opens. In the SQL Command window, use syntax similar to the
following statement:
2014-09-16 3:55 PM
4 of 9
https://netbeans.org/kb/docs/php/wish-list-lesson1.html
From the context menu, choose Run Statement. If the command is executed successfully, the
Status bar shows the message: "SQL Statement(s) executed successfully". If another message is
displayed, check the syntax and follow the message hints.
The "Grant full access to user" function does not always work. If it does not work, connect
to the database as the root user and send the SQL query GRANT ALL ON wishlist.* TO
phpuser@localhost.
A connection to the database appears in the tree. However the connection is for the root user.
You need a connection for the phpuser user.
2. In the New Connection Wizard's Locate Driver panel, select the MySQL (Connector/J Driver).
Click Next. The Customize Connection panel opens.
2014-09-16 3:55 PM
5 of 9
https://netbeans.org/kb/docs/php/wish-list-lesson1.html
The corresponding new connection node is displayed in the Databases tree. Now you can delete the
root user's connection to the wishlist database. Click the jdbc:mysql://localhost:3306/wishlist
[root on Default schema] connection and choose Delete.
2014-09-16 3:55 PM
6 of 9
https://netbeans.org/kb/docs/php/wish-list-lesson1.html
Note: You can get a unique auto generated number from MySQL by specifying the
AUTO_INCREMENT property for a field. MySQL will generate a unique number by
incrementing the last number of the table and will automatically add to the auto
incremented field. In our example the ID field is auto incremented.
b. Click the right mouse button on the query and then choose Run Statement from the context
menu.
2014-09-16 3:55 PM
7 of 9
https://netbeans.org/kb/docs/php/wish-list-lesson1.html
Note: The default storage engine for MySQL is MyISAM, which does not support foreign
keys. If you want to use foreign keys, consider using InnoDB as the storage engine.
4. To create the wishes table:
a. Type the following SQL query:
CREATE TABLE wishes(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
wisher_id INT NOT NULL,
description CHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
due_date DATE,
FOREIGN KEY (wisher_id) REFERENCES wishers(id)
)
b. Click the right mouse button on the query and then choose Run Statement from the context
menu.
5. To verify that the new tables are added to the database, switch to the Services window and then
navigate to the jdbc:mysql://localhost:3306/wishlist connection node.
6. Click the right mouse button and choose Refresh. The nodes wishers and wishes appear in the
tree.
Note: You can download a set of SQL commands for creating the MySQL wishlist database here.
Click the right mouse button on the query and from the context menu choose Run Statement.
Note: The statement does not contain a value for the id field. The values are entered
automatically because the field type is specified as AUTO_INCREMENT.
Enter another test wisher:
INSERT INTO wishers (name, password)
VALUES ('Jerry', 'jerrymouse');
Select the queries, click the right mouse button on each query and from the context menu choose
Run Selection.
Note: You can also execute the queries one after another as described in item 2.
4. To view the test data, click the right mouse button on the relevant table and from the context
menu choose View Data.
2014-09-16 3:55 PM
8 of 9
https://netbeans.org/kb/docs/php/wish-list-lesson1.html
To get some general understanding of database principles and design patterns, check the following
tutorial: http://www.tekstenuitleg.net/en/articles/database_design_tutorial/1.
For more information on the syntax of MySQL CREATE TABLE statements, see http://dev.mysql.com
/doc/refman/5.0/en/create-table.html.
For more information on inserting values into table, see http://dev.mysql.com/doc/refman/5.0/en
/insert.html.
Note: You can download a set of SQL commands for creating the MySQL wishlist database here.
Next Step
Next Lesson >>
Back to the Tutorial main page
Send Us Your Feedback
To send comments and suggestions, get support, and keep informed on the latest developments on the
NetBeans IDE PHP development features, join the users@php.netbeans.org mailing list.
Back to the PHP Learning Trail
SiteMap
About Us
Contact
Legal & Licences
By use of this website, you agree to the NetBeans Policies and Terms of Use. 2013, Oracle Corporation and/or its affiliates.
2014-09-16 3:55 PM
9 of 9
https://netbeans.org/kb/docs/php/wish-list-lesson1.html
Sponsored by
2014-09-16 3:55 PM