php总结《2》.docx

上传人:b****4 文档编号:4284206 上传时间:2023-05-06 格式:DOCX 页数:15 大小:20.72KB
下载 相关 举报
php总结《2》.docx_第1页
第1页 / 共15页
php总结《2》.docx_第2页
第2页 / 共15页
php总结《2》.docx_第3页
第3页 / 共15页
php总结《2》.docx_第4页
第4页 / 共15页
php总结《2》.docx_第5页
第5页 / 共15页
php总结《2》.docx_第6页
第6页 / 共15页
php总结《2》.docx_第7页
第7页 / 共15页
php总结《2》.docx_第8页
第8页 / 共15页
php总结《2》.docx_第9页
第9页 / 共15页
php总结《2》.docx_第10页
第10页 / 共15页
php总结《2》.docx_第11页
第11页 / 共15页
php总结《2》.docx_第12页
第12页 / 共15页
php总结《2》.docx_第13页
第13页 / 共15页
php总结《2》.docx_第14页
第14页 / 共15页
php总结《2》.docx_第15页
第15页 / 共15页
亲,该文档总共15页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

php总结《2》.docx

《php总结《2》.docx》由会员分享,可在线阅读,更多相关《php总结《2》.docx(15页珍藏版)》请在冰点文库上搜索。

php总结《2》.docx

php总结《2》

php总结《2》

2010-08-1711:

32:

27|  分类:

php|  标签:

|字号大中小 订阅

文件处理

   文件属性

      file_exists('1.php')文件或目录是否存在

      filesize()取得文件大小

      is_readable()判断给定文件名是否可读

      is_writable()判断给定文件名是否可写

      is_executable()判断给定文件名是否可执行

      filectime()获取文件的创造时间

      filemtime()获取文件的修改时间

      fileatime()获取文件的访问时间

      stat()获取文件大部分属性值

   解析目录

      basename()返回路径中的文件名部分

      dirname()返回目录

      pathinfo()返回目录名、基本名和扩展名的关联数组

   遍历目录

      opendir()打开指定目录

      readdir()关闭指定目录

      closedir()关闭指定目录

      rewinddir()倒回目录句柄

         $dir_handle=opendir('.');

         while($file=readdir($dir_handle))

         {

            echofilesize($file).'___'.$file.'
';

         }

         closedir($dir_handle);

   建立和删除目录

      mkdir()创建目录

      rmdir()删除空目录

      unlink()将目录中的每个文件都删除掉

   文件操作

      fopen()

      fclose()

      fwrite()写入文件

      fputs()fwrite的别名

      file_put_contents($文件名,$内容)把内容存成文件

      file_get_contents()从文件读出内容

   文件读取

      fread()

      fgets()从文件指针中读取一行

      fgetc()从文件指针中读取字符

      file()

      readfile()读入一个文件并写入到输出缓冲

      ftell()返回文件指针的当前位置

      fseek()移动文件指针到指定的位置

      rewind()移动文件指针到文件的开头

      flock()文件锁定

      copy()复制文件

      unlink()删除文件

      ftruncate()将文件截断到指定的长度

      rename()重命名文件或目录

   保存读取文件

      -----------把内容存成文件

      $cache_file=fopen('f:

\1.txt','w+');

      fwrite($cache_file,$t);

      -----------把内容存成文件

      $s="内容";

      file_put_contents('f:

/2.txt',$s);

      -----------把文件内容读成字符串

      $s=file_get_contents('f:

/2.txt');

      echo$s;

      -----------把文件内容按行读成字符串

      $handle=@fopen("f:

/2.txt","r");

      if($handle)

      {

         while(!

feof($handle))

         {

            $buffer=fgets($handle,4096);

            echo$buffer.'
';

         }

         fclose($handle);

      }

      ----------

session/cookie

   setcookie("MyCookie[foo]",'Testing1',time()+3600)

   session_start()

   ini_set('session.cookie_lifetime',0);session对应cookie存活时间

   ini_set('session.save_path','dir');

   ini_set('session.save_path','2;session');session分两级存放

   ini_set('session.name','SNS');

   客户端禁用Cookie

      session.use_trans_sid=1开启url传递sessionIdphp.ini

mysql

   $link=mysql_connect('localhost','root','root')ordie(mysql_errno());

   mysql_select_db('test')ordie(mysql_errno());

   mysql_query('SETNAMESgbk');

   $sql="SELECT*FROMtestLIMIT0,20";

   $result=mysql_query($sql)ordie(mysql_errno());

   while($msg=mysql_fetch_array($result)){

      print_r($msg);

   }

   mysql_free_result($result);

   mysql_close($link);

mysqli

   查询

      -------------------------------过程

      $db_host="localhost";  //连接的服务器地址

      $db_user="root";   //连接数据库的用户名

      $db_psw="root";    //连接数据库的密码

      $db_name="test";//连接的数据库名称

      $mysqli=mysqli_connect($db_host,$db_user,$db_psw,$db_name);

      mysqli_query($mysqli,'SETNAMESutf8');

      $query="select*fromusers";

      $result=mysqli_query($mysqli,$query);

      while($row=mysqli_fetch_array($result))//循环输出结果集中的记录

      {

         echo($row['id'])."
";

         echo($row['username'])."
";

         echo($row['password'])."
";

         echo"


";

      }

      mysqli_free_result($result);

      mysqli_close($mysqli);

      -------------------------------对象

      $db_host="localhost";  //连接的服务器地址

      $db_user="root";   //连接数据库的用户名

      $db_psw="root";    //连接数据库的密码

      $db_name="test";//连接的数据库名称

      $mysqli=newmysqli($db_host,$db_user,$db_psw,$db_name);

      $mysqli->query('SETNAMESutf8');

      $query="select*fromusers";

      $result=$mysqli->query($query);

      if($result)

      {

         if($result->num_rows>0)//判断结果集中行的数目是否大于0

         {

            while($row=$result->fetch_array())//循环输出结果集中的记录

            {

               echo($row[0])."
";

               echo($row[1])."
";

               echo($row[2])."
";

               echo"


";

            }

         }

      }

      else

      {

         echo"查询失败";

      }

      $result->free();

      $mysqli->close();

   增、删、改

      $mysqli=newmysqli("localhost","root","root","sunyang");//实例化mysqli

      $query="deletefromemployeewhereemp_id=2";

      $result=$mysqli->query($query);

      if($result){

         echo"删除操作执行成功";

      }else{

         echo"删除操作执行失败";

      }

      $mysqli->close();

   绑定结果

      $mysqli=newmysqli("localhost","root","root","test");     //实例化mysqli

      $query="select*fromusers";

      $result=$mysqli->prepare($query);                //进行预准备语句查询

      $result->execute();                          //执行预准备语句

      $result->bind_result($id,$username,$password);        //绑定结果

      while($result->fetch()){

         echo$id.'_';

         echo$username.'_';

         echo$password;

         echo"
";

      }

      $result->close();                            //关闭预准备语句

      $mysqli->close();                            //关闭连接

   绑定参数

      $mysqli=newmysqli("localhost","root","root","test");         //实例化mysqli

      $query="insertintousers(id,username,password)  values('',?

?

)";

      $result=$mysqli->prepare($query);

      $result->bind_param("ss",$username,$password);           //绑定参数I:

integerD:

doubleS:

stringB:

blob

      $username='sy0807';

      $password='employee7';

      $result->execute();                              //执行预准备语句

      $result->close();

      $mysqli->close();

   绑定参数、绑定结果

      $mysqli=newmysqli("localhost","root","root","test");     //实例化mysqli

      $query="select*fromuserswhereid

";

      $result=$mysqli->prepare($query);

      $result->bind_param("i",$id);                //绑定参数

      $id=10;

      $result->execute();

      $result->bind_result($id,$username,$password);        //绑定结果

      while($result->fetch()){

         echo$id."_";

         echo$username."_";

         echo$password;

         echo"
";

      }

      $result->close();

      $mysqli->close();

   多条查询语句

      $mysqli=newmysqli("localhost","root","root","test");         //实例化mysqli

      $query="selectidfromusers;";

      $query.="selectidfromtest";

      if($mysqli->multi_query($query)){                  //执行多个查询

         do{

            if($result=$mysqli->store_result()){

               while($row=$result->fetch_row()){

                  echo$row[0];

                  echo"
";

               }

               $result->close();

            }

            if($mysqli->more_results()){

               echo("-----------------
");                      //连个查询之间的分割线

            }

         }while($mysqli->next_result());

      }

      $mysqli->close();//关闭连接

pdo

   查询

      $db=newPDO('mysql:

host=localhost;dbname=test','root','root');

      $sql="SELECT*FROMusers";

      $result=$db->query($sql);

      foreach($resultas$row)

      {

         var_dump($row);

      }

      $db=null;

   增、删、改、事务开启

      try

      {

         $db=newPDO('mysql:

host=localhost;dbname=test','root','root');

         $db->beginTransaction();

         $a=$db->exec("insertintousers(id,username,password)values('','Joe','Bloggs')");

         if($a==false)

         {

            thrownewException("sql1执行失败");

         }

         $b=$db->exec("insertintousers(id,username,password,kkk)values('','Joe','Bloggs')");

         if($b==false)

         {

            thrownewException("sql2执行失败");

         }

         $db->commit();

         $db=null;

      }

      catch(Exception$ex)

      {

         echo$ex;

         $db->rollback();

      }

缓存

   Memcache

      .下载memcached,;2.解压,比如放在D:

\memcached-1.2.1;3.DOS下输入‘D:

\memcached-1.2.1\memcached.exe-dinstall’,进行安装(注意‘’不要输入);4.再次输入‘D:

\memcached-1.2.1\memcached.exe-dstart’启动memcached。

  注意:

memcached以后会随机启动。

这样memcached就已经安装完毕了。

apache-conf-httph。

conf下面的LoadModulemem_cache_modulemodules/mod_mem_cache.so之前的#去掉

在php下面的php。

ini下面添加extension=php_memcache.dll

php下的ext下面复制php_memcache.dll文件

      $memcache=newMemcache;

      $memcache->addServer('172.19.5.199',11211);

      $memcache->addServer('172.19.5.13',11211);

      //$memcache->connect('localhost',11211)ordie("Couldnotconnect");

      //$version=$memcache->getVersion();

      //echo"Server'sversion:

".$version;

      $memcache->set('key3',array(1,2,3));

      var_dump($memcache->get('key3'));

   ob

      ob_start()

      $content=ob_get_contents();

      ob_clean();

      $cache_file=fopen('f:

\1.html','w+');

      fwrite($cache_file,$content);

      页面静态化--------------------------------------

      ob_start();

      $static_file='1.html';//静态页面

      $php_file=basename(__FILE__);//当前动态页面

      if(!

file_exists($static_file)||

         ((filemtime($static_file)+10)

         filemtime($php_file)>filemtime($static_file))//源文件已修改

      {

         echo'静态页面示例';

         echo'erer';

         $c=ob_get_contents();

         ob_clean();

         file_put_contents($static_file,$c);

      }

      $s=file_get_contents($static_file);

      echo$s;

   

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2