PHP笔记(PHP高级篇)
高级篇中将涉及数据库的使用以及Cookie和Session会话,提高PHP的开发效率和运行效率
PHP程序员需要掌握的MySQL操作
连接MySQL DB:
数据定义语言(DDL)
<span style="color: #0000ff;">CREATE</span> <span style="color: #0000ff;">DATABASE</span> <span style="color: #ff0000;">[</span><span style="color: #ff0000;">IF NO EXISTS</span><span style="color: #ff0000;">]</span> DatabaseName
<span style="color: #0000ff;">CREATE</span> <span style="color: #0000ff;">TABLE</span> <span style="color: #ff0000;">[</span><span style="color: #ff0000;">IF NOT EXISTS</span><span style="color: #ff0000;">]</span><span style="color: #000000;"> TableName (colname1 type </span><span style="color: #ff0000;">[</span><span style="color: #ff0000;">property</span><span style="color: #ff0000;">]</span> <span style="color: #ff0000;">[</span><span style="color: #ff0000;">index</span><span style="color: #ff0000;">]</span><span style="color: #000000;">,colname2 type </span><span style="color: #ff0000;">[</span><span style="color: #ff0000;">property</span><span style="color: #ff0000;">]</span> <span style="color: #ff0000;">[</span><span style="color: #ff0000;">index</span><span style="color: #ff0000;">]</span><span style="color: #000000;">,...)[tableType] [tableCharSet];</span>
※任何数据类型以字符串的形式存入,都可以自动转换类型
※将时间保存为php时间戳,方便运算
数据字段属性
索引
数据表类型及存储位置
功能 | MyISAM | InnoDB |
事务处理 | 不支持 | 支持 |
数据行锁定 | 不支持 | 支持 |
外键约束 | 不支持 | 支持 |
表空间占用 | 相对较小 | 较大 |
全文索引 | 支持 | 不支持 |
MySQL默认字符集
数据操作语言(DML)
数据查询语言(DQL)
数据控制语言(DCL)
MySQL内置函数
strcmp(s1,s2):如果S1比S2小,返回-1;如果S1比S2大则返回1;如果相等则返回0(比较的是ASCII码)
PHP操作数据库
mysqli操作数据库
PDO
mamcache/memcached
基于libevent事件,所以必须先安装libevent库
Command | Description | Example |
---|---|---|
get | Reads a value | get mykey |
set | Set a key unconditionally | set mykey 0 60 5 |
add | Add a new key | add newkey 0 60 5 |
replace | Overwrite existing key | replace key 0 60 5 |
append | Append data to existing key | append key 0 60 15 |
prepend | Prepend data to existing key | prepend key 0 60 15 |
incr | Increments numerical key value by given number | incr mykey 2 |
decr | Decrements numerical key value by given number | decr mykey 5 |
delete | Deletes an existing key | delete mykey |
flush_all | Invalidate specific items immediately | flush_all |
Invalidate all items in n seconds | flush_all 900 | |
stats | Prints general statistics | stats |
Prints memory statistics | stats slabs | |
Prints memory statistics | stats malloc | |
Print higher level allocation statistics | stats items | |
stats detail | ||
stats sizes | ||
Resets statistics | stats reset | |
version | Prints server version. | version |
verbosity | Increases log level | verbosity |
quit | Terminate telnet session | quit |
PHP中使用memcache
<span style="color: #008080;">1</span> <span style="color: #000000;">php</span><span style="color: #008080;">2</span> <span style="color: #800080;">$memcache</span> = <span style="color: #0000ff;">new</span><span style="color: #000000;"> Memcache;</span><span style="color: #008080;">3</span> <span style="color: #800080;">$memcache</span>->connect("localhost",11211) or <span style="color: #0000ff;">die</span>("could not connect");
会话控制:面向连接的可靠的连接方式,通过会话控制,判断用户的登录行为
至此,PHP的基础学习算是完成了,需要多做多学,方能提高!