php在mysql中插入的问题!!!

admin 发表于 2011-03-04 21:08 浏览次数:

下面的代码执行后数据库中插入的是$name,而不是变量对应的值,什么情况呀?

PHP code
<?php $name =$_POST["name"]; $contest = $_POST["contest"]; $date=date("Y-m-d")." ".idate("H").":".idate("i").":".idate("s"); $mysql_server_name="localhost"; $mysql_username="zzz"; $mysql_password="zzz"; $mysql_database="zzz"; $conn=mysql_connect($mysql_server_name, $mysql_username,$mysql_password); mysql_select_db($mysql_database, $conn); mysql_query("SET NAMES 'GBK'"); $sql='INSERT INTO contest(time,name,contest) VALUES ( "$date","1234","1232")'; mysql_query($sql); mysql_close($conn); ?>

  若将其中$date换成任何一个字符串,比如123,那么插入的就是123,没问题!

分类: PHP | 评论数: 14 | 阅读全文

求一个ajax上传图片的代码

admin 发表于 2011-03-04 19:21 浏览次数:

求一个ajax上传图片的代码

分类: PHP | 评论数: 2 | 阅读全文

php怎么使用sql server的缓冲池?

admin 发表于 2011-03-04 17:41 浏览次数:

如何连接、如何设置、如何使用
大侠赐教,谢谢

分类: PHP | 评论数: 7 | 阅读全文

adodb_lite使用方法高手指教。

admin 发表于 2011-03-04 17:40 浏览次数:

简单的登录增删改 等等。不知道都有啥方法 新手请指教!

若有用adodb_lite做的源码更好。 先谢谢了!

分类: PHP | 评论数: 0 | 阅读全文

PHP文件操作(对ppt文件)

admin 发表于 2011-03-04 17:40 浏览次数:

最近看到PHP有对EXCEL文件的操作扩展,请问如果我想对PPT文件进行处理该怎么做啊?

或者应该从哪个方向入手去处理呢?希望高手指点一二!

分类: PHP | 评论数: 8 | 阅读全文

正则匹配问题~~~~

admin 发表于 2011-03-04 17:40 浏览次数:

AQ 6103-2007 焊工防护手套_3
DL/T 444-91 反击式水轮机气蚀损坏评定标准
DZT 0046-1993 钻石分级标准

请问如何用正则匹配前面的DZT 0046-1993这些啊,注意T和0之间有空格

分类: PHP | 评论数: 2 | 阅读全文

求助:Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename

admin 发表于 2011-03-04 17:40 浏览次数:

<?php
//check we have the appropriate variable data
//variables are button-text and color

$button_text=$_REQUEST['button_text'];
$color=$_REQUEST['color'];

if((empty($button_text)||empty($color))||(!($color==’red’
  ||$color==’blue’||$color==’green’)))
{
  echo ‘Could not create image-form not filled out correctly’;
  exit;
 }
 //create an image of the right background and check size
 $im=imagecreatefrompng($color.’-button.png’);
 if(!$im)
 {
  echo ‘Could not create image’;
  exit;
  }
 $width_image=imagesx($im);
 $height_image=imagesy($im);
 
 //our images need an 18 pixel margin in from the edage of the image
 $width_image_wo_margins=$width_image-(2*18);
 $height_image_wo_margins=$height-(2*18);
 //work our if the font size will fit and make itsmaller until it does
 //start our with the biggest size that will reasonably fit on our buttons
 $font_size=3;
 //you need to tell GD2 where fonts reside
 putenv(‘GDFONTFATH=C:\windows\fonts’);
 $fontname=’Arial’;
 
 do
 { 
  $font_size–;
  //find out the size of the text at that font size
  $bbox =imagettfbbox($font_size,0,$fontname,$button_text);
  
  $right_text=$bbox[2];//right co-ordinate
  $left_text=$bbox[0];
  $width_text=$right_text-$left_text; //how wide is it?
  $height_text=abs($bbox[7]-$bbox[1]);//how tall is it?
  }
  while($font_size>8&&($height_text>$height_image_wo_margins||
  $width_text>$width_image_wo_margins)
);
 
  if($height_text>$height_image_wo_margins||
  $width_text>$width_image_wo_margins)
  {
  //no readable font size will fit on button
  echo ‘Text given will not fit on button.<br/>’;
  }
  else
  {
  //we have found a font size that will fit
//now work out where to put it
$text_x=$width_image/2.0-$width_text/2/0;
$text_y=$height_image/2.0-$height_text/2.0;

if($left_text<0)
$text_x+=abs($left_text);
$above_line_text=abs($bbox[7]);
$text_y+=$above_line_text;

$text_y-=2;
$white=imagecolorallocate($im,255,255,255);
imagettftext($im,$font_size,0,$text_x,$text_y,$white,$fontname,
$button_text);
header(‘content-type:image/png’);
imagepng($im);
}
imagedestroy($im);
?>
 
 Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename in E:\AppServ\www\make_button.php on line 38

分类: PHP | 评论数: 3 | 阅读全文

win7下 xampp 环境配置虚拟目录有问题

admin 发表于 2011-03-04 17:40 浏览次数:
PHP code
<VirtualHost *:80> DocumentRoot "E:/www/dede" ServerName dede.com </VirtualHost> <VirtualHost *:80> DocumentRoot "E:/www/hello" ServerName hello.com </VirtualHost> ----------------------------------- <Directory "E:/www/dede"> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride None Order allow,deny Allow from all </Directory> <Directory "E:/www/hello"> AllowOverride None Order allow,deny Allow from all </Directory>

这是我的配置文件,现在 用 dede.com 和hello.com 访问的都是 dede 目录里面的文件,请问还有什么需要改动的?

分类: PHP | 评论数: 6 | 阅读全文

php定时任务

admin 发表于 2011-03-04 17:21 浏览次数:

虚拟主机。
每分钟检测是否有任务需要完成,有则执行,否则等待下一分钟。
困扰中,请教

分类: PHP | 评论数: 10 | 阅读全文

导出excle文件时自动取消迅雷

admin 发表于 2011-03-04 17:21 浏览次数:

我用php导出excle文件 是总是会弹出迅雷下载:

1、可以取消迅雷后 开始直接下载 excle文件…

2、如果使用迅雷下载 excle文件会 迅雷就会下载一个 index.php文件(不是想要的excle文件)

这个问题能不能解决…. 用迅雷下载让下载的文件变成 excle文件 或者是 直接取消迅雷下载

这是我第一次碰到这么牛X的问题

分类: PHP | 评论数: 3 | 阅读全文

PHP包含文件(require/include/require_once/include_once/__autoload/spl_autoload)分析总结

admin 发表于 2011-03-04 17:21 浏览次数:

author: selfimpr
blog: http://blog.csdn.net/lgg201
mail: lgg860911@yahoo.com.cn
本文博客地址: http://blog.csdn.net/lgg201/archive/2011/02/24/6204951.aspx

四种语法的差异
在PHP中,包含一个文件有4种方式:require,require_once,include,include_once.其中require_once/include_once与require/include相比,在功能上,仅仅是增加了一个是否已经加载过的检测,require_once/include_once在一次PHP执行过程中,保证一个文件只被加载一次.
require_once/include_once这样只加载一次的功能,通常是为了避免发生函数/类重定义等异常,或者多次包含同一文件导致的变量覆写.
在说明了_once版本和没有_once的版本之间的区别后,我们同样需要知道require和include之间的区别.下面是php手册对require的解释:
require() is identical to include() except upon failure it will also produce a fatal E_ERROR level error. In other words, it will halt the script whereas include() only emits a warning (E_WARNING) which allows the script to continue.
可以看出,require和include之间的区别仅在于发生错误时(比如被包含文件查找不到),require引发一个E_ERROR级别的错误,而include引发一个E_WARNING级别的错误.(E_ERROR级别的错误会中断脚本执行)
require_once和include_once之间的区别也就不言而喻了.

一个需要注意的点
require/require_once/include/include_once都是语法结构,不是函数,可以通过function_exists验证

性能问题
require/require_once的性能问题,在http://blog.csdn.net/lgg201/archive/2011/02/14/6184745.aspx中已经做了比较详细的阐述,这里仅仅列举一个用以发现性能问题的示例:
main.php

