I have a custom php script that was written for a Joomla 3 site.
Of course on Joomla 4 it doesn't work.
I've been working on re writing the query statements to use prepared statements but even with the simplest dumbed down query I get a 500 error
Working off https://docs.joomla.org/J4.x:Selecting_data_using_JDatabase
<?php
// Connect to Joomla!
define( '_JEXEC', 1);
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE', realpath(dirname(__FILE__) .'/' ) );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
//using new use statement instead of JFactory
use Joomla\CMS\Factory;
//copied from
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('*')
->from($db->quoteName('#__content'))
->setLimit('10');
$db->setQuery($query);
$result = $db->loadResult();
?>
What am I missing for a custom script to work on Joomla 4 ?
If I get that far I can maybe figure out the prepared statements for this: It's an inner join between custom fields table, content and categories
$query = $db->getQuery(true);
$query
->select($db->quoteName(array('v.item_id','cat.alias','c.title','c.alias','c.images','c.introtext','v.value'), array('item_id','category','title','alias','images','introtext','college')))
->from($db->quoteName('#__fields_values', 'v'))
->innerJoin($db->quoteName('#__content', 'c') . ' ON v.item_id = c.id')
->innerJoin($db->quoteName('#__categories', 'cat') . ' ON c.catid = cat.id')
->where($db->quoteName('v.field_id').'= :fieldValue')
->where($db->quoteName('c.state').'= :activeState')
->order($db->quoteName('c.title').'ASC');
->bind(':fieldValue', 5);
->bind(':activeState', 1);
$db->setQuery($query);
$articles = $db->loadObjectList();
bind()
methods. See the bottom of joomla.stackexchange.com/a/22712/12352setLimit()
? ...hmm, to my surprise, the documentation demonstrates this too: docs.joomla.org/… I guess it's time for you to turn your error reporting all the way up and check the stacktrace / error logs.