9lessons Programming Blog - Tutorials about Angular, ReactJS, PHP, MySQL and Web Development
Showing posts with label Mysql. Show all posts
Showing posts with label Mysql. Show all posts
Wednesday, September 09, 2009

Pagination with jQuery, MySQL and PHP.

I received lot of requests from my readers that asked to me how to implement Pagination with jQuery, PHP and MySQL. so I had developed a simple tutorial. It's looks big but very simple script. Take a look at this live demo New updated post Pagination with Jquery, PHP , Ajax and MySQL.

Pagination with jQuery, MySQL and PHP.
Friday, May 22, 2009

Update a Record with Animation effect using JSP and jQuery.

I received a lot of requests about integration of JQuery and Ajax with Java (JSP). After long time again I'm working on JSP. I prepared a tutorial to update a record with animation effect using jQuery and JSP. Its very simple example contains some lines of Java and HTML code.

Monday, February 23, 2009

Backup your Web Projects Database using MySQL Administrator.

Some days back I had posted an article about MySQL WorkBench Usage. So in this post I want to explain how to take backup your database using MySQL Administrator. It's a part of MySQL GUI Tools.

It's very easy to use and using this we can take backup and restore web projects database.



Thursday, January 08, 2009

Visual Database Design with MySQL Workbench

Few days back I received one request about Mysql WorkBench Usage. So in this post I want to explain with screen shots to create a visual database design, follow these steps.

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..

Tuesday, November 18, 2008

Delicious Database Design: create tables and relationships with SQL

In the previous lesson we have seen how to design the relationship-entities model for a database to be used in a del.icio.us-like web site project. Our R-E model is:



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:


CREATE TABLE USER (
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:

FOREIGN KEY (attribute_name_1) REFERENCES tableOfReference(attribute_name_2)


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:

ON UPDATE CASCADE ON DELETE CASCADE


Our database is now ready and we can implement it using JSP, PHP and MySQL
Tuesday, November 18, 2008

Delicious Database Design: relationships

This lesson explains how to project a typical relationships-entities model for a database to be used in our web projects. My approach is:

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
-----------
user_id_pk (Primary Key)
user_name
email
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:


USER > SITE (M:M) - Many to Many (an user can add many sites).
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
-----------
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
Saturday, September 20, 2008

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));


Tuesday, September 16, 2008

Connecting JSP To Mysql Database Lesson

My brother Ravi Tamada request one mail about his college presentation. He is planning to do web dynamic project. So i am giving small explanation about JSP (Java Server Pages) to Mysql Connection structure, Tomcat directory structure and simple database examples.

Login.html


Code :
<body>
<form action="login.jsp" method="post">

User name :<input type="text" name="usr" />
password :<input type="password" name="pwd" />
<input type="submit" />

</form>
</body>

Reg.html



code:
<form action="reg.jsp" method="post">

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
Tuesday, August 26, 2008

Secure PHP Login Page Example

PHP - Hypertext Preprocessor before it was a Personal Home Page now a days very popular open source language in web world.


mailxengine Youtueb channel
Make in India
X