Connect MySQL database through PHP, create database, CREATE table

Source: Internet
Author: User
Tags mysql create database mysql database

Connect MySQL database via PHP

$conn = mysql_connect("localhost","root","password") or die("无法连接数据库");
mysql_select_db("table" ,$conn) or die ("找不到数据源");

Create MySQL database via PHP

$conn = mysql_connect("localhost","root","password") or die("无法连接数据库");
mysql_create_db("webjx") or die("无法创建数据库");
$sqlstr = "create database other_webjx";
mysql_query($sqlstr) or die("无法创建,一般请检查权限什么的");

Create a table for MySQL

$conn = mysql_connect("localhost","root","password") or die("无法连接数据库");
mysql_select_db("webjx",$conn) or die("无法连接数据库webjx");
$sql = "create table webjx_table(
ids integer not null auto_increment ,
primary key(ids)
)";
$mysql_query($sql) or die(mysql_error());

Related Article

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.