【发布时间】:2012-03-10 01:31:31
【问题描述】:
我在互联网上搜索了这个“基本”(我是 postgresql 的新手,但对 MySQL 有点熟悉)问题,但关于 postgresql 和 php 的参考资料很少,所以我转向了 stackoverflow。 :D
我按照 yii 网站 http://www.yiiframework.com/doc/guide/1.1/en/database.dao 上的示例进行操作,但我不断遇到错误。这是我的代码:
$barya = 'INSERT INTO "BILL" (Assessed_Value,Total_Assessed_Value,Penalty_Percentage,Basic_Tax,SEF_Tax,Discount) VALUES (:Assessed_Value,:Total_Assessed_Value,:Penalty_Percentage,:Basic_Tax,:SEF_Tax,:Discount)';
$command = $connection->createCommand($barya);
$command = $connection->createCommand($barya);
$command = bindParam(":Assessed_Value", $compute, PDO::PARAM_STR);
$command =bindParam(":Total_Assessed_Value", $compute, PDO::PARAM_STR);
$command =bindValue(":Penalty_Percentage", 0.20, PDO::PARAM_STR);
$command =bindValue(":Basic_Tax", 0.15, PDO::PARAM_STR);
$command =bindValue(":SEF_Tax", 0.20, PDO::PARAM_STR);
$command =bindValue(":Discount", 0.03, PDO::PARAM_STR);
$command->execute();
我的错误是服务器错误:500。这是在 postgre 中插入新行的正确方法吗?
[编辑编辑]
我发现我的语法有误(在随机用 ' 和一些箭头替换 " 之后)。
它是这样的:
$barya = 'INSERT INTO "BILL" ("Assessed_Value","Total_Assessed_Value","Penalty_Percentage","Basic_Tax","SEF_Tax","Discount") VALUES(:Assessed_Value,:Total_Assessed_Value,:Penalty_Percentage,:Basic_Tax,:SEF_Tax,:Discount)';
$command = $connection->createCommand($barya);
$command->bindParam(":Assessed_Value", $compute, PDO::PARAM_STR);
$command->bindParam(":Total_Assessed_Value", $compute, PDO::PARAM_STR);
$command->bindParam(":Penalty_Percentage", $compute, PDO::PARAM_STR);
$command->bindParam(":Basic_Tax", $compute, PDO::PARAM_STR);
$command->bindParam(":SEF_Tax", $compute, PDO::PARAM_STR);
$command->bindParam(":Discount", $compute, PDO::PARAM_STR);
$command->execute();
但现在我遇到了外键问题。 T.T 有人知道怎么做吗?谢谢。 :D
【问题讨论】:
-
说“现在我的外键有问题”意义不大。嗯,它比原来的“服务器错误:500”要好,但差不了多少。
-
为什么在 pg_query_params() 更容易使用的情况下使用 PDO?
-
@FrankHeikens - 首先,使用
pg_query_params并不容易,其次,PDO 用于底层数据库通信要好得多(实际上更容易)。至于原始问题 - 给我们对您的问题的模糊描述不会让您走得太远。 “我的外键有问题”实际上可能是成千上万个不同的问题,而您没有指出一个。你真的认为有人会那样帮助你吗?
标签: php postgresql insert yii