0% found this document useful (0 votes)
4 views

mysql

MySQL is a widely used open-source relational database management system based on SQL, originally developed by MySQL AB and now owned by Oracle. The document provides various SQL commands for database management, including creating, altering, inserting, updating, and deleting data. It also covers PHP integration with MySQL, detailing functions for opening and closing database connections and executing SQL queries.

Uploaded by

neelesh1222
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

mysql

MySQL is a widely used open-source relational database management system based on SQL, originally developed by MySQL AB and now owned by Oracle. The document provides various SQL commands for database management, including creating, altering, inserting, updating, and deleting data. It also covers PHP integration with MySQL, detailing functions for opening and closing database connections and executing SQL queries.

Uploaded by

neelesh1222
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

My SQL

My SQL

• MySQL is the most popular Open Source (RDBMS) Relational


Database Management System based on Structure Query
Language (SQL).
• MySQL is used for developing various web-based software
applications.
My SQL

MySQL, (Developed by - Monty) which was originally conceived by


the Swedish company MySQL AB (1996), was acquired by Sun
Microsystems in 2008 and then by Oracle when it bought Sun in
2010. Developers can still use MySQL under the GNU General
Public License (GPL), but enterprises must obtain a commercial
license from Oracle.
My SQL
Create New Database

create database <database name>;

To show active database


select database();

To show version
select version();

To show user
select user();
My SQL
Switch Database

Use <database name>;

To view tables
show tables;

To view databases

show databases;

To create tables
Create table <table name>(id int primary key auto_increment, ename
varchar(20), salary int);
To check table structure
Desc <tablename>;
Describe <tablename>;
My SQL Alter Table
To add field
alter table <table name> add doj date;

To modify field
alter table <table name> modify <field name> <values to modify>;
alter table emp modify ename varchar(40);

To delete field
Alter table <table name> drop <field name>;

To delete table
drop table <table name>;
To delete database
drop database <database name>;
My SQL INSERT into Table

Three ways to insert data into table:

1. Insert into <table name> values (………);


2. Insert into <table name> (fields-name) values(………);
3. Insert into <table name> (fields-name) values(………), (………), (………);
My SQL Viewing Data into Table
To show fields from a table:

Select <fields-name> from <table-name>; //All rows with given fields


Select * from <table-name>; //All rows with all fields

Viewing Conditional Data (Where)

select * from <table name> where <condition>;


example: select * from emp where sal>10000 and sal<1000;

select <field-name> form <table-name> where condition;


example: select Name from studentinfo where fine<1000;
My SQL

select max(fieldname) from <tablename>; //it will shows only integer(numeric) value

select max(sal) from emp;


select min(sal) from emp;

select count(fieldname) from <tablename> //return total number of rows


select count(*) from <tablename>;
My SQL
Update Data in a table

Update <table-name> set <values>;


Update <table-name> set <values> where <condition>;
Update emp set salary=9000, name=”Mohan” where id=2;
My SQL
Delete Data in a table

Delete <table-name>; or delete from <tablename> where 1;


Delete from <table-name> where <condition>;

Truncate Data in a table

Truncate <table-name>;
PHP with MySql
Php will work with virtually all database
software, including Oracle and Sybase but most
commonly used is freely available MYSQL
database.
Opening database connection
PHP provides mysql_connect function to open a database connection
This function takes five parameters and returns a MYSQL link identifier on success, or FALSE on failure.
Mysql_connect(server,user,passwd,new_link,client_flag);

server: Optional – The host name running database server. If not


specified then default value is localhost:3306
user: Optional – The username accessing the database. If not specified
then default is the name of the user that owns the
server process.
password:Optional – the password of the user accessing the database.
If not specified then default is an empty password.
new_link:Optional – If a second call is made to mysql_connect() with the same
arguments, no new connection will be established;
instead, the identifier of the already opened connection will be returned.
client_flags:Optional – a combination of the following constants:
1. MYSQL_CLIENT_SSL - Use SSL encryption(Secure Socket Layer)
2. MYSQL_CLIENT_COMPRESS - Use compression protocol
3. MYSQL_CLIENT_IGNORE_SPACE - allow space after function names
4. MYSQL_CLIENT_INTERACTIVE - allow interactive timeout seconds of
inactivity before closing the connection
Close Database Connection

Its simplest function mysql_close PHP provides to close a database connection.

mysql_close (resource $link_identifier);

Database Selection

mysql_select_db():- PHP Provides function mysql_select_db to select a database. It returns


TRUE on success or FALSE on failure.

mysql_select_db (db_name,connection);

mysql_query():- it is use to execute any type of SQL query.

mysql_query(sql,connection); <if connection established earlier then no need to pass connection>

You might also like