I have an issue with setting mysql user-defined variables with codeigniter. How am I able to use SET with CI query builder?
SET @weekVideoCount := (SELECT COUNT(*) FROM videos v );
SELECT @weekVideoCount;
When I execute this Query on Sqlyog the result will be successfully shown but if I call this Query in the model like this
function getWeeklyUserData(){
$query= $this->db->query("SET @weekVideoCount := (SELECT COUNT(*) FROM videos v);
SELECT @weekVideoCount;
");
return $query->result();
}
the error has generated
Try separate the query
$this->db->query("SET @weekVideoCount := (SELECT COUNT(*) FROM videos v)");
$query= $this->db->query("SELECT @weekVideoCount");
you should know $this->db->query() execute only one sql statement just like mysql_query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With