简体   繁体   English

使用Codeigniter从数据库中检索单词

[英]Retrieving words from database with codeigniter

I have recently started using codeigniter and I am a bit stuck as it is all rather new to me. 我最近开始使用Codeigniter,但由于对我而言这是个新手,所以我感到有些困惑。

I use to have a config file with database conection and this on it: 我曾经有一个带有数据库连接的配置文件,上面有这个:

$qset = "select * from re_settings";
$rset = mysql_query($qset) or die(mysql_error());
$aset = mysql_fetch_array($rset);

and this would allow me to pull words from database by simply putting this on the site 这将使我只需将其放在网站上就可以从数据库中提取单词

<?=$aset['SiteTitle']?>

How can I do this in codeigniter? 如何在Codeigniter中执行此操作? Do I need to have a controller to do this or is it something much simpler than that. 我是否需要一个控制器来执行此操作,还是比这更简单的操作?

You'll need to become familiar with the concepts of MCV which is how Codeigniter is built on and your ORM framework. 您需要熟悉MCV的概念,这是Codeigniter的构建方式以及您的ORM框架。

There's a bunch of helpful resources on http://tutorialcodeigniter.com/ or the official docs http://ellislab.com/codeigniter/user-guide/database/examples.html http://tutorialcodeigniter.com/上或官方文档http://ellislab.com/codeigniter/user-guide/database/examples.html上有大量有用的资源

as an example 举个例子

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

foreach ($query->result_array() as $row)
{
    echo $row['title'];
    echo $row['name'];
    echo $row['email'];
}

I strongly recommend to use Datamapper along with CodeIgniter. 我强烈建议将Datamapper与CodeIgniter一起使用。 You will be surprised on how it is easy to work with your MySQL database. 您将对使用MySQL数据库的便捷性感到惊讶。

Say goodbye to "mysql_fetch_array" 's and such. 告别“ mysql_fetch_array”等。

Have a look : http://datamapper.wanwizard.eu/pages/getadvanced.html 看看: http : //datamapper.wanwizard.eu/pages/getadvanced.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM