PHP PDO ѧϰ±Ê¼Ç
¡öPDOΪºÎÎ
POD£¨PHP Data Object£©À©Õ¹ÔÚPHP5ÖмÓÈ룬PHP6Öн«Ä¬ÈÏʶÓÃPDOÁ¬½ÓÊý¾Ý¿â£¬ËùÓзÇPDOÀ©Õ¹½«»áÔÚPHP6±»´ÓÀ©Õ¹ÖÐÒƳý¡£¸ÃÀ©Õ¹ÌṩPHPÄÚÖÃÀà PDOÀ´¶ÔÊý¾Ý¿â½øÐзÃÎÊ£¬²»Í¬Êý¾Ý¿âʹÓÃÏàͬµÄ·½·¨Ãû£¬½â¾öÊý¾Ý¿âÁ¬½Ó²»Í³Ò»µÄÎÊÌâ¡£
ÎÒÊÇÅäÖÃÔÚwindowsÏÂ×ö¿ª·¢Óõġ£
¡öPDOµÄÄ¿±ê
ÌṩһÖÖÇáÐÍ¡¢ÇåÎú¡¢·½±ãµÄ API ͳһ¸÷ÖÖ²»Í¬ RDBMS ¿âµÄ¹²ÓÐÌØÐÔ£¬µ«²»Åųý¸ü¸ß¼¶µÄÌØÐÔ¡£ ͨ¹ý PHP ½Å±¾Ìṩ¿ÉÑ¡µÄ½Ï´ó³Ì¶ÈµÄ³éÏó/¼æÈÝÐÔ¡£
¡öPDOµÄÌص㣺
ÐÔÄÜ¡£PDO ´ÓÒ»¿ªÊ¼¾ÍÎüÈ¡ÁËÏÖÓÐÊý¾Ý¿âÀ©Õ¹³É¹¦ºÍʧ°ÜµÄ¾Ñé½Ìѵ¡£ÒòΪ PDO µÄ´úÂëÊÇȫеģ¬ËùÒÔÎÒÃÇÓлú»áÖØпªÊ¼Éè¼ÆÐÔÄÜ£¬ÒÔÀûÓà PHP 5 µÄ×îÐÂÌØÐÔ¡£ ÄÜÁ¦¡£PDO Ö¼ÔÚ½«³£¼ûµÄÊý¾Ý¿â¹¦ÄÜ×÷Ϊ»ù´¡Ìṩ£¬Í¬Ê±Ìṩ¶ÔÓÚ RDBMS ¶ÀÌع¦Äܵķ½±ã·ÃÎÊ¡£ ¼òµ¥¡£PDO Ö¼ÔÚʹÄúÄܹ»ÇáËÉʹÓÃÊý¾Ý¿â¡£API ²»»áÇ¿ÐнéÈëÄúµÄ´úÂ룬ͬʱ»áÇå³þµØ±íÃ÷ÿ¸öº¯Êýµ÷ÓõĹý³Ì¡£ ÔËÐÐʱ¿ÉÀ©Õ¹¡£PDO À©Õ¹ÊÇÄ£¿é»¯µÄ£¬Ê¹ÄúÄܹ»ÔÚÔËÐÐʱΪÄúµÄÊý¾Ý¿âºó¶Ë¼ÓÔØÇý¶¯³ÌÐò£¬¶ø²»±ØÖØбàÒë»òÖØа²×°Õû¸ö PHP ³ÌÐò¡£ÀýÈ磬PDO_OCI À©Õ¹»áÌæ´ú PDO À©Õ¹ÊµÏÖ Oracle Êý¾Ý¿â API¡£»¹ÓÐһЩÓÃÓÚ MySQL¡¢PostgreSQL¡¢ODBC ºÍ Firebird µÄÇý¶¯³ÌÐò£¬¸ü¶àµÄÇý¶¯³ÌÐòÉÐÔÚ¿ª·¢¡£
¡ö°²×°PDO
ÎÒÕâÀïÊÇWINDOWSÏ¿ª·¢ÓõÄPDOÀ©Õ¹£¬ÒªÊÇÄãÒªÔÚLinuxÏ°²×°ÅäÖã¬Çëµ½±ðµÄµØ·½Ñ°ÕÒ¡£
°æ±¾ÒªÇó£º
php5.1ÒÔ¼°ÒÔºó°æ±¾µÄ³ÌÐò°üÀïÒѾ´øÁË£»
php5.0.xÔòÒªµ½pecl.php.netÏÂÔØ£¬·Åµ½ÄãµÄÀ©Õ¹¿â£¬¾ÍÊÇPHPËùÔÚµÄÎļþ¼ÐµÄextÎļþ¼ÐÏ£»
ÊÖ²áÉÏ˵5.0֮ǰµÄ°æ±¾²»ÄÜÔËÐÐPDOÀ©Õ¹¡£
ÅäÖãº
ÐÞ¸ÄÄãµÄphp.iniÅäÖÃÎļþ,ʹËüÖ§³Öpdo.£¨php.iniÕâ¸ö¶«Î÷ûÓÐŪ¶®µÄ»°£¬ÏÈŪÇå³þ£¬ÒªÐ޸ĵ÷ÓÃÄãµÄphpinfo()º¯ÊýËùÏÔʾµÄÄǸöphp.ini£©
°Ñ
extension=php_pdo.dllÇ°ÃæµÄ·ÖºÅÈ¥µô£¬·ÖºÁÊÇphpÅäÖÃÎļþ×¢ÊÍ·ûºÅ,Õâ¸öÀ©Õ¹ÊDZØÐëµÄ¡£
ÍùÏ»¹ÓÐ
;extension=php_pdo.dll
;extension=php_pdo_firebird.dll
;extension=php_pdo_informix.dll
;extension=php_pdo_mssql.dll
;extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_oci8.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
;extension=php_pdo_sqlite.dll
¸÷¸÷À©Õ¹Ëù¶ÔÓ¦µÄÊý¾Ý¿âÊÇ£º
Driver nameSupported databasesPDO_DBLIBFreeTDS / Microsoft SQL Server / SybasePDO_FIREBIRDFirebird/Interbase 6PDO_INFORMIXIBM Informix Dynamic Ser
Ïà¹ØÎĵµ£º
header() is used to send raw HTTP headers. See the HTTP/1.1 specification for more information on HTTP headers.
ʹÓ÷¶Àý
·¶ÀýÒ»:
<?PHP
Header("Location: http://www.phpchina.com";);
exit;//ÔÚÿ¸öÖض¨ÏòÖ®ºó¶¼±ØÐë¼ÓÉÏ“exit",±ÜÃâ·¢Éú´íÎóºó£¬¼ÌÐøÖ´ÐС£
?>
<?php
head ......
ÏÈÏÂÔز¢°²×°eclipse£¬ÏÂÔصØÖ·£ºhttp://download.Eclipse.org/downloads/index.php¡£Eclipse ÐèÒª jre µÄÖ§³Ö£¬ËùÒÔÈç¹û»úÆ÷ÉÏ»¹Ã»×°jreµÄ»°¾Í¸Ï¿ìÈ¥ÏÂÔØÒ»¸ö×°ÉÏ£¬http://java.sun.comÓÐjreµÄÏÂÔØ¡£
µÚ¶þ£¬ÏÂÔز¢°²×° PHP ÔÚ Eclipse µÄ²å¼þ
µØÖ·£ºhttp://sourceforge.net/project/showfiles.php?group_id=57621&pa ......
ÎÒÏÖÔÚÓÐÕâÑùÒ»¸öÐèÇ󣬻òÐí×öc++³ÌÐòµÄ×ö¹ýÕâÑùµÄÍæÒâ¶ù£¬ÎÒÏÖÔÚÏëÓÃphpÀ´ÊµÏÖ£¬´ÓûÅöµ½ÕâÑùµÄÇé¿ö£¬ËùÒÔÓеãã¡£»¹Çë¸ßÈËÖ¸µãŶ£¬²»Ê¤¸Ð¼¤£¬Çë²é¿´ÎÒÉÏ´«µÄ½Øͼ£¬¸´ÖƹýÀ´£¬ÑùʽÂÒÁË¡£
ÃèÊöÒ»ÏÂÐèÇó°É£º¾ÍÊÇÔÚÎı¾ÀïÃæÓÃÖƱí·û»³ö±í¸ñÊ ......
<?php
//$str = "abcdef¡ôÖлªÈËÃñ¹²ºÍ¹ú";
//$str = "1234567890";
$str = "ÖлªÈËÃñ¹²ºÍ¹úabcÖлªÈËÃñ¹²ºÍ¹úÖлªÈËÃñ¹²ºÍ¹ú";
$str = cut_str($str, 18);
echo $str;
function cut_str($str, $len){
if(strlen($str) <= $len) return $str;
$n = 0;
$tempstr = '';
for($i = 0; ......
Ò».Ê×ÏÈÊÇPHPÍøÒ³µÄ±àÂë
¡¡¡¡1.phpÎļþ±¾ÉíµÄ±àÂëÓëÍøÒ³µÄ±àÂëӦƥÅä
¡¡¡¡a.Èç¹ûÓûʹÓÃgb2312±àÂ룬ÄÇôphpÒªÊä³öÍ·£ºheader(“Content-Type: text/html; charset=gb2312")£¬¾²Ì¬Ò³ÃæÌí¼Ó£¬ËùÓÐÎļþµÄ±àÂë¸ñʽΪANSI£¬¿ÉÓüÇʱ¾´ò¿ª£¬Áí´æΪѡÔñ±àÂëΪANSI£¬¸²¸ÇÔ´Îļþ¡£
¡¡¡¡b.Èç¹ûÓûʹÓÃutf-8±àÂ룬ÄÇôphpÒªÊä³ ......