PHP code
<?php /** * author: selfimpr * blog: http://blog.csdn.net/lgg201 * mail: lgg860911@yahoo.com.cn * require/require_once性能测试 */ /** * 测试require * @param unknown_type $filename */ function test_require($filename) { isset($GLOBALS[$filename]) or (($GLOBALS[$filename] = 1) and require $filename); } /** * 测试require_once * @param unknown_type $filename */ function test_require_once($filename) { require_once($filename); } /** * cpu时间缓存 */ $cpu_time_tmp = array(); /** * 记录开始cpu时间 */ function cputime_start() { global $cpu_time_tmp; $rusage = getrusage(); $cpu_time_tmp[] = $rusage['ru_utime.tv_sec'] + $rusage['ru_utime.tv_usec'] / 1000000; $cpu_time_tmp[] = $rusage['ru_stime.tv_sec'] + $rusage['ru_stime.tv_usec'] / 1000000; } /** * 输出运行cpu消耗 */ function cputime_end() { global $cpu_time_tmp; $rusage = getrusage(); printf("user_cpu: %.8f, system_cpu: %.8f<br />\n", $rusage['ru_utime.tv_sec'] + $rusage['ru_utime.tv_usec'] / 1000000 - $cpu_time_tmp[0], $rusage['ru_stime.tv_sec'] + $rusage['ru_stime.tv_usec'] / 1000000 - $cpu_time_tmp[1]); $cpu_time_tmp = array(); } $times = 1000000; print "<h1>测试用例运行次数: $times</h1>"; print "<b><font color='blue'>require方式消耗: </font></b>"; cputime_start(); while($i ++ < $times) test_require("required_require.php"); cputime_end(); print "<b><font color='blue'>require_once方式消耗: </font></b>"; cputime_start(); while($j ++ < $times) test_require_once("required_requireonce.php"); cputime_end(); ?> <meta http-equiv="Content-Type: text/html; charset=utf-8" />

required_require.php

PHP code
<?php class T1{} ?>

required_require_once.php

PHP code
<?php class T2{} ?>

输出结果:
测试用例运行次数: 1000000
require方式消耗: user_cpu: 0.56000000, system_cpu: 0.01000000
require_once方式消耗: user_cpu: 2.84000000, system_cpu: 1.05000000
多次运行,结果稳定. 可以看出require_once与require相比,系统cpu消耗是其105倍,用户cpu消耗约为5倍左右, 总体cpu时间消耗是其8倍左右.

自动加载
PHP引入了__autoload机制, 如果脚本解释执行过程中定义了__autoload函数, 那么当需要类而类未定义的时候, 就会将类名作为参数, 调用__autoload函数, __autoload由用户程序员自己来实现一个文件的加载机制.
在使用__autoload机制时,我们需要确保文件层次结构,命名有严格的规范.
自动加载的应用场景:
当我们需要一个动态的加载机制的时候,比如使用可变类名的情况(new $classname),在这种情形下,我们为了避免一次去加载所有可能的类定义文件,通常会有一个规则去require类定义文件,那我们可以把这个require放入到__autoload中,对其做一个统一的规范.

spl自动加载
__autoload解决了类的自动加载问题,但是,当系统比较大的时候,可能一个autoload并不能完全的(或难度较大)规范自动加载规则(特别是在与其他系统协同工作时).那我们首先想到的就是提供多个autoload功能的函数来解决这个问题,spl自动加载就是解决这个问题的.
通过函数spl_autoload_register($autoload_callback, $throw, $prepend)/spl_autoload_unregister来维护一个autoload函数的栈, 三个参数都是可选的, $autoload_callback是要加入的函数名, $throw指函数注册过程发生错误(比如提供的函数名不存在)时是否抛出异常, $prepend用来指明是否是向autoload栈的前面插入.

总结
关于"包含文件",能够想到的就这么多,在这里做一个小的总结:
1. 尽可能自定义一个require_once函数来管理这个once的加载机制, 这样做不仅有性能上的提升,而且同时对"包含文件"进行了一个统一的管理
2. 对于利用面向对象特性较多的系统,应尝试使用autoload机制, 当系统比较复杂时, 可以使用spl_autoload_xxx对autoload进行管理
3. 对于非文件域需要的(比如类的继承等)"包含文件", 尽可能的把require/include放入到函数等具体的处理过程中,在真正需要的时候条件包含.
比如:
common.func.php

PHP code
<?php function ud_require_once($filename) { isset($GLOBALS[$filename]) or (($GLOBALS[$filename] = 1) and require $filename); } ?>

user.func.php

PHP code
<?php function f() { } ?>

A.class.php

PHP code
<?php class A { } ?>

B.class.php

PHP code
<?php //common.func.php和A.class.php是当前文件B.class.php无论如何都需要的,所以在文件头部进行包含 function_exists('ud_require_once') or require 'common.func.php'; ud_require_once("A.class.php"); class B extends A { public function test() { //user.func.php只有在此函数调用时才需要,所以在这里进行require ud_require_once("user.func.php"); f(); } } ?>

