Comment System with jQuery, Ajax and PHP (Version 2.0).
Pagination with jQuery, MySQL and PHP.
Update a Record with Animation effect using JSP and jQuery.
Backup your Web Projects Database using MySQL Administrator.
It's very easy to use and using this we can take backup and restore web projects database.
Visual Database Design with MySQL Workbench
I prepared this tutorial to improve your Database design Skills in Visual style.
Download Mysql Workbench
For example if we want to project like Twitter web site updating user profile, our database will have these entities:
1 - Users( User_name, password, email, some registration data....)
2 - Updates( Updates/Messages added by the Users)
Step 1 -> Add EER Diagram
Step 2 -> Place a New Table
Ok now... edit the table just right click.
You have to add Column and fix the Data types.
Set the table Primary Key in Column details
Same way you have to create Update table also.
Step 3->Link the both table with Relationship tools
Link the Updates table to Users table automatically generate Foreign key column.
Finally export project SQL script.
We can export ERR Diagram image *.png formate also.
If you feel free post a Comment..
Delicious Database Design: create tables and relationships with SQL
Now we implement the database using SQL and phpMyAdmin. We crate a new database on phpMyAdmin and select the "SQL" tab. Copy and paste this SQL code into the form and click on execute button:
user_id_pk INT NOT NULL AUTO_INCREMENT,
user_name VARCHAR(40),
email VARCHAR(40),
password VARCHAR(20),
user_date DATE,
PRIMARY KEY (user_id_pk)
) TYPE=INNODB;
CREATE TABLE SITE (
site_id_pk INT NOT NULL AUTO_INCREMENT,
url VARCHAR(250),
description LONGTEXT,
share_data DATA,
PRIMARY KEY
) TYPE=INNODB;
CREATE TABLE SHARE (
share_id_pk INT NOT NULL AUTO_INCREMENT,
user_id INT NOT NULL,
site_id INT NOT NULL,
submitted_by INT NOT NULL DEFAULT 0,
PRIMARY KEY (share_id_pk),
FOREIGN KEY (user_id) REFERENCES USER(user_id_pk) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (site_id) REFERENCES SITE(site_id_pk) ON UPDATE CASCADE ON DELETE CASCADE
) TYPE=INNODB;
Create Relationships
To create relationships between database's table (for example between SHARE table and the other tables) you have to use the SQL code below:
where attribute_name_1 is the foreign key (generally, a field of type INTEGER)a and attribute_name_2 the primary key of the table of destination.
To force the referencial integrity between the data of database, you have to add this code:
Our database is now ready and we can implement it using JSP, PHP and MySQL
Delicious Database Design: relationships
1. Define database entities (tables)
2. Identify attributes for tables
3. Define relationships and cardinality between the instances (records) of tables.
Step 1: define database entities
The first step when you project a database is to identify all entities (tables). For example if we want to project a simplified del.icio.us-like web site, our database will have these entities:
1. - USER (to store data about users, email, password, nickname,...)
2. - SITE (to store data about the sites added by the users)
These are only the main entities required from our project but, take a mind, that we will add other tables to store data about relationships between istances (records) of these tables in case of cardinality (M:M), many to many (see Step 3).
Step 2: define attributes
The next step is to define attributes for the tables USER and SITE. In this semplified example we will have something like this:
-----------
user_id_pk (Primary Key)
user_name
password
user_data (user signup date)
SITE
-----------
site_id_pk (Primary Key)
url
description
share_user (total number of users that share a site)
Step 3: define database relationships
Our simple application del.icio.us-like works in this way: an user add a site that can be shared by other users. The relationship's cardinality between USER table and SITE table is:
SITE > USER (M:M) - Many to Many (a site can be shared by many users).
In this case ( cardinality M:M) we have to add a new table (SHARE) that contains all possible combination between all instances of USER table and SITE table . In this new table, SHARE, to identify an user that share a site added by another user or by itself, we will add two Foreign Key:
-----------
share_id_pk (Primary Key)
user_id (Foreign Key > USER)
site_id (Foreign Key >SITE)
submitted_by (boolean: flag only if the current user has submitted the site)
Implement your database using SQL
Now, our database is ready to be implement with a DBMS (for example using MySQL). The next lesson will explains how to implement this database using SQL language.
Next Lessons:Create Tables and Relationships with SQL
What is FOREIGN KEY? Easy Lesson
What's in a Database?
a database is a container that holds tables and other SQL structures related to those tables.
An easier way to diagram accout table.
Every one having different hobbies. Remove the hobbiles column and put it in its own table
Add name colum that will let us identify which hobbies belong to which person in the account table.Linking two tables in a diagram
Connecting Two tables
The problem we're trying to use name field to somehow let use connect the two tables. But what if two people in the accout table have the same name ?
Foreing Key Facts :
A foreign key can have a different name that the primary key it comes form.
The primary key used by a foreign key is also knownas a parent key. the table where the primary key is from is knows as a parent table.
The foreing key can be used to make sure that the rows in on table have corresponding rows in another table.
Foreign key values can be null, even thugh primary key values can't.
Foreign key don't have to be unique - in facts, they ofter aren't
CREATE TABLE accout(
user_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(20),
email VARCHAR(30),
birthday DATE,
gender VARCHAR(10),
city VARCHAR(30));
CREATE TABLE hobbies(
hob_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,hobby VARCHAR(100) NOT NULL,
user_id INT NOT NULL,
CONSTRAINT account_user_id_fK
FOREIGN KEY(user_id)
REFERENCES accout(user_id));
Connecting JSP To Mysql Database Lesson
Login.html
Code :
<form action="login.jsp" method="post">
User name :<input type="text" name="usr" />
password :<input type="password" name="pwd" />
<input type="submit" />
Reg.html
code:
Email :<input type="text" name="email" />
First name :<input type="text" name="fname" />
Last name :<input type="text" name="lname" />
User name :<input type="text" name="userid" />
password :<input type="password" name="pwd" />
<input type="submit" />
</form>
Mysql Create Database Test:
Mysql no doubt about it best open source database http://mysql.com/
Create Table Users:
login.jsp
<%@ page import ="java.sql.*" %>
<%@ page import ="javax.sql.*" %>
<%
String userid=request.getParameter("user");
session.putValue("userid",userid);
String pwd=request.getParameter("pwd");
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/
test","root","root");
Statement st= con.createStatement();
ResultSet rs=st.executeQuery("select * from users where user_id='"+userid+"'");
if(rs.next())
{
if(rs.getString(2).equals(pwd))
{
out.println("welcome"+userid);
}
else
{
out.println("Invalid password try again");
}
}
else
%>
reg.jsp
<%@ page import ="java.sql.*" %>
<%@ page import ="javax.sql.*" %>
<%
String user=request.getParameter("userid");
session.putValue("userid",user);
String pwd=request.getParameter("pwd");
String fname=request.getParameter("fname");
String lname=request.getParameter("lname");
String email=request.getParameter("email");
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test",
"root","root");
Statement st= con.createStatement();
ResultSet rs;
int i=st.executeUpdate("insert into users values ('"+user+"','"+pwd+"','"+fname+"',
'"+lname+"','"+email+"')");
%>
welcome.jsp
<%@ page import ="java.sql.*" %>
<%@ page import ="javax.sql.*" %>
<%
String user=session.getValue("userid").toString();
%>
Registration is Successfull. Welcome to <%=user %>
Tomcat Directory Structure
Tomcat open source web server you can download from this link http://tomcat.apache.org/
Run Your Project