I'm getting this error :
Warning: PDO::query() [pdo.query]: 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 'When, RDV, Comments FROM distributions WHERE IDFond = 1' at line 1 in /Applications/XAMPP/xamppfiles/htdocs/JG/DistributionManager.class.php on line 56
When executing this code :
$Distribution_Manager->getListByFunds($Selected_Fond->id());
foreach ($Distribution_Manager as $Distrib)
{
echo $Distrib->Comments();
}
Here is the concerned function :
public function getListByFunds($FundID)
{
$Distribution = array();
$q = $this->_db->query('SELECT id, IDClient, IDFond, Who, When, RDV, Comments FROM distributions WHERE IDFond = '.$FundID);
while ($donnees = $q->fetch(PDO::FETCH_ASSOC))
{
$Distribution[] = new Distribution($donnees);
}
return $Distribution;
}
Should be a little mistake but I'm lagging on it for almost 50 minutes !
Thanks in advance for the help ;)
WHEN is a mysql reserved word, so try using a different column name or enclose WHEN in backquotes.
When is mysql keyword, try this
SELECT id, IDClient, IDFond, Who, When AS anything..
or enclose this keyword to backquotes
SELECT id, IDClient, IDFond, Who, `When`, RDV..
Give back quotes for column names like id and try it
You're never closing your quotes on your statement.
Related
Hello stackoverflow community, I need help with this mysqli query. My auto increase column in database is ZERO-FILL element for example 00001 so when I try to query like this:
$stmt = $mysqli->query("UPDATE ".$db_table_prefix."korteles
SET
vardas = '".$this->clean_k_name."',
pavard = ".$this->clean_k_surname.",
WHERE korteles_nr = '00001'");
And I get error:
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 'WHERE korteles_nr = 00001' at line 18
I was searching Internet for solving this problem. But can't find so please help!
Query should be like this:-
$stmt = $mysqli->query("UPDATE ".$db_table_prefix."korteles
SET
vardas = '$this->clean_k_name',
pavard = '$this->clean_k_surname'
WHERE
korteles_nr = '00001'");
You have to remove the comma after $this->clean_k_surname variable
Is now 6am in the morning and i'm still struggling to execute a query with the CodeIgniter PHP framewok. Hope you guys can help me
Code:
$query='
UPDATE `STUDY_LIST_AUX`
INNER JOIN `study_report`
ON `STUDY_LIST_AUX.study_iuid`=`study_report.study_iuid`
SET `STUDY_LIST_AUX.report_date`=DATE_FORMAT(`study_report.report_date`,\'%Y-%m-%d %h:%i:%s\'), `STUDY_LIST_AUX.report_status` = `study_report.report_status`
';
if ($this->db->query($query))
{
echo "True!<br><br>";
}
else
{
echo "False<br><br>";
};
Error:
A Database Error Occurred
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 'UPDATE STUDY_LIST_AUX INNER JOIN study_report ON `STUDY_LIST_AUX.study_iu' at line 22
I've tried everything, backticks, normal ticks, quote marks, but the error persists. On phpmyadmin the query run successfully.
Any suggestions or ideas will be much appreciated
Thanks in advance guys :)
You can update your query code using this below Active Record code
$data = array('s.report_date' => 'DATE_FORMAT(`study_report.report_date`,\'%Y-%m-%d %h:%i:%s\')','s.report_status' => 'sr.report_status');
$this->db->update('STUDY_LIST_AUX s JOIN study_report sr on s.study_iuid = sr.study_iuid',$data);
This'll help you...
try this. use double quote so you don't have to worry the quote inside
$query="UPDATE STUDY_LIST_AUX
INNER JOIN study_report
ON STUDY_LIST_AUX.study_iuid = study_report.study_iuid
SET STUDY_LIST_AUX.report_date =
DATE_FORMAT(study_report.report_date,'%Y-%m-%d %h:%i:%s'),
STUDY_LIST_AUX.report_status = study_report.report_status";
You have some syntax issue in the query ex:
`STUDY_LIST_AUX.study_iuid`
If you are using backticks then it should be as
`STUDY_LIST_AUX`.`study_iuid`
The correct query should be
$query = "
update `STUDY_LIST_AUX` sla
join `study_report` sr on sr.study_iuid = sla.study_iuid
set
sla.report_date = date_format(sr.report_date,'%Y-%m-%d %h:%i:%s'),
sla.report_status = sr.report_status
";
$query = $this->db->query('select
sum(like) as atotal
from
like
where
sfid = '.$short);<br>
print_r($query);
and the error is
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 'like) as atotal from like where sfid = 11' at line 2
select sum(like) as atotal from like where sfid = 11
Filename: C:\wamp\www\don\system\database\DB_driver.php
Line Number: 330
'like' in sum(like) is column name and 'like' after 'from' is table name
thank you in advance
$data = array(
"category_id"=>$this->input->post('category'),
"name"=>$this->input->post('name'),
"description"=>$this->input->post('descri')
);
$this->db->insert('measurement', $data);
$inserted_id = $this->db->insert_id();
like is a MySQL reserved word
http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html
which needs to be wrapped in backticks.
Either do that, or rename your table/column to something else.
Using reserved words is discouraged to be used. You can use them, but require special attention.
I suggest you rename your table to likes and your column to another word.
If renaming them isn't an option, then modify your code to read as this:
$query = $this->db->query('select
sum(`like`) as atotal
from
`like`
where
sfid = '.$short);
print_r($query);
You shouldn't use like keyword in your query.
It is sql-specific word treated as special keyword. To solve this task, you should change column name in database table or wrap like keyword in backticks either:
$query = $this->db->query('select sum(`like`) as atotal from `like` where sfid = '.$short);
You can still use it. Just use `like` instead of like OR change the table name. The backQuote helps to override the MySql keyword override.
I have a basic query which gets all fields and exports the file but it keeps giving me an error. My code looks like this:
$array = ['users'];
foreach($array AS $i){
$file = $i.'.sql';
$stmt = $pdo->prepare("SELECT * FROM ? INTO OUTFILE ?");
try {
$stmt->execute(array($i,$file));
} catch (PDOException $e) {
$log .= $e -> getMessage().'........ \n ';
}
}
I keep getting this error how ever:
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 ''users' INTO OUTFILE 'users.sql'' at line 1.
What is the correct syntax for this ?
It(Syntax) should be the other way around
SELECT * INTO OUTFILE ? FROM ?;
See the documentation here
EDIT :
As JAL clarified, The table name cannot be passed as a parameter under a PreparedStatement. So your query should be like
SELECT * INTO OUTFILE ? FROM users;
You cannot prepare a statement where the table name is a parameter.
See Can PHP PDO Statements accept the table or column name as parameter?
$sql="SELECT count(actid) AS tr
FROM useractions ua
WHERE qid=-1
OR qid IN (
SELECT qid
FROM questions q
WHERE q.visible=".VISIBLE."
)
AND ua.actid =".$actid;
The query above gives this error:
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
Whats wrong with the statement?
I did a dump and got this:
string "SELECT count(actid) AS tr
FROM useractions ua
WHERE qid=-1
OR qid IN (
SELECT qid
FROM questions q
WHERE q.visible=1
)
AND ua.actid =" (length=270)
$actid is the result of another query, shown below. It's then passed to the function that has the query show above.
foreach ($_POST['q'] as $qid) {
list($actid) = mysql_fetch_row(mysql_query("SELECT actid FROM useractions WHERE qid='$qid'"));
upd_facts_status($actid);
}
Verify that the VISIBLE constant has a value and that the $actid variable has a value.
Probalby a typo - VISIBLE is a constant? And if it is a string, it should be in quotes.
You should enable all error messages too:
ini_set("display_errors", true);
error_reporting(E_ALL);