$handle=fopen("C:/1.txt","r")
fseek($handle,-200,SEEK_END)
$str=fgets($handle)
echo $str//输出最后一行
fclose($handle)
$con = mysql_connect("localhost","root","")//连接数据库mysql_select_db("btxiazai",$con)//选择数据库
mysql_query("set names utf8")
$sql = "select * from persons order by id desc limit 2"//获取persons中的数据,并按id倒叙排列,取其中两条
$get = mysql_query($sql)//执行sql
while($result = mysql_fetch_assoc($get)){//取回数据
}
<?php//建立连接
$conn = mysql_connect('localhost','','')
or die(mysql_error())
//选择数据库
mysql_select_db('databaseName',$conn)
//sql语句
$query = "select * from your table"
//查询
$result = mysql_query($query)
//取结果集行数
$rownum = mysql_num_row($result)
//定位到最后一行
mysql_data_seek($result,$rownum)
//取出数据
$row = mysql_fetch_assoc($result)
//访问数据
echo $row[id]
echo $row[row1]
?>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)