Codeigniter PDO集成 [英] Codeigniter PDO integration

查看:89
本文介绍了Codeigniter PDO集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上做了很多研究,但我没有找到任何可以帮助我使用PDO在codeigniter。我在CI 2.1.0的变化lof(我认为)pdo驱动程序被添加到框架。
现在我用一个database.php配置文件,如下所示:

i did lot of research on the web but i didnt find anything that could help me to use PDO in codeigniter. I saw in the change lof of CI 2.1.0(i think) that pdo driver was added to the framwork. I ended up now with a database.php config file that looks like this:

$db['default']['hostname'] = 'mysql:host=myhostname;port=myport'; 
$db['default']['username'] = 'myusername';
$db['default']['password'] = 'mypassword'; 
$db['default']['database'] = 'mydb'; 
$db['default']['dbdriver'] = 'pdo';

现在(经过很多浪费时间得到上面的代码片段工作。接收没有关于连接的错误,但如何执行查询现在?我不知道什么语法将工作和如何构建查询。任何人都有提示?

So now(after a lot of wasted time to get the snippet above to work -.- ) i receive no error about connection, but HOW TO EXECUTE QUERY NOW? i cant figure out what syntax will work and how to build queries. Anyone have hints?

PS:如果你说的是为什么我需要pdo在ci,答案是我的老板要我创建一个结构化的环境: p>

PS: if you're wordering about why i need pdo in ci, the answer is my boss want me to create a structured enviroment with:


  1. CI 2.x +(完成)

  2. Smarty 3(完成)

  3. PhpUnit(尚未)

  4. PDO(尚未)

  1. CI 2.x + (done)
  2. Smarty 3 (done)
  3. PhpUnit (not yet)
  4. PDO (not yet)

如果你也有任何提示整合phpunit感觉自由回答。提前使用PDO与在CodeIgniter中使用任何其他数据库驱动程序的方式相同。

so if you have also any hints for integrate phpunit feels free to answer. Ty in advance

推荐答案

如果您仍不确定,那么我建议您阅读数据库类的文档。

You use PDO the same way you use any other database driver in CodeIgniter. If you are still unsure then I would recommend reading the documentation on the Database Class.

您可以通过明确写入查询来执行标准查询,也可以使用 Active Record类<

You can issue standard queries by explicitly writing the query or you can use the Active Record Class (which is more of a query builder).

以下是一些示例:

// Standard query
$results = $this->db->query('SELECT name, title, email FROM my_table');

// Active record
$this->db->select('name, title, email');
$results = $this->db->get('my_table');

至于集成PHPUnit,请查看https://github.com/cmillr/CI-PHPUnit (我没有自行测试)或查看 CodeIgniter论坛。我已经看到了很多关于集成PHPUnit与CodeIgniter的主题。

As for integrating PHPUnit, have a look at https://github.com/cmillr/CI-PHPUnit (I haven't tested it myself) or look around the CodeIgniter forums. I've seen a ton of topics on integrating PHPUnit with CodeIgniter.

这篇关于Codeigniter PDO集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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