1 <?php 2 ⁄⁄ example データベースにあるnails テーブルから、データを取り出す 3 class NailData { 4 var $_conn; 5 6 function NailData() { 7 $this->connect(); 8 } 9 10 function connect() { 11 $this->_conn = mysql_connect(); 12 mysql_select_db('example'); 13 } 14 15 ⁄** 16 * データを必要な部分だけ取り出す 17 *⁄ 18 function data($start,$numRows) { 19 $sql = "select * from nails order by nail_id " 20 . "limit $start, $numRows"; 21 $res = mysql_query($sql); 22 23 $ret = array(); 24 25 $i = $start; 26 while($row = mysql_fetch_object($res)) { 27 $ret[$i++] = $row; 28 } 29 return $ret; 30 } 31 32 ⁄** 33 * テーブルから行数を取り出す 34 *⁄ 35 function numRows() { 36 $sql = "select count(*) from nails"; 37 $res = mysql_query($sql); 38 $row = mysql_fetch_row($res); 39 return $row[0]; 40 } 41 } 42 ?>