dsgdfg30210 2010-08-26 13:43
浏览 59
已采纳

mysql LAST_INSERT_ID()在传回检索到的值时导致一些SQL问题

I need some help figuring out why the following scenario does not work. I'm trying to retrieve a value from the last updated ID in mysql, then pass that value via javascript over to an ajax call which calls a .php page, which also calls another function "ZEND_emaiL" in a different php page.

In the very first php page that retrieves the id from mysql LAST_INSERT_ID(), if I hard code the value "100" it works, but if I use the value returned from LAST_INSERT_ID() it causes a failure.

Here's the php code for the LAST_INSERT_ID():

$sql='SELECT LAST_INSERT_ID();';
$last_updated_id = $db->get_var( $sql );
$last_updated_id = $last_updated_id+0;//make int
echo $last_updated_id; //send output back to the ajax call
var_dump($last_updated_id); ------------->RETURNS **int 149**

if I send back a hard coded "100" like this: echo 100; then it works.

Any ideas? Thanks for your help in advance.

The following are values retrieved from the php page that contains the ZEND_email() function. I grabbed these for debugging purposes hoping it would help.

RETURN VALUES for Hard Coded:

var_dump($n_id);---------->Returns **int 100**
var_dump($sqlresult);----->Returns **resource 24**
var_dump($row);----------->Returns **array of data to parse through**

RETURN VALUES FOR Passed in Variable (Fails):

function ZEND_email($to, $from="", $subject="", $msg="", $notif_id='', $root_dir="")
{
var_dump($notif_id);---------------------->RETURNS **string '100'**
$notif_id = $notif_id+0;//convert to int
var_dump($notif_id);---------------------->RETURNS **int 100**

$n_id = $notif_id;      
$xsql = $sql_str->SQL_SELECT_all_notif_attachments($account_id, $n_id);

$sqlresult=mysql_query($xsql);
$row=mysql_fetch_row($sqlresult);

var_dump($n_id);---------------->RETURNS **int 100**
var_dump($sqlresult);----------->RETURNS **resource 24**
var_dump($row);----------------->RETURNS **boolean false**
}

展开全部

  • 写回答

3条回答 默认 最新

  • douti8321 2010-09-09 08:21
    关注

    Had to scrap this code...couldn't get it all to work with the feature for the app so we dropped it. Thanks for your help.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部