In mysql, if we want to use PHP to create databases and tables, the method is very simple. We can directly use mysql_query() to execute the mysql create table command, CREATE DATABASE database_name.
The details are as follows
In order for PHP to execute the above statement, we must use the mysql_query() function. This function is used to send a query or command to the MySQL connection.
Example
In the example below, we create a database named "my_db":
The code is as follows | Copy code | ||||||||||||||||||||||||
{ die('Could not connect: ' . mysql_error());} if (mysql_query("CREATE DATABASE my_db",$con)){ echo "Database created";} else
echo "Error creating database: " . mysql_error(); }mysql_close($con); ?>
CREATE TABLE is used to create database tables in MySQL. Example
-------------------------------------------------- ----------------------------------
source:php.cn
Previous article:Detailed explanation of a PHP message board example (with source code download)_PHP tutorial
Next article:Detailed explanation of get and post examples of PHP form submission data_PHP tutorial
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
Group MySQL results by ID for looping over
I have a table with flight data in mysql. I'm writing a php code that will group and displ...
From 2024-04-06 17:27:56
0
1
406
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
|