quer"/> quer">

Home  >  Article  >  Backend Development  >  ThinkPHP 3.0调用存储过程有关问题

ThinkPHP 3.0调用存储过程有关问题

WBOY
WBOYOriginal
2016-06-13 10:12:03950browse

ThinkPHP 3.0调用存储过程问题

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->        $model = D('Demo');        $str = 'aaa';        $sql = "SET @uname = '$str'; CALL new_pr(@uname);";        $data = $model -> query($sql, true);        echo $model -> getLastSql();


输出
SET @uname = 'aaa'; CALL new_pr(@uname); 
放到查询编辑器里面可以执行

求解

------解决方案--------------------
可能是定界符的问题,试试下面的:
PHP code
$sql = 'delimiter //';$sql .= "SET @uname = '$str';"$sql .= "CALL new_pr(@uname)//";$sql .='delimiter ;';<br><font color="#e78608">------解决方案--------------------</font><br>你说的情况我遇到过!在thinkphp中调用存储我成我是这样解决的:在链接数据库时多加了个参数就解决了:<br>define('CLIENT_MULTI_RESULTS',131072);<br>$conn =  mysql_connect('127.0.0.1','root','123456','1',CLIENT_MULTI_RESULTS) or die('连接失败');<br><br>你可以试一下!<br><font color="#e78608">------解决方案--------------------</font><br>对于 #13 的代码:<br>第一段和第三段除没有对 $str 赋值外,没有什么不同<br>第三段不行的原因,应该是 $str 没赋值<br><br>第一段可以而第二段不可以,则表示  <br>ThinkPHP 3.0 依然没有绕过 php 除声明存储过程外,不能不能在一个 query 中执行一条以上 sql 指令的安全约定<br>你需要分别执行那两条 sql 指令<div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn