MySQL creates a database using PHP

Source: Internet
Author: User

Create a database using Mysqladmin

With a normal user, you may need specific permissions to create or delete a MySQL database.

So here we are using the root user login, the root user has the highest privileges, you can use the MySQL mysqladmin command to create a database.

Instance

The following command simply demonstrates the process of creating a database with the data name tutorials:

[[email protected]] - - Create tutorialsenter Password: ******

After successful execution of the above command, MySQL database tutorials will be created.

creating a database using PHP scripts

PHP uses the Mysql_query function to create or delete MySQL databases.

The function has two parameters, returns TRUE on successful execution, or FALSE.

Grammar
mysql_query (SQL, connection);

Parameters Description
Sql Necessary. Specifies the SQL query to send. Note: The query string should not end with a semicolon.
Connection Optional. Specifies the SQL connection identifier. If not specified, the previous open connection is used.

Instance

The following example demonstrates the use of PHP to create a database:

MySQLdatabase</title>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 DATABASE tutorials ';$retval=mysql_query($sql,$conn );if(!$retval ){   die(' Could not create database: '.Mysql_error());}Echo"Database Tutorials created successfully\n";Mysql_close($conn);?></body>

Original address: http://www.manongjc.com/mysql/mysql_create_database.html

Related reading:

    • MySQL Delete Database
    • MySQL Select Database
    • MySQL data type
    • MySQL Create data table
    • MySQL Delete Data Sheet
    • MySQL Inserting data
    • MySQL query data

MySQL creates a database using PHP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.