触摸艺术和时尚的音弦 ---- happydog's art secret garden ~~~

PHP笔记七

上一篇 / 下一篇  2008-04-20 19:35:57

PHP & MySQL

  有mysql和mysqli 两套函数组,后者新,有新的特点使得他效率高。

假设 mysql里面建立test数据库,users表格
 <?php
 print "<pre>";
 if (!($connection = mysql_connect("localhost","root","password")))
  die ("Cannot connect");
 //连接数据库
  if (!(mysql_select_db("test",$connection)))
 //选择DB
  die ("Cannot select DB");
  $query ='SELECT * FROM `users`';
  $result = @mysql_query($query,$connection);
 //进行一条查询
  $count = @mysql_num_fields($result);
 //看看有多少列 
 while ($row = @mysql_fetch_array($result))
 //读出来
 //如果不是用index下标则
 // print "{$row["username"]}  ";
 
    { print "\n";
 for ($x=0;$x<$count;$x++)
 print "{$row[$x]}  "; }
  print "</pre>";
?>

数据库基本概念
 table:   fields(describe structure) and records(data)
  field 也可以叫column或者attribute
 Normalization     删去冗余
 Relationship between tables
  1 对 1,  常常可以用来删除frequently Null valued field
  1 对 多   比如一个作家表(author_id,name),一个作品表(subject_id,author_id,title) 一个作家在作品表当中可能有很多作品。
  多对多    比如有一个学生表,一个课程表,一个学生可能出现在课程表中多个记录中,反过来一个课程也可以出现在学生表中选课项多处。
  1 with 0 表示未必一定要出现
  0 without 1 表示一定要存在
KEYS
 Primary Key  主键  唯一,而且起识别作用
 Unique Key 唯一, 和主键不同是,它不想主键那样要被用来定义表格之间的关系
 Foreign Key  是父表中的主键拷贝了一份在子表格中,维持两个表格的关系,
 这种Primary Key , Foreign Key 的限制条件满足检查就是 Referential Integrity
 
INDEX 索引
 
 


TAG:

 

評分:0

我來說兩句

顯示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

Open Toolbar