当前位置: 编程技术>php
本页文章导读:
▪解决FastCGI 进程超过了配置的活动超时时限的问题
近日,需要满足测试需求,进行大数据并发测试时,报出【HTTP 错误 500.0 - Internal Server Error E:\PHP\php-cgi.exe - FastCGI 进程超过了配置的活动超时时限】
解决办法:
IIS7->FastCGI设置->双击"php-c.........
▪解析在PHP中使用mysqli扩展库对mysql的操作
1、在PHP中 使用mysqli扩展库对mysql 的dql操作 代码如下:<?php header("Content-type: text/html;charset=utf-8"); //mysqli操作mysql数据库(面向对象方式) //1、创建MySQLi对象 $mysqli =new MySQLi("loc.........
▪PHP 文件编程综合案例-文件上传的实现
PHP文件上传1、upload.php 代码如下:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <title>ddd</title> <meta http-equiv="content-type" content="text/html; charset=UTF.........
[1]解决FastCGI 进程超过了配置的活动超时时限的问题
来源: 互联网 发布时间: 2013-11-30
近日,需要满足测试需求,进行大数据并发测试时,报出【HTTP 错误 500.0 - Internal Server Error E:\PHP\php-cgi.exe - FastCGI 进程超过了配置的活动超时时限】
解决办法:
IIS7->FastCGI设置->双击"php-cgi.exe"->"活动超时" 项默认是设置为70(秒),改为600(10分钟,此处根据需求设置可以略高~)
[2]解析在PHP中使用mysqli扩展库对mysql的操作
来源: 互联网 发布时间: 2013-11-30
1、在PHP中 使用mysqli扩展库对mysql 的dql操作
<?php
header("Content-type: text/html;charset=utf-8");
//mysqli操作mysql数据库(面向对象方式)
//1、创建MySQLi对象
$mysqli =new MySQLi("localhost","root","root","test");
if($mysqli->connect_error){
die("连接失败".$mysqli->connect_error);
}
//2、操作数据库(发送sql)
$sql="select *from user1";
//3、处理结果
$res =$mysqli->query($sql);
//var_dump($res);
//fetch_assoc \fetch_array \fetch_object
while($row=$res->fetch_row()){
var_dump($row);
/* foreach($row as $val){
echo '--'.$val;
}
echo '<br/>';*/
}
//4、关闭资源
$res->free();
$mysqli->close();
?>
下面是面向过程的
<?php
header("Content-type: text/html;charset=utf-8");
$mysqli=mysqli_connect("localhost","root","root","test");
if(!$mysqli){
die("连接失败".mysqli_connect_error());
}
$sql="select *from user1";
$res=mysqli_query($mysqli,$sql);
//var_dump($res);
while($row=mysqli_fetch_row($res)){
foreach ($row as $val){
echo '-'.$val;
}
echo '<br/>';
}
//释放内存
mysqli_free_result($res);
mysqli_close($mysqli);
?>
2、在PHP中 使用mysqli扩展库对mysql 的dml操作
<?php
//使用mysqli 扩展库对mysql的crud 操作
header("Content-type: text/html;charset=utf-8");
$mysqli = new MySQLi("localhost","root","root","test");
if($mysqli->connect_error){
die("连接失败".$mysql->connect_error);
}
//增加一条记录
//$sql="insert into user1 (name,password,email,age) values ('lucy',md5('lucy'),'lucy@163.com',17)";
//删除一条记录
//$sql="delete from user1 where id =80";
//更新一条记录
$sql="update user1 set age=20 where id=7";
$res=$mysqli->query($sql);
if(!$res){
echo "操作失败".$mysqli->error;
}else{
if($mysqli->affected_rows>0){
echo "成功";
}else{
echo "没有行受影响";
}
}
//关闭资源
$mysqli->close();
?>
3、进行封装
<?
class SqlHelper{
private $mysqli;
//这里先写死,以后写死的东西用一个文件来配置
private static $host="localhost";
private static $user="root";
private static $pwd="root";
private static $db="test";
public function __construct(){
$this->mysqli=new MySQLi(self::$host,self::$user,self::$pwd,self::$db);
if($this->mysqli->connect_error){
die("连接失败".$this->mysqli->connect_error);
}
//设置字符集
$this->mysqli->query("set names utf8");
}
//dql operate
function execute_dql($sql){
$res =$this->mysqli->query($sql) or die($this->mysqli->error);
return $res;
}
//dml operate
function execute_dml($sql){
$res =$this->mysqli->query($sql) or die($this->mysqli->error);
if(!$res){
return 0;//失败
}else{
if($this->mysqli->affected_rows>0){
return 1;//成功
}else{
return 2;//没有行到影响
}
}
}
}
?>
代码如下:
<?php
header("Content-type: text/html;charset=utf-8");
//mysqli操作mysql数据库(面向对象方式)
//1、创建MySQLi对象
$mysqli =new MySQLi("localhost","root","root","test");
if($mysqli->connect_error){
die("连接失败".$mysqli->connect_error);
}
//2、操作数据库(发送sql)
$sql="select *from user1";
//3、处理结果
$res =$mysqli->query($sql);
//var_dump($res);
//fetch_assoc \fetch_array \fetch_object
while($row=$res->fetch_row()){
var_dump($row);
/* foreach($row as $val){
echo '--'.$val;
}
echo '<br/>';*/
}
//4、关闭资源
$res->free();
$mysqli->close();
?>
下面是面向过程的
代码如下:
<?php
header("Content-type: text/html;charset=utf-8");
$mysqli=mysqli_connect("localhost","root","root","test");
if(!$mysqli){
die("连接失败".mysqli_connect_error());
}
$sql="select *from user1";
$res=mysqli_query($mysqli,$sql);
//var_dump($res);
while($row=mysqli_fetch_row($res)){
foreach ($row as $val){
echo '-'.$val;
}
echo '<br/>';
}
//释放内存
mysqli_free_result($res);
mysqli_close($mysqli);
?>
2、在PHP中 使用mysqli扩展库对mysql 的dml操作
代码如下:
<?php
//使用mysqli 扩展库对mysql的crud 操作
header("Content-type: text/html;charset=utf-8");
$mysqli = new MySQLi("localhost","root","root","test");
if($mysqli->connect_error){
die("连接失败".$mysql->connect_error);
}
//增加一条记录
//$sql="insert into user1 (name,password,email,age) values ('lucy',md5('lucy'),'lucy@163.com',17)";
//删除一条记录
//$sql="delete from user1 where id =80";
//更新一条记录
$sql="update user1 set age=20 where id=7";
$res=$mysqli->query($sql);
if(!$res){
echo "操作失败".$mysqli->error;
}else{
if($mysqli->affected_rows>0){
echo "成功";
}else{
echo "没有行受影响";
}
}
//关闭资源
$mysqli->close();
?>
3、进行封装
代码如下:
<?
class SqlHelper{
private $mysqli;
//这里先写死,以后写死的东西用一个文件来配置
private static $host="localhost";
private static $user="root";
private static $pwd="root";
private static $db="test";
public function __construct(){
$this->mysqli=new MySQLi(self::$host,self::$user,self::$pwd,self::$db);
if($this->mysqli->connect_error){
die("连接失败".$this->mysqli->connect_error);
}
//设置字符集
$this->mysqli->query("set names utf8");
}
//dql operate
function execute_dql($sql){
$res =$this->mysqli->query($sql) or die($this->mysqli->error);
return $res;
}
//dml operate
function execute_dml($sql){
$res =$this->mysqli->query($sql) or die($this->mysqli->error);
if(!$res){
return 0;//失败
}else{
if($this->mysqli->affected_rows>0){
return 1;//成功
}else{
return 2;//没有行到影响
}
}
}
}
?>
[3]PHP 文件编程综合案例-文件上传的实现
来源: 互联网 发布时间: 2013-11-30
PHP文件上传
1、upload.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>ddd</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<!--文件上传要注意:1、要有enctyp,2、method="post"-->
<form enctype="multipart/form-data" action="/blog_article/uploadProcess.html" method="post" >
<table>
<tr><td>请填写用户名</td><td><input type="text" name="username"></td></tr>
<tr><td>请简单介绍文件</td><td><textarea rows="7" cols="50" name="fileintro" ></textarea></td></tr>
<tr><td>请上传你的文件</td><td><input type="file" name="myfile"></td></tr>
<tr><td colspan="2"><input type="submit" value="上传"><td></tr>
</table>
</form>
</body>
</html>
2、uploadProcess.php
<?php
//接收
$username=$_POST['username'];
$fileintro=$_POST['fileintro'];
//echo $username.$fileintro;
//获取文件信息
/* echo "<pre>";
print_r($_FILES);
echo "</pre>";
*/
//获取文件的大小
$file_size=$_FILES['myfile']['size'];
if($file_size>2*1024*1024){
echo "<script type='text/javascript'>window.alert('文件不能大于2M')</script>";
exit();
}
//获取文件类型
$file_type=$_FILES['myfile']['type'];
if($file_type!="image/jpeg" && $file_type!="image/pjpeg"){
echo "文件类型只能是 jpg 格式";
exit();
}
//判断上传是否OK
if(is_uploaded_file($_FILES['myfile']['tmp_name'])){
//得到上传的文件 转存到你希望的目录
$upload_file=$_FILES['myfile']['tmp_name'];
//防止图片覆盖问题,为每个用户建立一个文件夹
$user_path=$_SERVER['DOCUMENT_ROOT']."/file/up/".$username;
if(!file_exists($user_path)){
mkdir ($user_path);
}
//$move_to_file=$user_path."/".$_FILES['myfile']['name'];
//防止用户上传用户名相同的问题
$file_true_name=$_FILES['myfile']['name'];
$move_to_file=$user_path."/".time().rand(1,1000).substr($file_true_name,strripos($file_true_name,"."));
//echo $upload_file.$move_to_file;
//中文要转码
if(move_uploaded_file($upload_file,iconv("utf-8","gb2312","$move_to_file"))){
echo $_FILES['myfile']['name']."上传成功";
}else{
echo "上传失败";
}
}else{
echo "上传失败";
}
?>
3、封装:
<?php
class Upload{
public $upload_name; //上传文件名
public $upload_tmp_path; //上传文件保存到服务器的temp路径
public $file_size;
public $file_type;
public $file_save_path;
function __construct(){
$this->upload_name=$_FILES['myfile']['name'];
$this->upload_tmp_path=$_FILES['myfile']['tmp_name'];
$this->file_size=$_FILES['myfile']['size'];
$this->file_type=$_FILES['myfile']['type'];
$this->allow_file_type = array('jpeg','jpg','png','gif','bmp','doc','zip','rar','txt','wps','xlsx','ppt');
$this->file_save_path=$_SERVER['DOCUMENT_ROOT']."/file/up/";
}
public function upload_file($username){
//判断文件大小
if($this->file_size>2*1024*1024){
echo "<script type='text/javascript'>window.alert('文件不能大于2M')</script>";
exit();
}
//获取文件类型
/* if($this->file_type!="image/jpeg" && $this->file_type!="image/pjpeg"){
echo "文件类型只能是 jpg 格式";
exit();
}
*/ //获取文件的扩展名
$file_type=$this->getFileExt($this->upload_name);
if(!in_array($file_type,$this->allow_file_type)){
echo "上传文件类型格式错误";
exit();
}
//判断上传是否OK
if(is_uploaded_file($this->upload_tmp_path)){
//防止图片覆盖问题,为每个用户建立一个文件夹
$user_path=$this->file_save_path.$username;
if(!file_exists($user_path)){
mkdir ($user_path);
}
//$move_to_file=$user_path."/".$_FILES['myfile']['name'];
//防止用户上传用户名相同的问题
//$file_true_name=$_FILES['myfile']['name'];
$move_to_file=$user_path."/".time().rand(1,1000).substr($this->upload_name,strripos($this->upload_name,"."));
//echo $upload_file.$move_to_file;
//中文要转码
if(move_uploaded_file($this->upload_tmp_path,iconv("utf-8","gb2312","$move_to_file"))){
echo $this->upload_name."上传成功";
}else{
echo "上传失败";
}
}else{
echo "上传失败";
}
}
//获取文件的扩展名
public function getFileExt($filename){
$fileExt=pathinfo($filename);
return $fileExt["extension"];
}
}
?>
1、upload.php
代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>ddd</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<!--文件上传要注意:1、要有enctyp,2、method="post"-->
<form enctype="multipart/form-data" action="/blog_article/uploadProcess.html" method="post" >
<table>
<tr><td>请填写用户名</td><td><input type="text" name="username"></td></tr>
<tr><td>请简单介绍文件</td><td><textarea rows="7" cols="50" name="fileintro" ></textarea></td></tr>
<tr><td>请上传你的文件</td><td><input type="file" name="myfile"></td></tr>
<tr><td colspan="2"><input type="submit" value="上传"><td></tr>
</table>
</form>
</body>
</html>
2、uploadProcess.php
代码如下:
<?php
//接收
$username=$_POST['username'];
$fileintro=$_POST['fileintro'];
//echo $username.$fileintro;
//获取文件信息
/* echo "<pre>";
print_r($_FILES);
echo "</pre>";
*/
//获取文件的大小
$file_size=$_FILES['myfile']['size'];
if($file_size>2*1024*1024){
echo "<script type='text/javascript'>window.alert('文件不能大于2M')</script>";
exit();
}
//获取文件类型
$file_type=$_FILES['myfile']['type'];
if($file_type!="image/jpeg" && $file_type!="image/pjpeg"){
echo "文件类型只能是 jpg 格式";
exit();
}
//判断上传是否OK
if(is_uploaded_file($_FILES['myfile']['tmp_name'])){
//得到上传的文件 转存到你希望的目录
$upload_file=$_FILES['myfile']['tmp_name'];
//防止图片覆盖问题,为每个用户建立一个文件夹
$user_path=$_SERVER['DOCUMENT_ROOT']."/file/up/".$username;
if(!file_exists($user_path)){
mkdir ($user_path);
}
//$move_to_file=$user_path."/".$_FILES['myfile']['name'];
//防止用户上传用户名相同的问题
$file_true_name=$_FILES['myfile']['name'];
$move_to_file=$user_path."/".time().rand(1,1000).substr($file_true_name,strripos($file_true_name,"."));
//echo $upload_file.$move_to_file;
//中文要转码
if(move_uploaded_file($upload_file,iconv("utf-8","gb2312","$move_to_file"))){
echo $_FILES['myfile']['name']."上传成功";
}else{
echo "上传失败";
}
}else{
echo "上传失败";
}
?>
3、封装:
代码如下:
<?php
class Upload{
public $upload_name; //上传文件名
public $upload_tmp_path; //上传文件保存到服务器的temp路径
public $file_size;
public $file_type;
public $file_save_path;
function __construct(){
$this->upload_name=$_FILES['myfile']['name'];
$this->upload_tmp_path=$_FILES['myfile']['tmp_name'];
$this->file_size=$_FILES['myfile']['size'];
$this->file_type=$_FILES['myfile']['type'];
$this->allow_file_type = array('jpeg','jpg','png','gif','bmp','doc','zip','rar','txt','wps','xlsx','ppt');
$this->file_save_path=$_SERVER['DOCUMENT_ROOT']."/file/up/";
}
public function upload_file($username){
//判断文件大小
if($this->file_size>2*1024*1024){
echo "<script type='text/javascript'>window.alert('文件不能大于2M')</script>";
exit();
}
//获取文件类型
/* if($this->file_type!="image/jpeg" && $this->file_type!="image/pjpeg"){
echo "文件类型只能是 jpg 格式";
exit();
}
*/ //获取文件的扩展名
$file_type=$this->getFileExt($this->upload_name);
if(!in_array($file_type,$this->allow_file_type)){
echo "上传文件类型格式错误";
exit();
}
//判断上传是否OK
if(is_uploaded_file($this->upload_tmp_path)){
//防止图片覆盖问题,为每个用户建立一个文件夹
$user_path=$this->file_save_path.$username;
if(!file_exists($user_path)){
mkdir ($user_path);
}
//$move_to_file=$user_path."/".$_FILES['myfile']['name'];
//防止用户上传用户名相同的问题
//$file_true_name=$_FILES['myfile']['name'];
$move_to_file=$user_path."/".time().rand(1,1000).substr($this->upload_name,strripos($this->upload_name,"."));
//echo $upload_file.$move_to_file;
//中文要转码
if(move_uploaded_file($this->upload_tmp_path,iconv("utf-8","gb2312","$move_to_file"))){
echo $this->upload_name."上传成功";
}else{
echo "上传失败";
}
}else{
echo "上传失败";
}
}
//获取文件的扩展名
public function getFileExt($filename){
$fileExt=pathinfo($filename);
return $fileExt["extension"];
}
}
?>
最新技术文章: