小编leo*_*oap的帖子

在sql中多次使用相同的预处理语句参数

我试图在我的SQL中使用相同的参数,但它只识别第一个.看我的代码:

$stmt = $dbh->prepare("SELECT
    (SELECT SUM(oq.value)
    FROM operations_quotas AS oq
        JOIN operations AS o ON oq.operation = o.id
    WHERE o.user = :user AND o.type = 1 AND oq.status = 1
    ) AS total_incomes_open,

    (SELECT SUM(oq.value)
    FROM operations_quotas AS oq
        JOIN operations AS o ON oq.operation = o.id
    WHERE o.user = :user AND o.type = 1 AND oq.status = 2
    ) AS total_incomes_wroteoff");

$stmt->bindParam(":user", $this->getId());
$stmt->execute();
Run Code Online (Sandbox Code Playgroud)

那可能吗?

php sql prepared-statement

3
推荐指数
1
解决办法
3589
查看次数

致命错误:无法声明类Database,因为该名称已在中使用

我使用MVC为登录系统脚本编写tis代码

这是数据库类

<?php 



   class Database
   {

      private $host;
      private $user;
      private $password;
      private $database;


     function __construct($filename)
         {

            if (is_file($filename))include $filename;

                else throw new Exception("Error!");


            $this->host =$host;
            $this->user =$user;
            $this->password =$password;  
            $this->database =$database;

            $this->connect();

        }

    //Connect the server 

    private function connect()
       {
        $conn=mysqli_connect($this->host, $this->user, $this->password,       $this->database);

      //Check Connection
            if(!$conn)
                throw new Exception("Error: not connect to the server");




           // Select the database

       if(!mysqli_select_db($conn,$this->database))
           throw Exception("Error!");
     }


           //Close dataabase connection 

           function close()

            {
                    mysqli_close();    
            }    

     }




   ?>
Run Code Online (Sandbox Code Playgroud)

当我调用此代码

 <?php

    /*
    //Site login Controller …
Run Code Online (Sandbox Code Playgroud)

php model-view-controller login

-1
推荐指数
1
解决办法
2万
查看次数