ThinkPHPÁ¬½ÓOracleÊý¾Ý¿â

5年以前  |  阅读数:962 次  |  编程语言:PHP 

*Ò»¡¢²Ù×÷»¾³´i½¨**

ϵͳ£ºWindows7 Æi½¢°ae 64λ

PHP»¾³£ºwampserver2.2e-php5.4.3-httpd2.2.22-mysql5.5.24 32λ°ae
ÏÂÔصØÖ
£ºhttp://www.jb51.net/softs/161568.html

ThinkPHP£º3.2.3Õýʽ°ae
ÏÂÔصØÖ*£ºhttp://thinkphp.cn/down.html

Oracle£ºOrcale_11gR2 32λ°ae
ÏÂÔصØÖ*£ºhttp://www.oracle.com/technetwork/cn/indexes/downloads/index.html

Êý¾Ý¿a²Ù×÷¹¤¾ß£ºPLSQL Developer 32λ
ÏÂÔصØÖ*£ºhttp://www.jb51.net/softs/63962.html

¿ª¢¹¤¾ß£ºNetBeans IDE 7.1.2
ÏÂÔصØÖ
£ºhttp://www.jb51.net/softs/18343.html

˵Ã÷£ºÕaÀiÎÒ´¸´Ç¿µ÷Èi¼þµÄ¡°Î»¡±£¬ÊÇÒoΪÕa¸oºÜÖØÒª£¬Ò»°aÇe¿oÏ£¬ÎÒÃÇϵͳÊÇ64λµÄ£¬ÄÇô×iºÃÈi¼þÒ²ÓÃ64λµÄ£¬µ«ÊÇÕaÀi³ý¹ýϵͳÍa£¬È«²¿Ñ¡Ôñ32λÊÇÓÐÔ­ÒoµÄ£¬Ä¿µÄÊÇΪÁËÅaºÏPLSQL DeveloperºÍWAMPµÄPHPÀ(C)Õ¹¡£ÒoΪPLSQL DeveloperûÓÐ64λ°ae¡£ÓеÄÅoÓÑ˵ÓÃ64λOracleÊý¾Ý¿a£¬×°32λ¿Í»§¶Ë¾ÍÐУ¬ÎÒ²»ÏeÕaÑu×o£¬Èç¹u²»Ï²»¶ÎҵIJÙ×÷½Ê½£¬¿ÉÒÔÈƵÀ¡£µ±È»ÁË£¬Èç¹uÄa²»Ê¹ÓÃPLSQL Developer£¬¶øÑ¡ÔñʹÓÃOracle ×Ô´øµÄSQL Developer£¬ÄÇôÄaÈ«°²×°64λ»o32¶¼ÊÇÄa×Ô¼ºµÄÊ¡£PHPÁ¬½ÓOracleÊý¾Ý¿aÐeÒª¿ªÆoÏaÓ¦µÄÀ(C)Õ¹£¬Õa¸oÀ(C)Õ¹Ò²ÐeÒªÊý¾Ý¿a¿Í»§¶ËµÄÖ§³Ö£¬ÒoΪphpÀ(C)Õ¹Ò²ÐeÒª¶ÔÓ¦Êý¾Ý¿a¿Í»§¶ËµÄλÊý¡£†ªaÂÍe±Ï¡£

*¶þ¡¢»¾³ÅaÖÃ
**

1£¬²Ù×÷ϵͳµÄ°²×°ÎҾͲ»ËµÁË£¬Oracle°²×°×Ô¼º½a¾o£¬NetBeans IDE 7.1.2Ò²×Ô¼º½a¾o¡£

2£¬WampµÄ°²×°ÎÒÒ²²»ËµÁË£¬²»»aµÄÖ±½Ó´ÓDOS¿ªÊ¼ÖØÐÂѧϰ°É¡£

3£¬WAMP»a°ÑPHPµÄÍøÒ³Îļþ¼Ð¶¨ÒaÔÚ°²×°wampµÄÎļþ¼ÐϵÄwwwÀiÃae£¬ÎÒÊÇ°²×°ÔÚDÅÌ£¬ËuÒÔ¾ÍÊÇD:\WAMP\www¡£ÎÒÃÇÔÝʱ²»×o±ðµÄ×Ô¶¨ÒaÐ޸ġ£Æo¶¯wamp£¬ÏµÍ³ÍÐÅÌͼ±eΪÂÌÉ«±iʾÆo¶¯OK¡£

