0% found this document useful (0 votes)
23 views20 pages

Iwd Unit 5 Working With Database

This is a pdf of unit 5 subject of semester fourth

Uploaded by

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

Iwd Unit 5 Working With Database

This is a pdf of unit 5 subject of semester fourth

Uploaded by

Moviez king
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 20
e: Introduction to Web Development Unit -V Subject Code: 4340704 Unit — 5 Working With Database in PHP Introduction to MySQL Database with PHP ‘Overview of the database © Database: A database is simply an organized collection of related data, typically stored on disk, and accessible by possibly many concurrent users. ‘© Databases are generally separated into application areas. ‘© For example, one database may contain Human Resource (employee and payroll) data; another ‘may contain sales data; another may contain accounting data; and soon. ‘* Databases are managed by a DBMS. ‘* DBMS: Database Management System (DBMS) is a set of programs that manages any number of databases. Introduction to MySQL © MySQL is a database system used on the web ‘* MySQL is a database system that runs on a server ‘© MySQL is ideal for both small and large applications © MySQL is very fast, reliable, and easy to use, MySQL uses standard SQL. MySQL compiles on a number of platforms. MySQL is free to download and use, MySQL is developed, distributed, and supported by Oracle Corporation Data type of MySQL: ‘* MySQL Data Types are divided into three main categories as given below (1) Numeric DataType (2) String or Text DataType (3) Date Time Data Type © Numeric Datatype TINYINT 1 Itis used to store integer values. 2 SMALLINT 2) tis used to store integer values. 3 MEDIUMINT Bi Itis used to store integer values. Prepared By: Department of Computer Engineering Page 1 Subject Name: Introduction to Web Development Unit-V Subject Code: 4340704 eeu 4 INT 4 It is used to store integer values. 5 BIGINT 8 Lis used to store integer values. 6 FLOAT 4 It is used to store single precision floating point value. 7 DOUBLE 8 _Itis used to store double precision floating point value 8 DECIMAL tis used to store integer values. String Datatype tis used to store fixed length string. 2. VARCHAR 255 Itis used to store variable length string. 3. TINYBLOB 255 tis used to store short binary data. 4 TINYTEXT 255 tis used to store short text string, 5 BLOB 65535 _It is used to store large binary data. 6 TEXT 65535 _It is used to store large text string. 7 MEDIUMBLOB —_—_16777215 _It is used to store medium binary data. 8 MEDIUMTEXT — 16777215 _Itis used to store medium text string. 9 LONGBLOB 4294967295 It is used to store extremely large binary data, 10 LONGTEXT 4294967295 It is used to store extremely large text string © Date and Time Datatype Tris used to store date values in the YYYY ~ MM ~ DD Format. Prepared By: Department of Computer Engineering Page 2 Code: 4340704 e: Introduction to Web Development Unit -V It is used to store time values or time duration in the a ate a HH : MM: SS format. 3 YEAR 1 It is used to year values in the YYYY format. 4 DATETIME 8 ee Nig ait inthe YYYY 1S Eee Field Modifiers in PHP’ | NULL or NOT NULL : ‘© Itallows you to specify weather the field can accept null value or you must have to enter value for that field. © You can specify this modifier at the end field definition. © By default all the filed of the table having this modifier set to NULL. o Example create table Subject ( SubjectCode varchar (5) NOT NULL, SubjectName varchar (10) NOT NULL, SubDesc varchar (20) NULL ) « DEFAULT © Default modifier allows you to specify default value for the field so if you don’t enter any value for that field then default value is used. o Example create table Subject ( SubjectCode varchar (5) NOT NULL, SubjectName varchar (10) NOT NULL, SubDese varchar (20) DEFAULT ‘Computer’ ) * AUTO_INCREMENT © This modifier automatically increments the value of field by one, © There is no need to insert explicit value for this field. © It is widely used in primary key field where unique id is generated automatically by MySQL each time by incrementing previous by I. © However you can specify AUTO_INCREMENT modifier for only INT data type. © Example: create table Subject ( SubjectCode INT(5) AUTO_INCREMENT, SubjectName varchar (10) NOT NULL, SubDese varchar (20) NULL, ) ‘Types of MySQL tables & storage engines Prepared By: Department of Computer Engineering Page 3 Subject Nami e: Introduction to Web Development Unit -V Subject Code: 4340704 ‘+ When we create table using Create Table statement it is also possible to specify type of the table using TYPE attribute as shown below Create table TableName (ColumnNameDataType, ColumnNameDataType ) TYPE = TableType ‘* Following are the various Types of MySQL tables that you can specify at the time of creating new Database Table. MyISAM ISAM HEAP InnoDB BDB pre we «| MyISAM © While creating Table if you don’t specify the type of the Database Table then by default its type is set to MYISAM. © This table is portable, Portable means the table created using this type in one OS can also be used in other OS. It supports large table file more than 4GB. It is well suited for faster access then speed. Itallows you to reduce the space using compression. Itallows you to specify index on BLOB as well as TEXT type. coon « ISAM © This Table Type is similar to the MyISAM table type in the way it also supports fixed size as well as dynamic size table. © Butt is different from MYISAM table type in following way : = Itcan support table files up to 4GB but not grater then 4GB. = Tis not portable. Means table created using this type in one OS cannot use in other Os. * It does not allow faster accessing and compression. * Since maximum key length in this table type is 256 it does not allows you to specify index on BLOB and TEXT type. + HEAP © This table type is widely used for temporary tables because it supports incredible speed. © Itis in-memory table which uses hashed indices. © It does not allow BLOB and TEXT type as MYISAM and ISAM type. + BDB © BB isalso known as Berkeley DB. Prepared By: Department of Computer Engineering Page 4 e: Introduction to Web Development Unit -V Subject Code: 4340704 This table type is transaction safe and widely used for transaction. It supports very large applications with more than one users trying to insert and update the same data at the same time. It allows you the facility of transaction using commit and roliback statement, One important facility provided by this table type is that allows you the facility of recover data from crashes. It is not portable because the path of the table i the table. hardwired into the table file while creating + ImoDB ° ° This table type is also transaction safe It supports very large applications with more then one users trying to insert and update the same data at the same with locking mechanism. Locking mechanism prevents users from modifying records while another user is ‘modifying the same record at the same time. Italso allows you the facility of recovering data from crashes. This table type is portable. This table type is useful for virtual table, This table type can be created by joining more than one MyISAM table types into single table. However you can join more than one MyISAM table if and only if all the table having same structure. Prepared By: Department of Computer Engineering Page 5 ‘Subject Name: Introduction to Web Development Unit-V Subject Code: 4340704 Creating a database using phpmyadmin & Console ‘+ Creating a database using phpmyadmin 6 Run wampserver and Click on wampserver icon © Provide “root” username and click on Go button phpMyAdmin Welcome to phpMyAdmin Language English w Login Username: wad Passmore: ———— server Chote: ysau Prepared By: Department of Computer Engineering Page 6 ‘Subject Name: Introduction to Web Development Unit -V Subject Code: 4340704 a © On phpMyAdmin dashboard, click on Databases option ‘asnee end eeeaeaednaaeedineeenlanaaeena ay =n Se eer Ss ee Soros (oe — 2 eS eee ies Erne wlomoee oem s Co cd Prepared By: Department of Computer Engineering Page 7 ‘Subject Name: Introduction to Web Development Unit-V Subject Code: 4340704 TT © Now “GTU" database is created. phpMyAdmin uistiee | H meme ie 5 tri ti rtf tt | tt wea | amen ‘* Creating a database using console co Run wampserver and Click on wampserver icon © Now Click on MySQL option Ei Apache 2a belly rv 5635 Fey Mosca. 572 S er 10234 Pep) sta Al Services ES) stop al senices KY eta Al Serices Bs ror c/namp orPHP in PATH epartment of Computer Engineering Page & Subject Name: Introduction to Web Development Unit -V Subject Code: 4340704 © Click on MySQL console option |B version ¥ Service administration ‘wampmysqid’ ) MySQL settings BB M50 console 12 mys (2 MysQt og [Ed Myst documentation Stop All Services Restart All Services Zod 6) Error c/vamp or PHP in PATH © Provide username “root” and click on OK button Enter 2 vaid usemame. If you don't know, ‘een oot by defautt. rool) Coe) (ones) Prepared By: Department of Computer Engineering Page 9 Subject Name: Introduction to Web Development -V Subject Code: 4340704 As “root” username have no password press enter key inmysqlmysalS 7.20\bin\mysal exe © Now type a sql statement to create an database “211¢¢2”, “create database 21ce2 57.2Nbin\mysqlexe = aa a : ee Perey Champ binmysql my ST Cee rd See eeaet tre Caen eC] Prepared By: Department of Computer engineering Page 10 ‘Subject Name: Introduction to Web Development Unit -V Subject Code: 4340704 ‘+ Creating a database using PHP script Performing database operations ‘© mysqli_fetch_rows( ) © This function allows you to retrieve a record from the record set that is returned from executing the MySQL query. co The record that is returned by this function is in the form of numeric array. Numeric array contains index and value associated with that index. © If there is no record in the record set then it returns false value. © Syntax : mysqli_fetch_rows ($VariableName) ; Variable Name: Indicates the record set that is returned from executing the MySQL. command using mysqli_query () function, o Example: Write a php seript to search a record from database. "; } mysqli_close(Scon); > Prepared By: Department of Computer Engineering Page 13 e: Introduction to Web Development Unit -V Subject Code: 4340704 © This function allows you to retrieve a record from the record set that is returned from executing the MySQL query. © The record that is returned by this function is in the form of numeric array, associative array or both. © If there is no record in the record set then it returns false value. © Syntax: mysqli_fetch_array ($VariableName, ArrayType) ; Here, Variable Name : Indicates the record set that is retumed from executing the MySQL command using mysqli_query () function, © Array Type indicates the type of the array to be returned. © It can have one of the following value : (1) MYSQL_ASSOC : This type of array contains name of the field and the value associated with that field for current record, (2) MYSQL_NUM : This type array contains index of the field and the value associated with that index for current record. (3) MYSQL_BOTH : It is combination of both Associative array and Numeric array. Tt is the default type to be returned by this function, o Example : ‘+ Update data into the table + Retrieve data from the table ”; I mysqli_close($con); > Prepared By: Department of Computer Engineering Page 17 ‘Subject Name: Introduction to Web Development Unit-V Subject Code: 4340704 ‘* Delete data from the table isplaying data from the database in different formats, including tables * Display data from the database in tabular format 0) { echo “stable border=1>"; echo “ Enrollment No ”; echo “ Student Name ”; echo “ Semester ”; while (Sres=mysqli_fetch_row(Sans)) { echo "$res[0] ”; echo “Sres[]s/td>”; echo “Sres[2}”: echo “Sres[3}s/td>"; Prepared By: Department of Computer Engineering Page 18 Unit -V Subject Code: 4340704 echo “No record Found”; I mysqli_close($con); Hosting a Website FTP is stands for File Transfer Protocol. ‘¢ Ibis a system that allow you to log in to a server and upload, download or modify content. © FileZilla is powerful and free software for transferring file over the internet. © Once you have the FileZilla client downloaded and activate on your system, enter the domain name in the address field. ‘* The Username and password you need to type in are the same as the ones you use to log in to your cPanel. ‘+ Connect toa web server © In the FileZilla QuickConnect bar at the top of the page, enter your website URL in the host field. © Enter your FTP usemame and password. © Click QuickConnect. 27 RITTS) Chew viz ace es ee — wareae Te T= = il vinaowe x Prepared By: Department of Computer Engineering Page 19 : Introduction to Web Development Unit -V Subject Code: 4340704 © While FileZilla connect to your web server, a number of messages dis log. © Once you are successfully connected to web server, the folder structure of your webserver display in the Remote Site pane in FileZilla. lay in the message ‘+ Transfer file to website © In the local site pane, navigate to the location of your website. Select the files you want to upload to the website. You can select multiple files. Drag the files you want to transfer from the Local site pane to Remote Site Pane. FileZilla automatically transfer your files to your website. When you are finished uploading your files, close FileZilla and check your website in browser. e000 Hort: pdemouicem Username admin eel _) Coico) Baus Conecng io TEES BET Status Conmecton estate wating for welcome message. Stas: —_‘IntoingS.- Status: Vein cea Stas TS cannerbon esabihed Sats Logged Seas: Rereng deny Commné PO Response 257 inyeurcurtocaton Commune TYPE Resjorse —_BOTVPE snow b-bbiay Commun PASI Prepared By: Department of Computer Engineering Page 20

You might also like