存储过程,MySQL和PHP [英] Stored Procedures, MySQL and PHP

查看:68
本文介绍了存储过程,MySQL和PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是一个相当开放的问题.我已经将MS SQLServer的存储过程与经典的ASP和ASP.net一起使用了一段时间,并且非常喜欢它们.

The question is a fairly open one. I've been using Stored Procs with MS SQLServer for some time with classic ASP and ASP.net and love them, lots.

我正在从事一个小型的业余项目,由于各种原因,这条路走了LAMP路线.在MySQL和PHP5中使用存储过程有任何提示/技巧/陷阱或良好的起点吗?我的MySQL版本支持存储过程.

I have a small hobby project I'm working on and for various reasons have gone the LAMP route. Any hints/tricks/traps or good starting points to get into using stored procedures with MySQL and PHP5? My version of MySQL supports Stored Procedures.

推荐答案

忘了mysqli,它比PDO难用得多,应该已经删除了.确实,它引入了对mysql的巨大改进,但是要在mysqli中达到相同的效果,有时需要在PDO上付出巨大的努力,即关联fetchAll.

Forget about mysqli, it's much harder to use than PDO and should have been already removed. It is true that it introduced huge improvements over mysql, but to achieve the same effect in mysqli sometimes requires enormous effort over PDO i.e. associative fetchAll.

相反,请查看 PDO ,特别是 准备好的语句和存储过程.

Instead, take a look at PDO, specifically prepared statements and stored procedures.

$stmt = $dbh->prepare("CALL sp_takes_string_returns_string(?)");
$value = 'hello';
$stmt->bindParam(1, $value, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000); 

// call the stored procedure
$stmt->execute();

print "procedure returned $value\n";

这篇关于存储过程,MySQL和PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