4£¬´o¿ªlocalhost£¬¿´µ½ÈçϽçÃae£¬±iʾ»*¾³ÅaÖûu±¾OK¡£ÎªÊ²Ã´ÊÇ»u±¾ÁË£¬ÒoΪ»¹Ã»ÓжÔOracleµÄÅaÖýøÐÐÉeÖá£

5£¬´o¿ªÈçͼµÄPHPÀ(C)Õ¹²Ëµ¥£¬ÔÚÂÌɫͼ±eÉÏ£¬×o¼u->PHP->PHPÀ(C)Õ¹£¬µa»÷php-oci8µÄÀ(C)Õ¹£¬ÕaʱºoÕa¸oWAMP»aÖØÆo£¬µÈ´ýÖØÆoºo±aÂÌ£¬¾Í±iʾOK¡£

6£¬Ôٴδo¿ª¸Õ²ÅµÄlocalhostÒ³Ãae£¬Èç¹uÕÒµ½Èçͼ4µÄÏÔʾ£¬¾Í±iʾĿǰPHPÒѾ­Ö§³ÖOracleÁË¡£

×¢Òa£¬ÎÒÏÖÔÚÓÃµÄ wampºÍoracle¿Í»§¶Ë¶¼ÊÇ32룬Èç¹uÆaÖÐÒ»¸oÊÇ64룬ÄÇôÕa¸oociµÄÀ(C)չʱ´o²»¿ªµÄ£¬Í¬Ê±×Ô¶¯»*¾³¼a²aÒ³ÃaeҲûÓÐoci8µÄÏÔʾ¡£ÔÚ²»Ê¹ÓÃPL/SQLµÄÇ°ÌaÏ£¬±ØÐeÊÇ32λOracleºÍ32λWAMP´iÅa£¬64λOracleºÍ64λWAMP´iÅa£¬elseÇeÈƵÀ¡£

Èý¡¢ThinkPHPÅaÖÃ

1£¬°ÑÏÂÔغõÄ3.0Õýʽ°ae½aѹ£¬ÏiÄ¿ÖÐÖ»ÐeÒªThinkPHPÎļþ¼Ð£¬ÕaÊǺËÐÄ¡£
2£¬Ê¹ÓÃIDEн¨Ò»¸oÏiÄ¿£¬ÏiÄ¿µÄÎļþ¼ÐΪ¸Õ²ÅµÄWampϵÄwwwÎļþ¼Ð£¬Èç¹u¸oÈËÐeÒª×Ô¶¨Òa±ðµÄÎļþ¼Ð£¬ÐeÒªÐÞ¸ÄapacheµÄÅaÖÃÎļþ£¬ÕaÀiÎÒ²»Ð޸ġ£
3£¬½«ThinkphpÎļþ¼Ð¿½±´µ½ÏiÄ¿Îļþ¼ÐÖУ¬Ð½¨Ò»¸ophpÎļþ£¬ÃuÃuindex.php¡£
4£¬IDEÖÐÒѾ­ÓÐÕaÐ(C)ÎļþµÄÏÔʾÁË£¬´o¿ªindex.php£¬±aдÈçÏÂÄÚÈÝ£º


    <?php
     define('APP_DEBUG', true);
     require './ThinkPHP/ThinkPHP.php';

5£¬ÔÚa¯ÀÀÆ÷Öдo¿ªlocalhost/ÏiÄ¿Ãu/index.php£¬Thinkphp»a°iÄaÉu³ÉºÃÏa¹ØÎļþºÍÎļþ¼Ð¡£
6£¬¶ÔÅaÖÃÎļþ½øÐвÙ×÷£¬ÕÒµ½£ºConfÎļþ¼ÐÏÂconfig.phpÎļþ£¬ÐÞ¸ÄÈçÏ£º


    <?php
    return array(
     'DB_TYPE' => 'Oracle', // Êý¾Ý¿aÀaÐÍ
     'DB_HOST' => '192.168.0.8', // *þÎñÆ÷µØÖ*
     'DB_NAME' => 'orcl', // Êý¾Ý¿aÃu
     'DB_USER' => 'test', // Óû§Ãu
     'DB_PWD' => 'test', // ÃÜÂe
     'DB_PORT' => '1521', // ¶Ë¿Ú
    );

OracleÊý¾Ý¿aºÍmysql µÄ½a¹¹²»Í¬£¬Ò»°aĬÈÏ°²×°µÄÊý¾Ý¿aÃuÊÇorcl£¬Èç¹uÄaʹÓÃÁ˶a¸oÊý¾Ý¿a¼aÌý£¬ÄÇô¾ÍÒª¸u¾Ý¾ßÌaµÄ¼aÌý×Ö¶ÎÀ´ÉeÖᣱÈÈ磺ÎÒ±¾»uÊý¾Ý¿a¼aͦÊÇOrcl£¬Í¬Ê±¼aÌýÁiÍaÒ»¸oÍaÍøµÄÊý¾Ý¿a£¬¼aÌý×Ö*u´®ÎªOrcl2£¬ÄÇôÈç¹uÄaÐeÒªÁ¬½ÓÕa¸oÍaÍøÊý¾Ý¿a£¬ÄÇôÐeҪдµÄÊý¾Ý¿aÃu¾ÍÊÇorcl2¡£

7£¬¾­¹ýÒÔÉϵÄÅaÖã¬ÊÇÒѾ­¿ÉÒÔÁ¬½ÓoracleÊý¾Ý¿aÁË£¬µ«ÊÇÔÚthinkphpµÄʵ¼Ê²Ù×÷ÖÐÓÐʲôעÒaµÄµØ½£¬ÇÒÌýÏ»ØÖ½a¡£

×i½uÊÕ¼¯ÁËÒ»Ð(C)¹ØÓÚTHinkPHPÁ¬½ÓOracleÊý¾Ý¿aµÄÎÊÌa£¬ÓкܶaÅoÓÑ°´ÕÕÁ¬½ÓmysqlµÄ½¨À´²Ù×÷£¬µ¼ÖÂÓÐÒ»Ð(C)½¨ÔÚOrealeÖÐÎÞ¨Õý³£Ê¹ÓᣱÈÈç˵£ºfindAll£¬Select½¨ÎިʹÓ㬻ñÈ¡²»µ½ÐeÒªµÄÊý¾Ý¡£CreateºÍadd½¨ÎÞ*¨´´½¨ºÍдÈeÊý¾Ýµ½Êý¾Ý¿aÖС£

Æaʵ¸u¾ÝÒÔÇ°ÎÊÌaÎÒ×oÁ˼¸Ìiµ÷ÊÔ£¬ÕÒµ½ÁËÎÊÌaËuÔÚ£¬²¢³É¹¦ÔÚÎÒ×Ô¼ºÒ»¸oСÏiÄ¿ÁÏ°ÖÐʹÓÃÕý³££¬ÄÇôÏÖÔھͽ«Îҵľ­ÑeÖÏi¸ø´o¼Ò¡£

1£¬Êý¾Ý¿aµÄÁ¬½Ó¼°ÅaÖÃÎļþµÄÄÚÈÝÎҾͲ»ËµÁË£¬ ÉÏÃaeÒѾ­×oÁ˽aÊÍ¡£ÎÒÕaÀiÖ»¸u¾ÝÒ»¸oÊý¾Ý±iµÄÀý×ÓÀ´ËµÃ÷ÎҵIJÙ×÷¡£

2£¬±i½a¹¹ÈçÏ£º

3£¬Õa¸o±iÖÐÓÐ3¸o×ֶΣ¬IDÖ÷¼u£¬Óû§ÃuusernameºÍÃÜÂepassword£¬ÒoΪoracleÊý¾Ý¿a°Ñ±iÃuºÍ×ֶζ¼ÊÇת³É´oдµÄ£¬Í¬Ê±²»Ö§³ÖIDÖ÷¼u×ÔÔo£¬ÎÒÖ»ÓÐʹÓÃÁiÍaµÄ½¨À´ÊµÏÖÕa¸o¹¦ÄÜ£¬±ÈÈ磺ID×Ô¶¯ÐoÁÐ+´¥*¢Æ÷ʵÏÖID×ÔÔo¡£

4£¬ ThinkPHPÖУ¬ActionÊÇ¿ØÖÆÆ÷£¬ModelÊÇÄ£ÐÍ£¬ÊÓͼÊÇÒÔÄ£°a*½Ê½ÌaÏֵġ£

Ê×ÏÈ£¬Ëµ¿ØÖÆÆ÷£¬ÎÒÖ»×oÔo¼ÓºÍ»ñÈ¡ÁбiµÄ½¨½eÉÜ¡£

Æa´Î£¬ËµÄ£ÐÍ£¬ÕaÀi²ÅÊdzɹ¦µÄÖ÷ÒªÔ­Òo¡£ÎªÊ²Ã´£¿ThinkPHPÊÇÓÐ×Ö¶ÎÓ³ÉaµÄ£¬Õa¸oÔÚ¶ÔMYSQLµÄÖ§³Ödz£ÍeÃÀ£¬»u±¾²»ÓÃдMODEL£¬µ«ÊǶÔORALCE¾Í²»ÐÐÁË£¬µ±Ê¹ÓÃM->add()À´Ìi¼ÓÊý¾Ýʱ£¬×ֶλa±»$this->_facade()½¨¹ýÂ˵o¡£ÕaÑuÉu³ÉµÄSQLÓi¾a¾ÍÊÇû¨Ö´Ðеģ¬¿Ï¶¨ÊÇ´iÎoµÄ£¬µ¼ÖÂÊý¾ÝÌi¼Ó²»µ½Êý¾Ý¿aÖУ¬ÄÇôʹÓÃselect()½¨Ò²ÊÇÒ»Ñu±»¹ýÂË¡£

ÔٴΣ¬µ±ÎÒµ¥²½µ÷ÊÔʱ£¬¶Ïµa±»¹ýÂ˵Äʱºo£¬¹ýÂ˽¨Ê¹Óõ½ÁËnew³oÀ´µÄMODEL£¬Õa¸oMODEL»aÓÐÒ»¸o×Ö¶ÎÓ³ÉaµÄÊý×eÔÚÀiÃae£¬Õa¸o¹ýÂ˽¨¾ÍÊǺÍÕa¸o×Ö¶ÎÊý×e½øÐжԱȣ¬Èç¹u²»Ò»Ö¾͹ýÂ˵o£¬½a¹uÎÒµ÷ÊÔ¢ÏÖ£¬new³oÀ´µÄMODEL¸u±¾Ã»ÓаÑ×Ö¶ÎÓ³Éa¼Ó½øÈ¥£¬Êý×eÖ±½ÓΪ¿Õ£¬µ±È»¾Íû¨ºÍÌi¼ÓµÄÊý¾Ý×Ö¶ÎÒ»Ò»¶ÔÓ¦ÁË¡£Õa¾ÍÊÇ´iÎoµÄ¹Ø¼u¡£

ÏÂÃae¾ÍÀ´Ëµ½a¾o½¨£¬ÆaʵºÜ¼oµ¥£¬°´ÕÕ»u±¾µÄMVC½a¹¹£¬²»¹ÜÊÇPHP»¹ÊÇJAVA»¹ÊÇ.NET¶¼ÓÐÕaÑuµÄ½a¹¹£¬ÄÇô°´ÕÕÑϸñµÄ±e×¼£¬MODEL²aµÄ´uÂeÊDZØÐeдµÄ£¬¾ÍÊÇÒªºÍÊý¾Ý¿aµÄ×Ö¶Î×oÓ³Éa¡£µ«ÊǺܶaÓÃmysqlµÄ£¬¾ÍÖ±½ÓûÓÐȥдMODELÀiÃaeµÄ´uÂe¡£ÕaÖÖÏ°¹ß±»Óõ½ÁËoracleÖУ¬¾Í³oÁËÎÊÌa¡£

5£¬ ÏÂÃaeÕe¶ÔÎÒÉÏÃaeµÄÊý¾Ý±iд³oÎҵĴuÂe£º

ÎÒµÄActionÊÇÕaÑuµÄ£ºUserAction.class.php¡£¿ØÖÆÆ÷ÎÒÖ»¶ÔÌi¼ÓºÍ²eÕÒ×oÀý×Ó£¬Òo´Ë´uÂeÈçÏ£º


    public function index() {
      header("Content-Type:text/html; charset=utf-8");

      $M_User = new UserModel();

      $User_List = $M_User->select();

      $this->assign('Title', 'Óû§¹ÜÀi');

      $this->assign('UserList', $User_List);

      $this->display();
    }

     //Ìi¼ÓÓû§Ìa½»´¦Ài
    public function Create_Post() {
      $M_User = new UserModel();
      $data['username'] = $this->_post('username');
      $data['password'] = md5($this->_post('pwd'));

      if ($M_User->create()) {
       $Query_Result = $M_User->add($data);
       if (false !== $Query_Result) {
        $this->success('Óû§Ìi¼Ó³É¹¦');
       } else {
        $this->error('Óû§Ìi¼Ó´iÎo');
       }
      } else {
       header("Content-Type:text/html; charset=utf-8");
       exit($M_User->getError() . ' [ <a href="javascript:history.back()">*µ »Ø</a> ]');
      }
    }

Action½aÊÍ£º

$M_User=new UserModel();

Õa¸o½¨×iºÃÕaôд£¬ÒoΪ×o.NETµÄÔ­Òo£¬Ò»Ö±¶¼ÕaôдµÄ¡£Õe¶Ô¾ßÌaµÄÄ£ÐͽøÐÐʵÀý»¯£¬Ñϸñ¹ae¶¨ÎÒ¾ÍÒª¶ÔUser±i½øÐвÙ×÷ÁË¡£

»ñÈ¡POSTÊý¾ÝµÄ´uÂe¾Í²»¶a½aÊÍÁË¡£

$M_User->create();

ÕaÊÇThinkPHPµÄÒ»¸o½¨£¬ºÜºÃ£¬¿ÉÒÔ°iÄa¹ýÂ˵oǨµÄ¶«Î÷£¬½¨ÒeʹÓá£

$Query_Result = $M_User->add($data);

ÕaÒ»¶Î¾ÍÊÇÊý¾ÝµÄÌi¼Ó£¬ÎÒÏ°¹ßÖ¸¶¨ÒªÌi¼ÓµÄÊý¾Ý£¬Ò²ÊÇÒoΪÕaÒ»¶ÎÐeÒª¸u¾Ý$M_UserʵÀý»¯£¬²¢¹ýÂË×ֶΡ£µ±È»ÁË£¬ÎÒÃÇÖ»Òª×oºÃMODELµÄ´uÂe£¬¾Í²»»aÓÐÎÊÌa¡£ÏÂÃaeµÄ´uÂe¾Í²»½aÊÍ¡£¹Ù*½Îĵµ¶¼ÓС£

ÎÒµÄModelÊÇÕaÑuµÄ£ºUserModel.class.php

'id'``, ``'username'``, ``'password'``);

Model½aÊÍ£ºÕa²ÅÊÇÖصa£¬ÕaÓÐÕaÑu£¬new³oÀ´µÄ$M_UserµÄÓ³Éa×Ö¶ÎÊý×e²Å²»»aΪ¿Õ£¬ÕaÑu²ÅÄܺÍPOSTµÄÊý¾Ý½øÐжÔÓ¦£¬²Å»aÈùýÂ˽¨Õý³£Ê¶±ð£¬²»±»¹ýÂË¡£

6£¬¾­¹ýÁËÒÔÉϵIJÙ×÷£¬Õe¶ÔOracleµÄÊý¾Ý¿a²Ù×÷¾ÍÍe³ÉÁË£¬ÎÒÏÖÔÚÒ²¿ÉÒÔÈÎÒaʹÓÃThinkPHPÌa¹(C)µÄ½¨À´²Ù×÷Êý¾ÝÁË£¬°uÀ¨*ÖÒ³(limit)£¬find()£¬findAllµÈµÈ¡£

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例