-1

我有一个 MySQL 存储例程,它有一个 INTEGER 类型的 IN 参数(IN p_user_id INTEGER)。如果用户正在创建一个新用户,我将 p_user_id 作为 '' 传递,否则如果用户正在更新用户,我将传递正在编辑的用户的 user_id。我的问题是,当 p_user_id 以 '' 的形式出现时,它会被转换为 0。我在 PHP 将值发送到 MySQL(并且值是 '')之前将用户 ID 转储出去并正确地转储它在 MySQL 例程的开头,p_user_id 现在为 0。我可以了解如何处理这个问题,以便我可以让 p_user_id IN 参数为 NULL。提前致谢!

PHP代码:

<?php 
session_start();

$functionCalled = $_GET['function'];

function userMaintMerge()
{   
    $userMaintUserId = $_GET['userMaintUserId'];
    $userMaintStep = $_GET['userMaintStep'];
    $userMaintFirstName = $_GET['userMaintFirstName'];
    $userMaintMI = $_GET['userMaintMI'];
    $userMaintLastName = $_GET['userMaintLastName'];
    $userMaintUserType = $_GET['userMaintUserType'];
    $userMaintSchoolId = $_GET['userMaintSchoolId'];
    $userMaintGrade = $_GET['userMaintGrade'];
    $userMaintLogin = $_GET['userMaintLogin'];
    $userMaintLogin = $_GET['userMaintPassword1'];

    $mysqli = new mysqli($_SESSION['dbaddress'],$_SESSION['user'],$_SESSION['dbpword'],$_SESSION['database']);
    if ($mysqli->connect_errno) 
    {
        echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
    }
    if (!$SelectUser = $mysqli->query("call MergeUser('$userMaintUserId','$userMaintStep','$userMaintFirstName','$userMaintMI','$userMaintLastName','$userMaintUserType','$userMaintSchoolId','$userMaintGrade','$userMaintLogin','$userMaintPassword1',@error)")) 
    {
        echo "CALL failed: (" . $mysqli->errno . ") " . $mysqli->error;
    }
}
?>

MySQL存储例程:

CREATE DEFINER=`root`@`localhost` PROCEDURE `MergeUser`(IN  p_user_id      INTEGER
,IN  p_step         VARCHAR(10)
,IN  p_first_name   VARCHAR(100)
,IN  p_mi           VARCHAR(5)
,IN  p_last_name    VARCHAR(100)
,IN  p_user_type    INTEGER
,IN  p_school_id    VARCHAR(25)
,IN  p_grade        VARCHAR(2)
,IN  p_login        VARCHAR(25)
,IN  p_password     VARCHAR(25)
,OUT p_error        VARCHAR(1) 
)
BEGIN

    insert into rjh_log values ('',p_user_id,sysdate());

    IF p_step = 'add' THEN

        INSERT INTO USERS
                    ( USER_ID
                    , LOGIN
                    , FIRST_NAME
                    , MI
                    , LAST_NAME
                    , USER_TYPE_ID
                    , GRADE
                    , SCHOOL_ID
                    , PASSWORD
                    , ACTIVE_FLAG
                    ) 
             VALUES ( NULL
                    , p_login
                    , p_first_name
                    , p_mi
                    , p_last_name
                    , p_user_type
                    , p_grade
                    , p_school_id
                    , p_password
                    , 'Y'
                    ) ;

    ELSE

        UPDATE USERS
           SET LOGIN = p_login
             , FIRST_NAME = p_first_name
             , MI = p_mi
             , LAST_NAME = p_last_name
             , USER_TYPE_ID = p_user_type
             , GRADE = p_grade
             , SCHOOL_ID = p_school_id
             , PASSWORD = p_school_id
         WHERE USER_ID = p_user_id;

    END IF;

END
4

1 回答 1

0
$userMaintUserId = ($_GET['userMaintUserId'] == "" ? "NULL" : $_GET['userMaintUserId']);
$userMaintStep = ($_GET['userMaintStep'] == "" ? "NULL" : $_GET['userMaintStep']);
$userMaintFirstName = ($_GET['userMaintFirstName'] == "" ? "NULL" : $_GET['userMaintFirstName']);
$userMaintMI = ($_GET['userMaintMI'] == "" ? "NULL" : $_GET['userMaintMI']);
$userMaintLastName = ($_GET['userMaintLastName'] == "" ? "NULL" : $_GET['userMaintLastName']);
$userMaintUserType = ($_GET['userMaintUserType'] == "" ? "NULL" : $_GET['userMaintUserType']);
$userMaintSchoolId = ($_GET['userMaintSchoolId'] == "" ? "NULL" : $_GET['userMaintSchoolId']);
$userMaintGrade = ($_GET['userMaintGrade'] == "" ? "NULL" : $_GET['userMaintGrade']);
$userMaintLogin = ($_GET['userMaintLogin'] == "" ? "NULL" : $_GET['userMaintLogin']);
$userMaintLogin = ($_GET['userMaintPassword1'] == "" ? "NULL" : $_GET['userMaintPassword1']);
于 2012-06-04T02:19:55.793 回答