【发布时间】:2014-04-09 05:34:48
【问题描述】:
我是 PDO 的新手,听说这是做 Web 应用程序的更好方法,我正在开发小型计费应用程序。 有一个dobut,我可以像下面这样编码吗?
<?php
require_once '../../classes/PDO_connection.php';
$type = 'initial_stock';
$item_code = $_POST["item_code"];
$category = $_POST["category"];
$variety = $_POST["variety"];
$quantity = $_POST["quantity"];
$price = $_POST["price"];
$f_price = number_format($price, '2', '.', '');
$total = $quantity * $price;
$full_name = $item_code.':'.$category.':'.$variety.':'.$f_price;
$in_stock = $quantity;
$prev_stock = '';
//inserting data from initial stock page
$stmt = $pdo->prepare("INSERT INTO silk (type, item_code, category, variety, quantity, price, full_name, total, in_stock, sale_date, entered_date) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, now(), now())");
$stmt->bindParam(1, $type);
$stmt->bindParam(2, $item_code);
$stmt->bindParam(3, $category);
$stmt->bindParam(4, $variety);
$stmt->bindParam(5, $quantity);
$stmt->bindParam(6, $price);
$stmt->bindParam(7, $full_name);
$stmt->bindParam(8, $total);
$stmt->bindParam(9, $in_stock);
$stmt->execute();
//getting all initial stock for dispaling
$stmt = $pdo->prepare("SELECT * FROM silk WHERE type='initial_stock'");
$stmt->execute();
$rows = $stmt->fetchAll();
foreach($rows as $stock){
echo "<tr class='active'>
<td>".$stock['item_code']."</td>
<td>".$stock['category']."</td>
<td>".$stock['variety']."</td>
<td>".$stock['price']."</td>
<td>".$stock['quantity']."</td>
<td><a id='initial_stock_silk_delete' id_to_delete=".$stock['id'].">Delete</a></td>
</tr>";
}
在 mysql 中,我调用有查询的函数并返回值,但我认为 PDO 不需要那个?我对么?期待专业人士的建议....谢谢。
【问题讨论】: