Chapter 6 Part2: Manipulating MySQL Databases with PHP

Similar documents
What is MySQL? [Document provides the fundamental operations of PHP-MySQL connectivity]

PHP Development - Introduction

PHP. How Web Applications interact with server side databases CRUD. Connecting and using mysql from PHP PHP provides many mysql specific functions

More loops. Control structures / flow control. while loops. Loops / Iteration / doing things over and over and over and over...

Server side scripting and databases

Objectives. Chapter 10. Developing Object-Oriented PHP. Introduction to Object-Oriented Programming

By the end of this section of the practical, the students should be able to:

PHP Introduction. Some info on MySQL which we will cover in the next workshop...

PHP: Cookies, Sessions, Databases. CS174. Chris Pollett. Sep 24, 2008.

IELM 511 Information Systems Design Labs 5 and 6. DB creation and Population

Networks and Web for Health Informatics (HINF 6220) Tutorial 13 : PHP 29 Oct 2015

Web Programming. Dr Walid M. Aly. Lecture 10 PHP. lec10. Web Programming CS433/CS614 22:32. Dr Walid M. Aly

Create Basic Databases and Integrate with a Website Lesson 3

PHP. M hiwa ahamad aziz Raparin univercity. 1 Web Design: Lecturer ( m hiwa ahmad aziz)

Databases and SQL. Lecture outline. CSE 190 M (Web Programming) Spring 2008 University of Washington

An introduction for the novice. David Lawrence, JLab. 5/8/07 MySQL David Lawrence 1/36

WEB PROGRAMMING SCV1223. PHP : Authentication Example. Dr. Md Sah bin Hj Salam En. Jumail bin Taliba

MYSQL DATABASE ACCESS WITH PHP

Database Connectivity using PHP Some Points to Remember:

Chapter. Accessing MySQL Databases Using PHP

PHP: Databases and Classes. CS174. Chris Pollett. Sep 29, 2008.

CHAPTER 10. Connecting to Databases within PHP

MySQL: Access Via PHP

UNIT V ESTABLISHING A DATABASE CONNECTION AND WORKING WITH DATABASE

SQL stands for Structured Query Language. SQL lets you access and manipulate databases

Mysql Tutorial Show Table Like Name Not >>>CLICK HERE<<<

Lecture 13: MySQL and PHP. Monday, March 26, 2018

CET W/32 MySQL support module

CSC 405 Computer Security. Web Security

Lab 7 Introduction to MySQL

Accessing MySQL from PHP by George Yohng

This lecture. PHP tags

Databases PHP I. (GF Royle, N Spadaccini ) PHP I 1 / 24

itexamdump 최고이자최신인 IT 인증시험덤프 일년무료업데이트서비스제공

Development Technologies. Agenda: phpmyadmin 2/20/2016. phpmyadmin MySQLi. Before you can put your data into a table, that table should exist.

Lecture 7: Web hacking 3, SQL injection, Xpath injection, Server side template injection, File inclusion

Building an E-mini Trading System Using PHP and Advanced MySQL Queries ( ) - Contributed by Codex-M

Daniel Pittman October 17, 2011

A SQL Injection : Internal Investigation of Injection, Detection and Prevention of SQL Injection Attacks

COM1004 Web and Internet Technology

Oracle 1Z MySQL 5.6 Developer.

COMS 469: Interactive Media II

A QUICK GUIDE TO PROGRAMMING FOR THE WEB. ssh (then type your UBIT password when prompted)

Build Your Own Database Driven Website Using PHP & MySQL. by Kevin Yank

PHP Tutorial 6(a) Using PHP with MySQL

Mysql Manually Set Auto Increment To 1000

Chapters 10 & 11 PHP AND MYSQL

AN INTRODUCTION TO WEB PROGRAMMING. Dr. Hossein Hakimzadeh Department of Computer and Information Sciences Indiana University South Bend, IN

Adding A PHP+MySQL Hit Counter to your Website

Hello everyone! Page 1. Your folder should look like this. To start with Run your XAMPP app and start your Apache and MySQL.

CICS 515 b Internet Programming Week 2. Mike Feeley

PHP INTERVIEW QUESTION-ANSWERS

PHP: Hypertext Preprocessor. A tutorial Introduction

Chapter 7 PHP Files & MySQL Databases

Jackson State University Department of Computer Science CSC / Advanced Information Security Spring 2013 Lab Project # 3

Database-Aware Fault Localization for Dynamic Web Applications

Sample Relational Database


Introduction to PHP. Fulvio Corno, Laura Farinetti, Dario Bonino, Marco Aime 06/11/08

/Users/ekrimmel/Desktop/_potential/Zex site/assignment_8_common_functions.php Page 1 of 6

SQL Functionality SQL. Creating Relation Schemas. Creating Relation Schemas

LISUG web site project

School of Information and Computer Technology Sirindhorn International Institute of Technology Thammasat University

Simple SCORM LMS Adapter Full Documentation

If you do not specify any custom parameters, we will deliver the message using the default names.

Mount Saint Mary College, Newburgh, NY Internet Programming III - CIT310

Relational databases and SQL

Introduction to SQL on GRAHAM ED ARMSTRONG SHARCNET AUGUST 2018

A1 (Part 2): Injection SQL Injection

CSC System Development with Java. Database Connection. Department of Statistics and Computer Science. Budditha Hettige

How to use SQL to create a database

APLIKACJE INTERNETOWE 8 PHP WYKORZYSTANIE BAZY DANYCH MYSQL

IS 2150 / TEL 2810 Introduction to Security

Short List of MySQL Commands

Lecture 6 Session Control and User Authentication. INLS 760 Web Databases Spring 2013 Rob Capra

Introduction to Databases and SQL

A340 Laboratory Session #17

CPSC 421 Database Management Systems. Lecture 10: Embedded SQL

Week 11 ~ Chapter 8 MySQL Command Line. PHP and MySQL CIS 86 Mission College

Database and MySQL Temasek Polytechnic

Unit 27 Web Server Scripting Extended Diploma in ICT

Flex and PHP. Communication between Flex and PHP with amfphp

Oracle Exam 1z0-882 Oracle Certified Professional, MySQL 5.6 Developer Version: 7.0 [ Total Questions: 100 ]

Overview of MySQL Structure and Syntax [2]

SPECCHIO Administrators

Web Systems Nov. 2, 2017

Lecture 5. Monday, September 15, 2014

SQL Commands & Mongo DB New Syllabus

WEB SECURITY: SQL INJECTION

Systems Programming & Scripting

Web Security. Attacks on Servers 11/6/2017 1

Comp 519: Web Programming Autumn 2015

CSCI/CMPE Object-Oriented Programming in Java JDBC. Dongchul Kim. Department of Computer Science University of Texas Rio Grande Valley

Database Management Systems Design. Week 6 MySQL Project

PHP Personal Home Page PHP: Hypertext Preprocessor (Lecture 35-37)

SQL. Often times, in order for us to build the most functional website we can, we depend on a database to store information.

COMP519: Web Programming Autumn 2015

Application Links. Chapter 7.1 V3.0. Napier University Dr Gordon Russell

PHP Reference. To access MySQL manually, run the following command on the machine, called Sources, where MySQL and PhP have been installed:

PHP APIs. Rapid Learning & Just In Time Support

Transcription:

IT215 Web Programming 1 Chapter 6 Part2: Manipulating MySQL Databases with PHP Jakkrit TeCho, Ph.D. Business Information Technology (BIT), Maejo University Phrae Campus

Objectives In this chapter, you will: Connect to MySQL from PHP Work with MySQL databases using PHP Create, modify, and delete MySQL tables with PHP Use PHP to manipulate MySQL records Use PHP to retrieve database records 2

Connecting to MySQL with PHP PHP has the ability to access and manipulate any database that is ODBC compliant PHP includes functionality that allows you to work directly with different types of databases, without going through ODBC PHP supports SQLite, database abstraction layer functions, and PEAR DB 3

Determining which MySQL Package to Use The mysqli (MySQL Improved) package became available with PHP 5 and is designed to work with MySQL version 4.1.3 and later Earlier versions must use the mysql package The mysqli package is the object-oriented equivalent of the mysql package but can also be used proceduraly Mysqli package has improved speed, security and compatibility with libraries. 4

Opening and Closing a MySQL Connection Open a connection to a MySQL database server with the mysql_connect() function The mysql_connect() function returns a positive integer if it connects to the database successfully or FALSE if it does not Assign the return value from the mysql_connect() function to a variable that you can use to access the database in your script 5

Opening and Closing a MySQL Connection (continued) The syntax for the mysql_connect() function is: $connection = mysql_connect("host" [, "user", "password"]); The host argument specifies the host name where your MySQL database server is installed The user and password arguments specify a MySQL account name and password 6

Opening and Closing a MySQL Connection (continued) The database connection is assigned to the $DBConnect variable $DBConnect = mysql_connect("localhost", "dongosselin ", "rosebud"); Close a database connection using the mysql_close() function mysql_close($dbconnect); 7

Opening and Closing a MySQL Connection (continued) 8

Opening and Closing a MySQL Connection (continued) Figure 8-1 MySQLInfo.php in a Web browser 9

Reporting MySQL Errors Reasons for not connecting to a database server include: The database server is not running Insufficient privileges to access the data source Invalid username and/or password 10

Reporting MySQL Errors (continued) The mysql_errno() function returns the error code from the last attempted MySQL function call or 0 if no error occurred The mysql_error() Returns the text of the error message from previous MySQL operation The mysql_errno() and mysql_error() functions return the results of the previous mysql*() function 11

Selecting a Database The syntax for the mysql_select_db() function is: mysql_select_db(database [, connection]); The function returns a value of TRUE if it successfully selects a database or FALSE if it does not For security purposes, you may choose to use an include file to connect to the MySQL server and select a database 12

good Sample Code $link = mysql_connect("isam.sis.pitt.edu", ug1", pa ssword"); bad good bad mysql_select_db("nonexistentdb", $link); echo mysql_errno($link). ": ". mysql_error($link). "\ n"; mysql_select_db( ug1", $link); mysql_query("select * FROM nonexistenttable", $ link); echo mysql_errno($link). ": ". mysql_error($link). "\ n"; 13

Sample Code $host='isam.sis.pitt.edu'; $username = 'ug1'; $password = *****'; $database ='ug1'; $link = mysql_connect ($host, $username, $password ); if (!$link) { die('could not connect: '. mysql_error()); } echo 'Connected successfully'; mysql_close($link); 14

Sample Code <?php $link = mysql_connect('localhost', 'mysql_user', 'mysql_p assword'); if (!$link) { die('not connected : '. mysql_error()); } // make foo the current db $db_selected = mysql_select_db('foo', $link); if (!$db_selected) { die ('Can\'t use foo : '. mysql_error()); }?> 15

Suppressing Errors with the Error Control Operator By default, functions in the mysql package display errors and warnings as they occur Use the error control operator (@) to suppress error messages The error control operator can be prepended to any expression although it is commonly used with expressions 16

Executing SQL Statements Use the mysql_query() function to send SQL statements to MySQL The syntax for the mysql_query() function is: mysql_query(query [, connection]); The mysql_query() function returns one of three values: For SQL statements that do not return results (CREATE DATABASE and CREATE TABLE statements) it returns a value of TRUE if the statement executes successfully 17

Executing SQL Statements (continued) For SQL statements that return results (SELECT and SHOW statements) the mysql_query() function returns a result pointer that represents the query results A result pointer is a special type of variable that refers to the currently selected row in a resultset The mysql_query() function returns a value of FALSE for any SQL statements that fail, regardless of whether they return results 18

Sample Code <?php // This could be supplied by a user, for example $firstname = 'fred'; $lastname = 'fox'; // Formulate Query // This is the best way to perform an SQL query // For more examples, see mysql_real_escape_string() $query = sprintf("select firstname, lastname, address, age FROM friends WHERE firstname='%s' AND lastname='%s'", mysql_real_escape_string($firstname), mysql_real_escape_string($lastname)); // Perform Query $result = mysql_query($query); // Check result // This shows the actual query sent to MySQL, and the error. Useful for debugging. if (!$result) { $message = 'Invalid query: '. mysql_error(). "\n"; $message.= 'Whole query: '. $query; die($message); } // Use result // Attempting to print $result won't allow access to information in the resource // One of the mysql result functions must be used // See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(), etc. while ($row = mysql_fetch_assoc($result)) { echo $row['firstname']; echo $row['lastname']; echo $row['address']; echo $row['age']; } // Free the resources associated with the result set // This is done automatically at the end of the script mysql_free_result($result);?> 19

Adding, Deleting, and Updating Records To add records to a table, use the INSERT and VALUES keywords with the mysql_query() function To add multiple records to a database, use the LOAD DATA statement with the name of the local text file containing the records you want to add To update records in a table, use the UPDATE statement 20

Adding, Deleting, and Updating Records From W3c <?php $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('could not connect: '. mysql_error()); } mysql_select_db("my_db", $con); mysql_query("insert INTO Persons (FirstName, LastName, Age) VALUES ('Peter', 'Griffin', '35')"); mysql_query("insert INTO Persons (FirstName, LastName, Age) VALUES ('Glenn', 'Quagmire', '33')"); mysql_close($con);?>

Adding, Deleting, and Updating Records (continued) The UPDATE keyword specifies the name of the table to update The SET keyword specifies the value to assign to the fields in the records that match the condition in the WHERE clause To delete records in a table, use the DELETE statement with the mysql_query() function Omit the WHERE clause to delete all records in a table 22

Adding, Deleting, and Updating Records From W3c <?php $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('could not connect: '. mysql_error()); } mysql_select_db("my_db", $con); mysql_query("update Persons SET Age = '36' WHERE FirstName = 'Peter' AND LastName = 'Griffin'"); mysql_close($con);?>

Retrieving Records into an Indexed Array The mysql_fetch_row() function returns the fields in the current row of a resultset into an indexed array and moves the result pointer to the next row echo "<table width='100% border='1'>"; echo "<tr><th>make</th><th>model</th> <th>price</th><th>quantity</th></tr>"; $Row = mysql_fetch_row($queryresult); do { echo "<tr><td>{$row[0]}</td>"; echo "<td>{$row[1]}</td>"; echo "<td align='right'>{$row[2]}</td>"; echo "<td align='right'>{$row[3]}</td></tr>"; $Row = mysql_fetch_row($queryresult); } while ($Row); 24

Sample Code <?php $conn = mysql_connect("localhost", "mysql_user", "mysql_password"); if (!$conn) { echo "Unable to connect to DB: ". mysql_error( ); exit; } if (!mysql_select_db("mydbname")) { echo "Unable to select mydbname: ". mysql_er ror(); exit; } $sql = "SELECT id as userid, fullname, userstatus FROM sometable WHERE userstatus = 1"; $result = mysql_query($sql); if (!$result) { echo "Could not successfully run query ($sql) fr om DB: ". mysql_error(); } exit; if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exi ting"; exit; } // While a row of data exists, put that row in $row as an associative array // Note: If you're expecting just one row, no need t o use a loop // Note: If you put extract($row); inside the followin g loop, you'll // then create $userid, $fullname, and $userst atus while ($row = mysql_fetch_assoc($result)) { echo $row["userid"]; echo $row["fullname"]; echo $row["userstatus"]; } mysql_free_result($result);?> 25

Using the mysql_affected_rows() Function With queries that return results (SELECT queries), use the mysql_num_rows() function to find the number of records returned from the query With queries that modify tables but do not return results (INSERT, UPDATE, and DELETE queries), use the mysql_affected_rows() function to determine the number of affected rows 26

Using the mysql_affected_rows() Function (continued) $SQLstring = "UPDATE company_cars SET mileage=50112.3 WHERE license='ak-1234'"; $QueryResult = @mysql_query($sqlstring, $DBConnect); if ($QueryResult === FALSE) else echo "<p>unable to execute the query.</p>". "<p>error code ". mysql_errno($dbconnect). ": ". mysql_error($dbconnect). "</p>"; echo "<p>successfully updated ". mysql_affected_rows($dbconnect). " record(s).</p>"; 27

Using the mysql_affected_rows() Function (continued) Figure 8-5 Output of mysql_affected_rows() function for an UPDATE query 28

Using the mysql_info() Function For queries that add or update records, or alter a table s structure, use the mysql_info() function to return information about the query The mysql_info() function returns the number of operations for various types of actions, depending on the type of query The mysql_info() function returns information about the last query that was executed on the database connection 29

Using the mysql_info() Function (continued) The mysql_info() function returns information about queries that match one of the following formats: INSERT INTO...SELECT... INSERT INTO...VALUES (...),(...),(...) LOAD DATA INFILE... ALTER TABLE... UPDATE For any queries that do not match one of these formats, the mysql_info() function returns an empty string 30

Using the mysql_info() Function (continued) $SQLstring = "INSERT INTO company_cars ". " (license, model_year, make, model, mileage) ". " VALUES ". " ('CPQ-894', 2011, 'Honda', 'Insight', 49.2), ". " ('CPQ-895', 2011, 'Honda', 'Insight', 17.9), ". " ('CPQ-896', 2011, 'Honda', 'Insight', 22.6)"; $QueryResult = @mysql_query($sqlstring, $DBConnect); if ($QueryResult === FALSE) echo "<p>unable to execute the query.</p>". "<p>error code ". mysql_errno($dbconnect). ": ". mysql_error($dbconnect). "</p>"; else { echo "<p>successfully added the record.</p>"; echo "<p>". mysql_info($dbconnect). "</p>"; } 31

Using the mysql_info() Function (continued) Figure 8-6 Output of mysql_info() function for an INSERT query that adds multiple records 32

Using the mysql_info() Function (continued) The mysql_info() function also returns information for LOAD DATA queries $SQLstring = "LOAD DATA INFILE 'company_cars.txt' INTO TABLE company_cars;"; $QueryResult = @mysql_query($sqlstring, $DBConnect); if ($QueryResult === FALSE) else { } echo "<p>unable to execute the query.</p>". "<p>error code ". mysql_errno($dbconnect). ": ". mysql_error($dbconnect). "</p>"; echo "<p>successfully added the record.</p>"; echo "<p>". mysql_info($dbconnect). "</p>"; 33

Using the mysql_info() Function (continued) Figure 8-7 Output of mysql_info() function for a LOAD DATA query 34

Working with Query Results 35

Retrieving Records into an Indexed Array The mysql_fetch_row() function returns the fields in the current row of a result set into an indexed array and moves the result pointer to the next row 36

Retrieving Records into an Indexed Array $SQLstring = "SELECT * FROM company_cars"; $QueryResult = @mysql_query($sqlstring, $DBConnect); echo "<table width='100%' border='1'>\n"; echo "<tr><th>license</th><th>make</th><th>model</th> <th>mileage</th><th>year</th></tr>\n"; while (($Row = mysql_fetch_row($queryresult))!== FALSE) { echo "<tr><td>{$row[0]}</td>"; echo "<td>{$row[1]}</td>"; echo "<td>{$row[2]}</td>"; echo "<td align='right'>{$row[3]}</td>"; echo "<td>{$row[4]}</td></tr>\n"; } echo "</table>\n"; 37

Retrieving Records into an Indexed Array Figure 8-8 Output of the company_cars table in a Web Browser 38

Retrieving Records into an Associative Array The mysql_fetch_assoc() function returns the fields in the current row of a resultset into an associative array and moves the result pointer to the next row The difference between mysql_fetch_assoc() and mysql_fetch_row() is that instead of returning the fields into an indexed array, the mysql_fetch_assoc() function returns the fields into an associate array and uses each field name as the array key 39

Closing Query Results When you are finished working with query results retrieved with the mysql_query() function, use the mysql_free_result() function to close the resultset To close the resultset, pass to the mysql_free_result() function the variable containing the result pointer from the mysql_query() function 40

Accessing Query Result Information The mysql_num_rows() function returns the number of rows in a query result The mysql_num_fields() function returns the number of fields in a query result Both functions accept a database connection variable as an argument 41

Accessing Query Result Information (continued) $SQLstring = "SELECT * FROM company_cars"; $QueryResult = @mysql_query($sqlstring, $DBConnect); if ($QueryResult === FALSE) else echo "<p>unable to execute the query.</p>". "<p>error code ". mysql_errno($dbconnect). ": ". mysql_error($dbconnect). "</p>"; echo "<p>successfully executed the query.</p>"; $NumRows = mysql_num_rows($queryresult); $NumFields = mysql_num_fields($queryresult); if ($NumRows!= 0 && $NumFields!= 0) echo "<p>your query returned ". mysql_num_rows($queryresult). " rows and ". mysql_num_fields($queryresult). " fields.</p>"; else echo "<p>your query returned no results.</p>"; mysql_close($dbconnect); 42

Accessing Query Result Information (continued) Figure 8-10 Output of the number of rows and fields returned from a query 43

