创建数据库timelinedb:
create database timelinedb;
创建一个用户给他提供操作my_db的权利(用户名:mydbuser,密码:himydb):
grant select, insert, delete, update
on timelinedb.*
to mydbuser identified by 'himydb';
选择要操作的数据库:
use timelinedb;
给timelinedb创建表:
create table users
( userid int unsigned not null auto_increment primary key,
username char(50) not null,
email char(100) not null,
password char(50) not null
);
create table pages
( versionid int unsigned not null auto_increment primary key,
version bigint not null,
time datetime not null,
path char not null,
information longtext,
pageid int not null
);
如果保存较长的字符串,可用text/longtext代替char。
修改定义的列:
alter table pages change path path varchar(200) not null;
给表users插入数据:
insert into users values
(NULL, 'timeline', 'timeline@timeline.com', 'timeline');
清空一个表:
truncate table mytable;
PHP操作
选择数据:
$query = "select version, versionid from pages where version = (select max(version) from pages)";
$result=mysql_query($query);
if(mysql_num_rows($result) > 0){
while ($row = mysql_fetch_assoc($result)) {
return $row['version'];
}
注:存入的数据中有'\',则要加转义字符,应写成'\\'。