As the title suggests, I have a query that works fine in localhost but on my live environment I get a 500 server error. My PHP version locally is 7.4 but the live server uses 7.3.
The error I get is
PHP Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation:
1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL
server version for the right syntax to use near '(partition by prop_slug order by
prop_client) as rn
FROM listing_details
JOI' at line 4 in /hermes/bosnaweb23a/b60/ipg.site/site/index.php:23
Stack trace:
#0 /hermes/bosnaweb23a/b60/ipg.site/site/index.php(23): PDOStatement->execute()
#1 {m
My query looks like the below, but as I said this works fine in the local environment.
$get_listings = $db->prepare('SELECT *
FROM (
SELECT *,
row_number() over(partition by prop_slug order by prop_client) as rn
FROM listing_details
JOIN prop_gallery
ON prop_gallery.prop_gallery_id = listing_details.prop_slug
WHERE prop_slug LIKE prop_gallery_id OR prop_gallery_id LIKE prop_slug
AND listing_details.prop_mandate = 1
) x
where rn = 1');
$get_listings->execute();
$listings = $get_listings->fetchAll();
if (!$listings) {
echo 'Error: No Listings.';
}
Related
I am trying to get the value from MySQL subqueries but I am getting 'Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1'
The code is:
UPDATE national_avg_tariff SET Value= (CASE WHEN ((SELECT * FROM((SELECT Value
/ ((Select Sum_CPP_MlnRs from ppp_fy2020_2030_annex4.FY_CPP_exclKE_MlnRs where FiscalYear=2020) + (Select UoSC_MoF_exclKE_MlnRs from ppp_fy2020_2030_annex4.FY_UoSC_MoF_exclKE_MlnRs where FiscalYear=2020))/ (SELECT Sum(Sum_of_AvgMW) FROM ppp_fy2020_2030_annex4.AVG_OF_FY_MAX_DEMAND where FiscalYear=2020 GROUP BY FiscalYear)FROM tariff_true_cost.national_avg_tariff WHERE Sector='Residential' AND Category='Up to 50 Units' AND Parameter= 'Fixed Charge(Rs/kW/M)' AND FiscalYear=2020)temptbl8))>0)
THEN
(SELECT * FROM((SELECT Value
/ ((Select Sum_CPP_MlnRs from ppp_fy2020_2030_annex4.FY_CPP_exclKE_MlnRs where FiscalYear=2020) + (Select UoSC_MoF_exclKE_MlnRs from ppp_fy2020_2030_annex4.FY_UoSC_MoF_exclKE_MlnRs where FiscalYear=2020))/ (SELECT Sum(Sum_of_AvgMW) FROM ppp_fy2020_2030_annex4.AVG_OF_FY_MAX_DEMAND where FiscalYear=2020 GROUP BY FiscalYear)FROM tariff_true_cost.national_avg_tariff WHERE Sector='Residential' AND Category='Up to 50 Units' AND Parameter= 'Fixed Charge(Rs/kW/M)' AND FiscalYear=2020)temptbl8))
ELSE NULL END) where FiscalYear=2020 AND Parameter='Fixed Charge(%)';
The code doesn't show any red underline or pre-execution error something, the error only appears once I execute it.
Any help in rectifying syntax error of this piece of code would be appreciable. Thanks
I have a problem with my request, the request doesn't recognized WITH(). I work on Ubuntu & MySQL, can I get help please!
DB::select(DB::raw("WITH liststudentsoff as (
SELECT tbl_etudiants.*, tbl_cours.idCours FROM dependance_groupes
inner join tbl_etudiants on tbl_etudiants.idStudent = dependance_groupes.studentID
inner join tbl_cours on tbl_cours.groupID = dependance_groupes.groupID
inner join tbl_formations on tbl_formations.idFormation = tbl_cours.formationID
)
SELECT * FROM liststudentsoff
LEFT JOIN tbl_absences ON liststudentsoff.idStudent = tbl_absences.studentID AND liststudentsoff.idCours = tbl_absences.coursID
WHERE liststudentsoff.idCours = ".$request->idCours." and liststudentsoff.formationID = ".$cours->formationID.""));
Error display:
[previous exception] [object] (PDOException(code: 42000): SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'liststudentsoff as (
SELECT tbl_etudiants.*, tbl_cours.idCours FROM ' at line 1 at /var/www/html/emarge-backoffice/vendor/laravel/framework/src/Illuminate/Database/Connection.php:338)
when select images from a database below error is shown & after i delete record in the database its remain the same number inside (id)
this is the error
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL
server version for the right syntax to use near '16,19,1,2,1,2,1 )' at line 1
select * from images where id in(,16,19,1,2,1,2,1 )
Filename: controllers/Admin.php
Line Number: 1046
and this is select statment :
if (!empty($data->images)) {
$qry = $this->db->query("select * from images where id in($data-
>images )");
$res['results'] = $qry->result();
}
and now my database is empty and this error still remaining ?
just remove the leading comma. like this.
select * from images where id in( 16,19,1,2,1,2,1 )
there is a leading comma in $data->images
I am trying to do an LEFT Join in Yii v.1 Mysql .
There are alreday 4 tables joined and I want to join this table also.
$cmd = Yii::app()->db->createCommand();
$selectString .= "table2.dir_pic, table2.pic1, table2.pic2 , table2.pic3 ";
$cmd->select($selectString);
$cmd->from('table1');
$cmd->leftjoin('table2', 'table1.id=table2.user_entry_id');
$entries = $cmd->queryAll();
$this->render('index', compact('entries', 'model'));
It is giving an CDbException
CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '.`dir_pic`, `table2`.`pic1`, `table2`.`pic2`, ' at line 1.
I tried this query in mysql(phpmyadmin)
SELECT table1.id,table2.dir_pic,table2.pic1,table2.pic2, table2.pic3 FROM
table1 LEFT JOIN table2 ON table1.id = table2.user_entry_id
and It shows proper output.BUt not when I try in Yii .
I found the solution. Actually I missed an comma (,) after the end of previous $selectString query.
I have this query in Perl:
my $pkg="%";
my $sql = "SELECT pid, CAST(pid as UNSIGNED) AS l FROM xmld ORDER BY l WHERE pkg LIKE ?";
my $files_ref = $dbh->selectcol_arrayref($sql, undef, $pkg);
It crashes with:
DBD::mysql::db selectcol_arrayref failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE pkg LIKE '%'' at line 1 at ...
I have been looking at this statement for hours, tried various things, but no luck.
Where is that extra single quote coming from and how do I get rid of it?
order by goes after the where:
SELECT pid, CAST(pid as UNSIGNED) AS l
FROM xmld
WHERE pkg LIKE ?
ORDER BY l;