Joomla and MySQL

2019-02-25 05:17发布

问题:

Is there specific documentation available on Joomla regarding making database queries via MySQL in PHP?

What I'm really looking for:

  • Whether or not Joomla has it's own database wrapper implemented, and if not, is it recommended to create one using the specified config parameters.
  • Whether or not Joomla has the capability to parameterize their queries to prevent SQL injection.

回答1:

Yes, Joomla has it's own OOP defined to deal with databases.

Usually, you will deal with code like this:

$db =& JFactory::getDBO();

$query = "SELECT * FROM #__example_table WHERE id = 999999;";
$db->setQuery($query);

Can read more here: How to use the database classes in your script



回答2:

Yes, it has its own class, it's the class JDatabase if I recall correctly. There's an API page where you get all the documented code on the framework.

A this Joomla WIKI, then, you have example on how to use the database class. Don't know if updated to the latest (1.7) version, but I'm pretty sure it works the same (at least did for the 1.6)



标签: php mysql joomla