简体   繁体   English

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

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

I am using the below code to connect to the database in the module to write the several database queries which are not correct it seems, so please tell me what is the correct way of connecting to the database from the new module. 我正在使用以下代码连接到模块中的数据库,以编写一些看起来不正确的数据库查询,因此请告诉我从新模块连接到数据库的正确方法是什么。

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

I am new to the PrestaShop. 我是PrestaShop的新手。 help me. 帮我。

use 采用

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

you do not need anything else to make a query 您不需要其他任何查询

Just include these files and thats it! 只要包括这些文件就可以了!

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

And after all you can use methods as Matteo told u. 毕竟,您可以使用Matteo告诉您的方法。 Or read more here ( http://doc.prestashop.com/display/PS15/DB+class+best+practices ) 或在此处了解更多信息( http://doc.prestashop.com/display/PS15/DB+class+best+practices

Please, before read this guidelines to create a new module: How to create a module 请在阅读本指南以创建新模块之前: 如何创建模块

And then this: Best practices of the Db Class 然后是: Db类的最佳实践

Including the files like the elPresta says it's old and deprecated method, after that to make a simple query, read what he wrote Matteo Enna . 包括诸如elPresta类的文件说,它是一种过时的,过时的方法,然后进行简单查询,请阅读他写的Matteo Enna

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

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