Home >Database >Mysql Tutorial >php操作mysql--连接数据库创建表填充表_MySQL

php操作mysql--连接数据库创建表填充表_MySQL

WBOY
WBOYOriginal
2016-06-01 13:01:411106browse

<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/3/31
 * Time: 14:40
 */
header("Content-Type:text/html;charset=utf8");//申明编码格式
$conn=mysql_connect("localhost","root","aaaaaa") or die("数据库连接错误".mysql_errno());//连接sql
// $createTable=mysql_query("create database phpTest",$conn) or die ("创建表错误:".mysql_errno());//创建数据库
mysql_select_db("phpTest",$conn);//从sql中选择数据库
mysql_query(&#39;SET NAMES UTF8&#39;) or die(&#39;字符集设置错误&#39;.mysql_error());//设置输入的字符集编码

/*$sql ="CREATE TABLE txt (             //sql创建一个表,并且填充字段的命令
id TINYINT(2) UNSIGNED NOT NULL AUTO_INCREMENT,
username varchar(20),
password char(32),
email varchar(40),
regdate int(10),//用int来保存时间戳
PRIMARY KEY (id)
)";

mysql_query($sql) or die("创建表格错误:".mysql_errno());//执行创建表的SQL指令

*/
$regdate = time(); //得到时间戳
$input="INSERT INTO txt(username, password, email, regdate) VALUES (&#39;小王&#39;, &#39;passwords&#39;,&#39;12345@163.com&#39;, $regdate)";
//sql添加数据语句
mysql_query($input,$conn) or die("添加数据错误:".mysql_errno());//执行添加数据的sql指令

?>

Statement:
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