INSERT INTO不会填满所有行

时间:2019-05-01 16:22:50

标签: php pdo prepared-statement

我的代码有问题,它是PayPal Express Integration。我的意思是在进行一些调整以匹配我的数据库后,它保持其原始状态,依此类推,它可以用ex填充行。 payerID等。

我的数据库中有2个表-首先是Products,它有5行,例如productID,Price,currency等,但我需要多1行-假设我们称其为Credits。我手动将其添加到数据库中,并在表产品中填充了数据。

然后,我还有另一个表称为Orders,在表中我也添加了称为Credits的行,而不是在成功付款+结帐将Credits与所选产品匹配之后,它应该在Orders表中填充此Row Credits。我的问题是订单表中除了最后一行->贷项外,所有数据都被填充,它总是在数据库中显示NULL。

这是我的代码的一部分:

<?xml version="1.0"?>
<configuration>
  <runtime>
    <!--
      Support connecting to servers which require modern TLS protocols.

      DontEnableSystemDefaultTlsVersions=false is sufficient if running on ≥.net-4.7
      which supports using the system-provided TLS versions/policies.
      DontEnableSchUseStrongCrypto is required if running on .net-4.6 which defaults
      to newer versions of TLS but doesn’t support following system updates/policies.
     -->
    <AppContextSwitchOverrides value="Switch.System.Net.DontEnableSystemDefaultTlsVersions=false;Switch.System.Net.DontEnableSchUseStrongCrypto=false"/>
  </runtime>
</configuration>

这就是我遇到的问题

    public function getAllProducts()
    {
        $db = getDB();
        $stmt = $db->prepare("SELECT * FROM products");
        $stmt->bindParam("pid", $pid, PDO::PARAM_INT) ;
        $stmt->execute();
        $data = $stmt->fetchAll(PDO::FETCH_OBJ);
        $db=null;
        return $data;

    }

    public function getProduct($pid)
    {
        $db = getDB();
        $stmt = $db->prepare("SELECT * FROM products WHERE pid=:pid");
        $stmt->bindParam("pid", $pid, PDO::PARAM_INT) ;
        $stmt->execute();
        $data = $stmt->fetch(PDO::FETCH_OBJ);
        $db=null;
        return $data;

    }

我想不通。

1 个答案:

答案 0 :(得分:0)

这是一个非常常见的问题,因此它应该得到答案,无论看起来多么明显。

一旦您进行了有效的INSERT查询,并且一个列变为NULL,则表示源变量包含NULL

因此问题不仅仅在于PDO,预准备语句,数据库,而不仅仅是源变量$credits。您必须检查与该变量相关的代码,并确保它确实包含所需的值。

相关问题