如何在 CodeIgniter 中手动连接到数据库?
是否可以在 CodeIgniter 中使用任何 php 驱动程序手动连接到数据库?我会在模型中打开一个连接吗?我有一个 CodeIgniter 无法满足的需求,但我想将它用于它的 MVC 架构。我只是不能像在 MySQL 等演示中那样使用它的 ActiveRecord。
如果我只能进行“常规”非 CodeIgniter 数据库连接,我如何将信息获取到我的控制器中?
另外,我想以这种方式使用 CodeIgniter (没有活动记录)但对于它的所有其他“东西”是错误的吗?
谢谢。
Is it possible to connect to a database manually, using any set of drivers for php, in CodeIgniter? Would I just open a connection in the model? I have a need that CodeIgniter won't cover but I'd like to use it for it's MVC architecture. I just can't use it's ActiveRecord like in the demos with MySQL, etc.
If I can just do a "regular" non-CodeIgniter database connection, how do I get the information into my controller?
Also, am I wrong for wanting to use CodeIgniter in this way (no active record) but for all its other "stuff"?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个使用函数式 php 连接到 mysql 数据库的非常简单的示例。它来自 php 手册。将其放入您的模型中。通过正常 CI 方式调用模型函数来调用它。它将返回结果数组,因此将模型调用分配给控制器中的变量。
您可以在模型方法中使用它。假设您返回结果
编辑:将 mysql_close 移至 return 语句上方
This is a very simple example of using functional php to connect to a mysql db. It comes form the php manual. Put this in your model. Call it by calling a model function the normal CI way. It will return the result array, so assign the model call to a variable in your controller.
You can use this in your model method. Let's assume you return the results
EDIT: moved mysql_close above return statement
我真的不知道你的问题是什么,但你可以在没有活动记录的情况下执行查询。
例如
I don't really know what your problem is, but you can execute a query without the active record.
e.g
对于手动连接数据库,只需普通代码
for manual connection to database , just the normal code