8
votes
Accepted
SQL Injections using Jfactory::getDBO and setQuery() with LIKE condition
You won't need to worry about sql injection attacks if you use the quote() ( or q()) and quoteName() (or qn()) methods appropriately.
From https://docs.joomla.org/Secure_coding_guidelines#...
5
votes
Accepted
What does sql_select="e.*" do?
I guess the example you are talking about is this:
"SELECT e.* FROM #__example AS e GROUP BY name ORDER e.id ASC"
Ths basically mean select everything from the table #__example (which has an alias ...
4
votes
Accepted
Issues to be aware of when calling `concatenate()`, `regexp()`, `rand()`, and `castAsChar()` in sql queries
All of my demonstrations will assume this line is already declared:
$db = JFactory::getDBO();
I will also provide a "guinea pig" table as a demo reference and playground for researchers when sample ...
4
votes
Accepted
(RuntimeException $e) vs (JDatabaseExceptionExecuting $e) for SQL exception handling
The difference between a RuntimeException and a JDatabaseExceptionExecuting is a matter of semantics and inheritance.
In PHP, RuntimeException extends the Exception class (the base class -- which ...
3
votes
The MySQL adapter mysqli is not available - how to resolve this issue?
I had this error after a reboot on one site of 12 on my server. All my sites are Joomla. We recently upgraded to php7.1 I tried everything then found the fix.
The fix was to comment out the suPHP ...
3
votes
How can I get the names of the columns in an object or table with Joomla's SQL?
To get all columns of a table as arrays use JDatabase class method as follows:
$db=JFactory::getDBO();
$columnArr=$db->getTableColumns("#__table_name");
foreach ($columnArr as $key => $value) {
...
3
votes
What does sql_select="e.*" do?
When you are only referencing one table in your query, there is no need to explicitly reference the table when writing columns. Also, the default order direction for sql is ASC.
So your syntax could ...
3
votes
Accepted
Attempt to assign property "team" on bool
Well, your code is saying that $this->_item might be null (a non-object) -- if it is, you are overwriting it to be false (again, a non-object). Then, after grabbing your database results, you are ...
2
votes
Accepted
How to rewrite SQL-query with CASE/WHEN to Joomla-based "format"
I'll recommend this syntax:
$db = JFactory::getDBO();
try {
$query = $db->getQuery(true)
->select(
array(
$db->qn('b....
2
votes
How to rewrite SQL-query with CASE/WHEN to Joomla-based "format"
$query->select('a.virtuemart_product_id')
->from('#__virtuemart_product_categories AS a')
->select('(CASE WHEN '.$db->qn('b.product_override_price').' > 0
THEN '.$db->qn('b....
2
votes
Accepted
After Joomla update duplicate or create new module get id : 0
Hi Check your data base xxx_module must assign AUTO_INCREMENT STATUS, after it will be ok!
2
votes
getting some sql error
While using IN() or NOT IN() clause comma (,) separated values or empty string must be passed as parameter.
For example:
IN(1,2,3) OR IN('') OR IN('a', 'b', 'c')
2
votes
Joomla 3.4.8 Component SQL Update Not Working
For the sake of answering your actual question, it is likely to be an issue with version numbers - make sure it is above the version in the database. Also note that there is the version of Joomla in ...
2
votes
The MySQL adapter mysqli is not available - how to resolve this issue?
Most likely your hosting company made some modifications on their server or moved you to another server that doesn't have the MySQLi adapter. You can either edit the configuration.php and change $...
2
votes
Transfer Joomla data from PHPMyAdmin SQL Dump
Is the old website still accessible? If yes, then I think the safest and easiest way to transfer joomla website is to use Akeeba Backup component. You just need to install this component and then ...
2
votes
Accepted
Transfer Joomla data from PHPMyAdmin SQL Dump
You should be able to use the SQL Dump to recreate the database using phpMyAdmin or similar.
You will also need the Joomla files to be able to recreate the Joomla website.
Once the files and the ...
2
votes
Error 1146 while installing K2 extension
This situation can happen if K2 was installed in the past and not removed correctly or after a failed install attempt.
Have a look with your FTP client for either of the directories below as K2 ...
2
votes
Accepted
Rewriting code as per Joomla guide, but page showing 404 error
The short answer is because you have two queries that sort of mush together. In your 'improved code' version you build the query object and then replace the object with a string query.
I have ...
2
votes
Accepted
Convert PHP code to Jooma PHP syntax?
As @FFrewin noted, you've got a syntax issue with the extra comma before the FROM block. However, there's a few other things I'd recommend (this is untested however!):
$query->select($db->...
2
votes
Accepted
Delete row from custom made SQL when deleting article in Joomla
Create a plugin with onContentAfterDelete event. Basic example:
<?php
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\CMSPlugin;
class PlgContentExample extends CMSPlugin
...
2
votes
Accepted
How to query certain rows from a table based on other associated rows in the same table?
It is best practice to minimize the number of calls to the database.
Your logic in your two queries can be merged into one like this:
try {
$db = JFactory::getDbo();
$query = $db->...
2
votes
Accepted
Is it possible to edit the SQL custom field to be multi-select?
When creating/editing the field, set Multiple option to Yes. Or edit Fields - SQL plugin to enable multiple option globally for all SQL fields.
2
votes
Accepted
How to apply aliases in SELECT clause when two columns from JOINed tables have the same name?
Further explanation of the issue:
As you discovered, when two columns in the SELECT clause of a query share the same column name (or alias), the latter value overwrites the former in the result set. ...
2
votes
Accepted
Where to find article page title in database?
Articles are the small modular content inside the CMS content workflow, the Browser Page Title is managed by the structure of the Menú and the last part of this process comes from the direct ...
2
votes
Accepted
Joomla Select from DB AND / OR grouping
Because 0000-00-00 00:00:00 will always be less than the current datetime stamp, I am understanding your requirements as:
published = 1
AND
publish_up <= now
AND
(
publish_down = 0000-00-00 00:...
2
votes
How to use SQL statements not supported by JDatabaseQuery
As demonstrate by my answer at with insert on duplicate key update - updating multiple rows at once, I recommend using Joomla's secure query building methods, then performing any necessary surgery ...
2
votes
Accepted
Decode json strings from a database table column
It looks like you are mangling valid json data with explode() (the wrong tool for the job).
You just need to call json_decode() on each string. This can be done with array_map() or a classic foreach()...
2
votes
Accepted
After joining two tables in phpMyAdmin how do I save the results as a dynamic table?
Unless you are magically updating the new table with fresh data then you will only see the data from the initial select statement.
In this case you have a few options
populate the new table with ...
1
vote
Accepted
Retrieve article URL from phpMyAdmin
You can use jroute and contenthelperroute to get the sef urls.
JRoute::_(ContentHelperRoute::getArticleRoute($id, $catid, $language));
If you only have the article ID's you can try this without $...
1
vote
Accepted
add text after value that is retrieving from SQL in php
You simply need to add the km after the result from the database, like so:
$result = $db->loadResult();
if ($result)
{
echo $result . ' km';
}
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
sql × 94joomla-3.x × 29
mysql × 24
php × 19
jdatabase × 15
database × 10
component × 9
user × 5
joomla-4.x × 5
pivot × 5
joomla-2.5 × 4
development × 4
k2 × 4
rsform × 4
custom-field × 3
installation × 3
json × 3
phpmyadmin × 3
plugin × 2
joomla-3.4 × 2
joomla-3.3.x × 2
joomla-3.6 × 2
update × 2
form-fields-types × 2
fields × 2