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

查看:41
本文介绍了存储过程、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天全站免登陆