我想更新表系列中的一列和父表中的两列。 我知道如何在sql中做到这一点。我通过查看一些示例尝试了它,如果我尝试直接在sql中更新它,但我无法使用存储过程进行更新,则它有效。
CREATE PROCEDURE prc_EditProfile(
IN inputfamilyName VARCHAR(45),
inputuserName VARCHAR(45),
inputfamilyID INT(20),
inputparentID INT(20)
)
BEGIN
update family, parent SET family.familyName= inputfamilyName, parent.userName=inputuserName WHERE family.FamilyID=inputfamilyID AND parent.ParentID=inputfamilyID;
END
答案 0 :(得分:1)
了解Update。
你可以这样做(测试电话):
<?php
include "includes/db_config.php";
include "ChromePhp.php";
$post = getRealPOST();
ChromePHP::log("Array : ", $post);
$id = intval($post['Id']);
$Serie = $post['Serie'];
$Producto = $post['Producto'];
$AVL = $post['AVL'];
$UniqueId = $post['UniqueId'];
$sim = $post['sim'];
$conn = sqlsrv_connect(SV_NAME, $connectionInfo) OR die("Unable to connect to the database");
$sql = "SELECT Id,Numero from Lineas WHERE Sim= $sim";
$params = array();
$options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
$result = array();
$res = sqlsrv_query($conn, $sql, $params, $options);
if(sqlsrv_num_rows($res) == 0){
echo json_encode(array(
'isError' => true,
'msg' => 'No existe SIM en BD'
));
ChromePHP::log("Error no rows");
ChromePHP::log($sql);
}else if(sqlsrv_num_rows > 1){
ChromePHP::log("Error no rows");
echo json_encode(array(
'isError' => true,
'msg' => 'Multiples SIM en BD'
));
}else{
$row = sqlsrv_fetch_array( $res, SQLSRV_FETCH_ASSOC);
$telefono = $row['Numero'];
$sql = "UPDATE producto SET Sim_Id=(SELECT Id from Lineas WHERE Sim= $sim) WHERE Id = $id";
$res = sqlsrv_query($conn, $sql, $params, $options);
echo json_encode(array(
'isSuccess' => true,
'Id' => $Id,
'Serie' => $Serie,
'UniqueId' => $UniqueId,
'AVL' => $AVL,
'Producto' => $Producto,
'sim' => $sim,
'Numero' => $telefono
));
ChromePHP::log($sql);
}
function getRealPOST() {
$pairs = explode("&", file_get_contents("php://input"));
$vars = array();
foreach ($pairs as $pair) {
$nv = explode("=", $pair);
$name = urldecode($nv[0]);
$value = urldecode($nv[1]);
$vars[$name] = $value;
}
return $vars;
}
?>