PHP入门笔记

 1.资源类型变量
打开文件 $fh = fopen('./msg.txt', 'a');
写内容,沿着资源写 fwrite($fh,$str);
关闭资源 fclose($fh);   

2.读取资源
fgetcsv($fh)每次读取一行

3.mysql基本语句
连接mysql
mysql -h localhost -u root -p password
查询所有数据库
show databases;
选库
use 库名
查看库下面的表
show tables;
建表
create table msg (
id int auto_increment primary key,
content varchar(200),
pubtime int
) charset utf8;
添加数据
insert into msg (id,content,pubtime) values (1,'第一天',12345);
告诉服务器你的字符集
set names utf8/gbk;
查询数据
select * from msg where id=1;
快速清空表
truncate 表名;

4. php中连接数据库
$conn = mysql_connect('localhost','root','123456');
//发送查询
mysql_query('use test',$conn);
mysql_query('set names utf8',$conn);
//接收POST数据
$sql =  "insert into note (title,content,pubtime) values ('".$_POST['title']."','".$_POST['content']."',".time().")";
if(mysql_query($sql,$conn)){
    echo '留言成功';
}else{
    echo '留言失败';
}

5.php中读取数据库信息
$sql = 'select * from note';
$rs = mysql_query($sql,$conn);
while (($row = mysql_fetch_assoc($rs))) {
    echo '<li><a href="show.php?id=',$row['id'],'">',$row['title'],'</li>';
}

posted @ 2017-02-04 11:39  北冥有鹏  阅读(118)  评论(0编辑  收藏  举报