Module 6 Web Server And Server Side Scripting Part 2 Chapter

Module 6web Server And Server Side Scrpting Part 2chapter 19of Tex

Module 6:WEB SERVER AND SERVER SIDE SCRPTING, PART-2 Chapter 19of Text Book DATABSE Connection to MySQL / PHP Internet & World Wide Web How to Program, 5/e YANBU UNIVERSITY COLLEGE Management Science Department © Yanbu University College © Yanbu University College DATABASE CONNECTIVITY PHP combined with MySQL are cross-platform (you can develop in Windows and serve on a Unix platform) PHP Connect to the MySQL Server Use the PHP mysqli_connect() function to open a new connection to the MySQL server. Open a Connection to the MySQL Server Before we can access data in a database, we must open a connection to the MySQL server. In PHP, this is done with the mysqli_connect() function. Syntax mysqli_connect(host , username , password , dbname); STEPS CREATE A USER in PHPMyAdmin CREATE A DATABASE CONNECT TO DATABASE DATA RETREIVAL/ MANIPULATION © Yanbu University College © Yanbu University College © Yanbu University College © Yanbu University College © Yanbu University College PHP Create Database and Tables A database holds one or more tables. Create a Database The CREATE DATABASE statement is used to create a database table in MySQL. We must add the CREATE DATABASE statement to the mysqli_query() function to execute the command. The following example creates a database named “MIS352": © Yanbu University College Create a Table The CREATE TABLE statement is used to create a table in MySQL. We must add the CREATE TABLE statement to the mysqli_query() function to execute the command. The following example creates a table named “MArks", with three columns. The column names will be “STD_ID", “STD_NAME" and “STD_MARKS": Note: When you create a database field of type CHAR, you must specify the maximum length of the field, e.g. CHAR(50). The data type specifies what type of data the column can hold. © Yanbu University College PHP MySQL Insert Into Insert Data Into a Database Table The INSERT INTO statement is used to add new records to a database table. Syntax It is possible to write the INSERT INTO statement in two forms. The first form doesn't specify the column names where the data will be inserted, only their values: INSERT INTO table_name VALUES (value1, value2, value3,...) The second form specifies both the column names and the values to be inserted: INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...) © Yanbu University College PHP MySQL Insert Into Example:In the previous slide we created a table named “Marks", with three columns; “STD_ID", “STD_Name" and “STD_Marks". We will use the same table in this example. The following example adds two new records to the “Marks" table:

Record added successfully";} else {echo"error in insertion";} mysqli_close($n); ?> © Yanbu University College Insert Data From a Form Into a Database HTML FILE

Insert your Detail in the DATABSE