4. 这一点实际是一个老生长谈的问题, 文件结构和命名的规范…无论你是否使用autoload, 无论你是否使用自定义require_once, 无论你是否使用可变类名(new $classname()方式), 都需要遵循一个统一的文件结构和命名规范, 一旦这个规范确立了, 无论这个规范有多烂, 都要遵循它, 当然不是不能更改, 但是更改需要有一个统一的规划, 并且这种对规范的修改带来的对旧有代码的改动工作, 最好开发工具进行修改.
5. 与第四点同样重要的问题, 就是代码长度的问题, PHP是解释型语言, 多一个无用的东西, 每次执行就都会多一些消耗, 哪怕那只是一个函数定义….所以, 要尽可能的让自己的php文件功能单一, 让每次require都高效的包含所需文件

关于php的文件包含, 我只有这么多的认识, 希望有更多/更好这方面认知的朋友能够不吝赐教/拍砖

分类: PHP | 评论数: 21 | 阅读全文

请问eclipse下php开发,用什么统计代码行数阿

admin 发表于 2011-03-04 17:21 浏览次数:

请问eclipse下php开发,用什么统计代码行数阿

插件

分类: PHP | 评论数: 7 | 阅读全文

日了,我电脑里的Apache抽风了???

admin 发表于 2011-03-04 17:21 浏览次数:

昨晚还在调试代码,用的好好的,今天中午开机输入127.0.0.1就访问不了,localhost也不行,
测试80端口显示:
Your port 80 is actually used by:
Infprmation not available <might be Skype>.

我对Apache不熟悉,使用的是wamp,有人知道怎么回事?怎么解决,什么重装之类的无实际价值的话就不要回答了

分类: PHP | 评论数: 11 | 阅读全文

想做个网站,让大家建议下,选择哪个开源程序好?

admin 发表于 2011-03-04 17:02 浏览次数:

我想做个 类似 http://go.cqmmgo.com http://www.chengw.com/ 这样的一个网站,大家指导下,我应该选择哪个开源程序?

分类: PHP | 评论数: 17 | 阅读全文

kindeditor编辑器设置上传图片路径?

admin 发表于 2011-03-04 17:02 浏览次数:

我在kindeditor里面的php下面的upload_json.php文件里设置文件上传路径,
$save_path = ‘../../../uploadfile/’;
这里只能设置为相对路径, 我想设置成$save_path = ‘/uploadfile/’;但是这样是不成功的,
是不是kindeditor只能像上面这样设置相对路径呀?

分类: PHP | 评论数: 0 | 阅读全文

IIS+PHP一天都会出现网页打不慢或者网页访问错误

admin 发表于 2011-03-04 17:02 浏览次数:

问题是:IIS+PHP一天都会出现网页打不慢或者网页访问错误,每次都要重启IIS才可以,请高手忙吧下…
系统是:win2003+IIS+PHP(5.0)+Mysql(4.0)

分类: PHP | 评论数: 3 | 阅读全文

这段小代码有点点不懂,请教

admin 发表于 2011-03-04 17:02 浏览次数:

unset($_ENV,$HTTP_ENV_VARS,$_REQUEST,$HTTP_POST_VARS,$HTTP_GET_VARS,$HTTP_POST_FILES,$HTTP_COOKIE_VARS);
if(!get_magic_quotes_gpc()){
Add_S($_POST);
Add_S($_GET);
Add_S($_COOKIE);

分类: PHP | 评论数: 5 | 阅读全文

有关PHP Pack和服务器配置…

admin 发表于 2011-03-04 17:02 浏览次数:

代码如下:
#!/etc -q
<?php
echo "<br>";
echo pack("H12","E4B8ADE69687");
echo "<br>";
echo pack("H8","D6D0CEC4");
echo "<br>";
echo bin2hex("中文");
echo "<br>";  
?>

一个服务器的运行结果是:
#!/etc -q
中文
????
e4b8ade69687

另一个是环境下的运行结果是:
涓枃
中文
e4b8ade69687 

请问是什么原因?可以帮忙解释下代码吗?PHP服务器需要写什么特别的配置才可以识别类似#!/etc -q或者
#!/usr/local/bin/php.cli的语句呢?谢谢…

分类: PHP | 评论数: 0 | 阅读全文

php一些基础东西学完了,接下去应该学什么?

admin 发表于 2011-03-04 17:02 浏览次数:

大侠们给点建议。越详细越好。

分类: PHP | 评论数: 17 | 阅读全文

在用PHP开发全球化网站时,应选择什么字符集编码?应用此字符集编码时,有哪些步骤,需要注意些什么问题?

admin 发表于 2011-03-04 17:01 浏览次数:

RT

分类: PHP | 评论数: 12 | 阅读全文

返回首页 | 关于我们 | 联系我们 | 广告合作 | 网站地图 | 友情链接 | 版权声明