doudouchan5830 2016-07-21 21:31
浏览 31

OCI PDO不执行查询PHP

i have 1 week searching the solution to this problem in my code, i can connect to the Oracle DB, but when i try to execute an insert statement this won't proceed as i wish. Can anyone please give me some advice into how can i proceed?

i let the structure of my work.

this is my Connection class

    <?php
    class Connection
    {
      public $connection;

      public function __CONSTRUCT()
     {
       try{
         $this->connection = new PDO('oci:dbname=//localhost:1521/orcl',"username", "userpassword");
         $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
       }catch(PDOException $e){
          die($e->getMessage());
       }
     }

   public function __getConnection()
   {
       return $this->connection;
   }
 }

this is my Object class User

     <?php
     class Usuario
     {
       public $IdUsuario;
       public $Email;
       public $Clave;
       public $Rol;
       public $Estado;
       public $NombreUsuario;
       public $Foto;
       public $CodigoActivacion;
       public $Sexo;
       public $Tstamp;

    public function __GET($k)
    {
      return $this->$k;
    }

    public function __SET($k, $v)
    {
      $this->$k = $v;
    }
 }

this is my UserModel

  <?php
  /**
   *
   */
   require_once _dependencia_.'Objects/Usuario.php';
   require_once _dependencia_.'Connection/Connection.php';
   require_once _dependencia_.'Model/SesionModel.php';
   require_once _dependencia_.'Objects/Sesion.php';
   class UsuarioModel
  {
    private $connection;
    public function __construct()
    {
      try {
         $c = new Connection();
         $this->connection = $c->__getConnection();
      } catch (Exception $e) {
         die($e->getMessage());
     }
   }

    public function save($Usuario)
    {
      try {
          $sql = 'INSERT INTO Usuario (NombreUsuario, Email, Clave, Rol, Estado, Foto, CodigoActivacion,Sexo)
           VALUES (?, ? ,? ,? ,? ,? ,?,?)';

        return $this->connection->prepare($sql)
         ->execute(
         array(
            $Usuario->__GET('NombreUsuario'),
            $Usuario->__GET('Email'),
            $Usuario->__GET('Clave'),
            $Usuario->__GET('Rol'),
            $Usuario->__GET('Estado'),
            $Usuario->__GET('Foto'),
            $Usuario->__GET('CodigoActivacion'),
            $Usuario->__GET('Sexo'),
            )
        );
    } catch (Exception $e) {
        die($e->getMessage());

        return false;
    }
}

and this is my Constant class

   <?php
     define("_ROOT_","http://localhost/SistemaBayerWeb/");
     define("_dependencia_","C:/xampp/htdocs/SistemaBayerWeb/");
   ?>

I really appreciate any advice, the project im giving the best to be MVC, and every piece of code in POO. thanks :)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 聚类分析或者python进行数据分析
    • ¥15 如何用visual studio code实现html页面
    • ¥15 逻辑谓词和消解原理的运用
    • ¥15 三菱伺服电机按启动按钮有使能但不动作
    • ¥15 js,页面2返回页面1时定位进入的设备
    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?