在 PrestaShop 中创建新模块时,如何不使用 mysql_connect 连接到数据库

How do I connect to the database with out using the mysql_connect when creating the new module in PrestaShop

我正在使用下面的代码连接到模块中的数据库来编写几个看起来不正确的数据库查询,所以请告诉我从新模块连接到数据库的正确方法是什么.

$con = mysql_connect(_DB_SERVER_, _DB_USER_, _DB_PASSWD_);
mysql_select_db(_DB_NAME_);

使用

$query ="select * from name_table"; /*example query*/
Db::getInstance()->executeS($query);

您不需要其他任何东西来进行查询

只需包含这些文件即可!

include(dirname(__FILE__).'/../../config/config.inc.php');
include(dirname(__FILE__).'/../../init.php');

毕竟你可以使用 Matteo 告诉你的方法。或者在此处阅读更多内容 ( http://doc.prestashop.com/display/PS15/DB+class+best+practices )

请先阅读本指南以创建新模块:How to create a module

然后是:Best practices of the Db Class

包括像elPresta这样的文件说它是旧的和不推荐使用的方法,之后做一个简单的查询,阅读他写的Matteo Enna