
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How can we create a MySQL temporary table by using PHP script?
As we know that PHP provides us the function named mysql_query() to create a MySQL table. Similarly, we can use mysql_query() function to create MySQL temporary table. To illustrate this, we are using the following example −
Example
In this example, we are creating a temporary table named ‘SalesSummary’ with the help of PHP script in the following example −
<html> <head> <title>Creating MySQL Temporary Tables</title> </head> <body> <?php $dbhost = 'localhost:3036'; $dbuser = 'root'; $dbpass = 'rootpassword'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully<br />'; $sql = "CREATE TEMPORARY TABLE SalesSummary( ". "Product_Name VARCHAR(50) NOT NULL, ". "total_sales DECIMAL(12,2) NOT NULL DEFAULT 0.00, ". "avg_unit_price DECIMAL(7,2) NOT NULL DEFAULT 0.00, ". "total_units_sold INT UNSIGNED NOT NULL DEFAULT 0, ".); "; mysql_select_db( 'TUTORIALS' ); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not create table: ' . mysql_error()); } echo "Table created successfully
"; mysql_close($conn); ?> </body> </html>
- Related Articles
- How can we create a MySQL table by using PHP script?
- How can we delete an existing MySQL table by using PHP script?
- How can we create a new database by using PHP script?
- How can we handle NULL values stored in a MySQL table by using PHP script?
- How can we delete a MySQL database by using PHP script?
- How can we select a MySQL database by using PHP script?
- How can we insert data into an existing MySQL table by using PHP script?
- What are MySQL Temporary Tables? How can we create them?
- How can we write PHP script to count the affected rows by MySQL query?
- How can we display all the records from MySQL table with the help of PHP script?
- How can I delete MySQL temporary table?
- Create a temporary table in a MySQL procedure?
- How can we fetch all the data from MySQL table by using mysql_fetch_array() function, returning an array with the numeric index, in PHP script?
- Create a temporary table with dates in MySQL
- How to create a temporary MySQL table in a SELECT statement without a separate CREATE TABLE?

Advertisements