随笔分类 -  PHP

摘要:我们在写数据库程序的时候,经常会需要获取某个表中的最大序号数,一般情况下获取刚插入的数据的id,使用select max(id) from table 是可以的。但在多线程情况下,就不行了。下面介绍三种方法(1) getGeneratedKeys()方法:程序片断:Connection conn = ; Serializable ret = null; PreparedStatement state = .; ResultSet rs=null; try { state.executeUpdate(); ... 阅读全文
posted @ 2012-09-12 13:25 神马和浮云 阅读(320) 评论(0) 推荐(0) 编辑
摘要:上一篇文章中,返回json格式的中文显示成\u5723\u8bde\u8282\u5343\u4e07\u597d\u793c\u5927\u5949\u9001解决方法:另外从网上搜索到的其他方法这是从网上搜索得到的又一篇相关文章当使用php自带的json_encode对数据进行编码时,中文都会变成unicode,导致不可读。如:对字符串”厦门“进行json_encode后,输出的是"\u53a6\u95e8"。查询了一下,有两种方法:1.将"\u53a6\u95e8"还原成“厦门”,使用如下的代码:$str= preg_replace("# 阅读全文
posted @ 2012-09-10 10:59 神马和浮云 阅读(28002) 评论(1) 推荐(0) 编辑
摘要:include/conn.php为数据库链接文件,不会的网上搜索<?php include './include/conn.php'; //数据库链接文件$sql_notice = mysql_query('SELECT * FROM gg_notice where enable = "1" limit 0,10');$notice = mysql_fetch_array($sql_notice, MYSQL_ASSOC);print_r ($notice);?><!DOCTYPE html PUBLIC "-// 阅读全文
posted @ 2012-09-07 10:05 神马和浮云 阅读(70091) 评论(0) 推荐(0) 编辑
摘要:<?php$name = 'Today 3? , very/ cold';$name = strtolower($name);//$name = preg_replace('/[^a-z0-9\s]/','',$name);$name = preg_replace('/[\.\s+\?,\/"]/','_',$name); //change spacesecho $name;?>其中$name = preg_replace('/[\.\s+\?,\/"]/',' 阅读全文
posted @ 2012-09-06 11:55 神马和浮云 阅读(2643) 评论(0) 推荐(0) 编辑
摘要:一次性读取csv文件内所有行的数据<?php $file = fopen('windows_2011_s.csv','r'); while ($data = fgetcsv($file)) { //每次读取CSV里面的一行内容//print_r($data); //此为一个数组,要获得每一个数据,访问数组下标即可$goods_list[] = $data; }//print_r($goods_list);/* foreach ($goods_list as $arr){ if ($arr[0]!=""){ echo $arr[0].&q 阅读全文
posted @ 2012-09-06 10:09 神马和浮云 阅读(43788) 评论(0) 推荐(1) 编辑
摘要:function mkdirs($dir, $mode = 0777){ if (is_dir($dir) || @mkdir($dir, $mode)) return TRUE; if (!mkdirs(dirname($dir), $mode)) return FALSE; return @mkdir($dir, $mode);}mkdirs("aa01");默认的 mode 是 0777,意味着最大可能的访问权。有关 mode 的更多信息请阅读 chmod() 页面。 阅读全文
posted @ 2012-09-05 17:17 神马和浮云 阅读(814) 评论(0) 推荐(0) 编辑
摘要:PHP文件:1.php<?phpheader('Content-type: text/html; charset=utf8');$title = "这个是标题吗??变量名title";$file = "这是什么?这个变量名为file";$fp = fopen ("templets/temp.html","r");$content = fread ($fp,filesize ("templets/temp.html"));$content = str_replace (&qu 阅读全文
posted @ 2012-07-02 09:20 神马和浮云 阅读(302) 评论(0) 推荐(0) 编辑
摘要:PHP文件名:dome.php <?php $string = 1; ob_start(); @readfile("templets/list.html"); $text = ob_get_flush(); $myfile = fopen("list.html","w"); $text = str_replace ("{counent}",$string,$text); fwrite($myfile,$text); ob_clean(); ?>模板文件名:templets/list.html<!D 阅读全文
posted @ 2012-07-02 09:18 神马和浮云 阅读(550) 评论(0) 推荐(0) 编辑
摘要:文件名:login.php<?phpinclude("conn.php"); if($_GET[out]){ setcookie("cookie", "out"); echo "<script language=\"javascript\">location.href='login.php';</script>"; } if($_POST[id]=='admin'){ $pw=md5($_POST[pw]); if($pw==' 阅读全文
posted @ 2012-06-30 17:21 神马和浮云 阅读(944) 评论(0) 推荐(0) 编辑
摘要:文件名:list.php说明:mysql_fetch_array()mysql_fetch_array(data,array_type)函数从结果集中取得一行作为关联数组,或数字数组,或二者兼有返回根据从结果集取得的行生成的数组,如果没有更多行则返回 false。data 可选。规定规定要使用的数据指针。该数据指针是 mysql_query() 函数产生的结果。array_type 可选。规定返回哪种结果。可能的值:MYSQL_ASSOC - 关联数组;MYSQL_NUM - 数字数组;MYSQL_BOTH - 默认。同时产生关联和数字数组<?php include("conn 阅读全文
posted @ 2012-06-30 17:19 神马和浮云 阅读(1071) 评论(0) 推荐(0) 编辑
摘要:文件名:add.php<?php include("conn.php"); if($_POST['submit']){ $sql="insert into message (id,user,title,content,lastdate) " . "values ('','$_POST[user]','$_POST[title]','$_POST[content]',now())"; mysql_query($sql); echo "< 阅读全文
posted @ 2012-06-30 17:10 神马和浮云 阅读(2237) 评论(0) 推荐(0) 编辑
摘要:设置php的编码,可在php文件标识符的下面添加@header('Content-type: text/html; charset=UTF-8'); 阅读全文
posted @ 2012-06-30 10:47 神马和浮云 阅读(1597) 评论(0) 推荐(0) 编辑
摘要:PHP5的方法 文件名为:conn.php 查询数据库使用以下方法测试 阅读全文
posted @ 2012-06-30 10:38 神马和浮云 阅读(1884) 评论(1) 推荐(0) 编辑
摘要:留言条数的id,类型为整形,并且为主键留言者的名字,也就是用户名,类型为字符型,长度10,可根据需求自行设置留言的标题,类型为字符型,长度50,可根据需求自行设置留言内容,类型为文本留言时间,类型为时间型MYSQL代码:CREATE TABLE `message` (`id` int NOT NULL ,`user` char(10) NOT NULL ,`title` varchar(50) NOT NULL ,`content` text NOT NULL ,`lastdate` time NOT NULL ,PRIMARY KEY (`id`));数据库字段可根据需求自行配置 阅读全文
posted @ 2012-06-30 10:25 神马和浮云 阅读(1340) 评论(0) 推荐(0) 编辑
摘要:<?phpinclude_once 'common.php';include 'conn.php';$sql_add="insert into `message` (`id`,`user`,`title`,`content`,`lastdate`) values ('','$_POST[user]','$_POST[title]','$_POST[content]',now())";if ($_POST[submit]){ mysql_query($sql_add); if 阅读全文
posted @ 2012-06-29 17:48 神马和浮云 阅读(1263) 评论(1) 推荐(0) 编辑
摘要:双选确认框,点击是跳转到yes.html,点击否跳转到no.html<?phpecho "<script> if(confirm( '请选择跳转页面,是跳转到yes.html 否跳转到no.html? ')) location.href='yes.html';else location.href='no.html'; </script>"; ?>双选确认框,选择后继续弹出确认对话框<?phpecho "<script> var sure=confirm( ' 阅读全文
posted @ 2012-06-29 17:45 神马和浮云 阅读(16970) 评论(0) 推荐(1) 编辑
摘要:假设在127.0.0.1上有test1和test2两个库, 其中库test1库中有test1表,test2中有test2表$servername = "127.0.0.1";$username = "root";$password = "root";$conn1 = mysql_connect($servername, $username, $password);mysql_select_db('test1', $conn1);$conn2 = mysql_connect($servername, $username, 阅读全文
posted @ 2012-06-29 12:02 神马和浮云 阅读(2120) 评论(0) 推荐(0) 编辑
摘要:$val1=<?php$arr1['laruence'] = 'huixinchen';$arr1['yahoo'] = 2007;$arr1['baidu'] = 2008;foreach ($arr1 as $key => $val1) { echo $val1;//结果是什么?}?><br>$val2=<?php$arr2[2] = 'huixinchen';$arr2[1] = 2007;$arr2[0] = 2008;foreach ($arr2 as $key =&g 阅读全文
posted @ 2012-06-28 17:40 神马和浮云 阅读(6363) 评论(0) 推荐(0) 编辑
摘要:之前如果要在某个数组中删除一个元素,我是直接用的unset,也不管unset之后会发生什么。但今天看到的东西却让我大吃一惊 print_r($arr)之后,结果却不是那样的,最终结果是 Array ( [0] => a [2] => c [3] => d ) 那么怎么才能做到缺少的元素会被填补并且数 阅读全文
posted @ 2012-06-28 13:26 神马和浮云 阅读(1048) 评论(1) 推荐(0) 编辑
摘要:PHP页面编码问题导致页面乱码,PHP页面编码问题如何设置以及编码设置方法本文都一一介绍。 MySQL数据库编码、html页面编码、PHP或html文件本身编码要全部一致。 1、MySQL数据库编码设置;2、html页面的编码,指的是这一行的设置;3、PHP或html文件本身的编码;4、Javascript或Flash中传递的数据是utf-8编码;5、在PHP程序中,可以加上一行,来指定PHP源程序的编码 阅读全文
posted @ 2012-06-28 11:53 神马和浮云 阅读(26803) 评论(1) 推荐(2) 编辑