Summary The mysql_connect() function opens a connection to a MySQL database server The mysql_close() function closes a database connection The mysql_errno() function returns the error code from the last attempted MySQL function call or zero if no error occurred 44

Summary (continued) The mysql_error() function returns the error message from the last attempted MySQL function call or an empty string if no error occurred The error control operator (@) suppresses error messages You use the mysql_create_db() function to create a new database The mysql_select_db() function selects a database 45

Summary (continued) You use the mysql_drop_db() function to delete a database The mysql_query() function sends SQL statements to MySQL A result pointer is a special type of variable that refers to the currently selected row in a resultset You use the CREATE TABLE statement with the mysql_query() function to create a table 46

Summary (continued) The PRIMARY KEY clause indicates a field or fields that will be used as a referential index for the table The AUTO_INCREMENT clause creates a field that is automatically updated with the next sequential value for that column The NOT NULL clause creates a field that must contain data You use the DROP TABLE statement with the mysql_query() function to delete a table 47

Summary (continued) You use the LOAD DATA statement and the mysql_query() function with a local text file to add multiple records to a database MAY NOT WORK ON PARADOX You use the UPDATE statement with the mysql_query() function to update records in a table You use the DELETE statement with the mysql_query() function to delete records from a table 48

Summary (continued) The mysql_info() function returns the number of operations for various types of actions, depending on the type of query. The mysql_fetch_row() function returns the fields in the current row of a resultset into an indexed array and moves the result pointer to the next row. 49

Summary (continued) The mysql_fetch_assoc() function returns the fields in the current row of a resultset into an associative array and moves the result pointer to the next row The mysql_free_result() function closes a resultset 50

Summary (continued) The mysql_num_rows() function returns the number of rows in a query result, and the mysql_num_fields() function returns the number of fields in a query result With queries that return results, such as SELECT queries, you can use the mysql_num_rows() function to find the number of records returned from the query 51

Creating and Deleting Tables Use the CREATE TABLE statement with the mysql_query() function to create a new table Use the mysql_select_db() function before executing the CREATE TABLE statement to verify that you are in the right database 52

Creating and Deleting Tables (continued) $SQLstring = "CREATE TABLE drivers (name VARCHAR(100), ". "emp_no SMALLINT, hire_date DATE, ". "stop_date DATE)"; $QueryResult = @mysql_query($sqlstring, $DBConnect); if ($QueryResult===FALSE) else echo "<p>unable to execute the query.</p>". "<p>error code ". mysql_errno($dbconnect) "</p>";. ": ". mysql_error($dbconnect). echo "<p>successfully created the table.</p>"; 53

Creating and Deleting Tables (continued) Figure 8-3 Error code and message that displays when you attempt to create a table that already exists 54

Creating and Deleting Tables (continued) Use the SHOW TABLES LIKE command to prevent code from trying to create a table that already exists. If the table does not exist, the mysql_num_rows()function will return a value of 0 rows $TableName = "subscribers"; $SQLstring = "SHOW TABLES LIKE '$TableName'"; $QueryResult = @mysql_query($sqlstring, $DBConnect); 55

Creating and Deleting Tables (continued) To identify a field as a primary key in MySQL, include the PRIMARY KEY keywords when you define a field with the CREATE TABLE statement The AUTO_INCREMENT keyword is often used with a primary key to generate a unique ID for each new row in a table The NOT NULL keywords are often used with primary keys to require that a field include a value 56

Creating and Deleting Tables (continued) To delete a table, use the DROP TABLE statement with the mysql_query() function 57

Creating a Database Use the mysql_create_db() function to create a new database The basic syntax for the mysql_create_db() is: $result = mysql_create_db( "dbname" [, connection]); The mysql_create_db() returns a Boolean TRUE if successful or FALSE if there was an error In most cases we will use mysql monitor, PhpMyAdmin or Workbench to create databases. 58

Creating a Database (continued) Figure 8-2 Error message when the mysql_create_db() function is unavailable because of insufficient privileges 59

Deleting a Database To delete a database, use the mysql_drop_db() function. The format for the mysql_drop_db() function is: $Result = mysql_drop_db("dbname" [, connection]); The function returns a value of TRUE if it successfully drops a database or FALSE if it does not 60