SELECT `id`, `name_person`, `person_content`, `datetime`
FROM (`achievers_unverified`)
WHERE ` name_person LIKE '%ved%'
OR ` person_content LIKE '%ved%' LIMIT 10
This is the sql query i am trying to use where ved is the search term.
i am gettin a 1064 error.
the codeigniter code generating it is.
$this->db->select($select)
->from($table)
->like($str[1], $query, 'both')
->or_like($str[2], $query, 'both')
->limit($offset+10, $offset);
this is the 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 'person_content LIKE '%ved%' LIMIT 10' at line 3.
$str = explode(",", $select);
where $select = id, name_person, person_content, datetime
found the solution use trim($str[0]) and trim($str[1]) the sapce was creating the problem.
Related
I want to get a time difference from data using the TIMESTAMPDIFF function, but this time i want to use a pure query builder in codeigniter
$this->db->select("TIMESTAMPDIFF(DAY, (".$this->db->select('payment_date')."), (".$this->db->select('download_date').")))",FALSE);
$query = $this->db->get('transaksi');
return $query;
I've tried the code above, but it shows an error like this :
Severity: 4096 Message: Object of class CI_DB_mysqli_driver could not
be converted to string
and like this :
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 '), ())) FROM transaksi' at line 1
SELECT payment_date, download_date, TIMESTAMPDIFF(DAY, (), ())) FROM
transaksi
is there any solution to get the data?
Solution:
$this->db->select("payment_date, download_date, TIMESTAMPDIFF(DAY, payment_date, download_date)",FALSE);
$query = $this->db->get('transaksi');
return $query->result();
Sub Query not necessary there.
$this->db->select("payment_date, download_date, TIMESTAMPDIFF(DAY, payment_date, download_date)",FALSE);
$query = $this->db->get('transaksi');
return $query->result();
I am trying to execute this mySQL query in PHP.
$sql = "SELECT * FROM Property
WHERE CONCAT(name, '',
contact_number , '',
hostel_address,'',
renter_name,'',
other_details,'',
date_posted,'') LIKE '%".$var."'
ORDER BY STR_TO_DATE(date_posted,'%d/%m/%Y')";
An I am getting following 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 'ORDER BY STR_TO_DATE(date_posted,'%d/%m/%Y') ASC' at line 1
Any help here :(
may try this:
$sql = "SELECT * FROM Property WHERE CONCAT(name, '',contact_number , '', hostel_address,'',renter_name,'',other_details,'',date_posted,'') LIKE '%".$var."' ORDER BY STR_TO_DATE(date_posted,'%d/%m/%Y')";
Note that there should be an ending single quote before ORDER BY
I used Like operator and pass all the parameter But Still the following code is not working:
public function get_locations($lang, $suggest){
$this->lang = $lang;
$this->suggest = $suggest;
$sql = "SELECT l.location_id, l.location_name_col
FROM test_db.location_translations as l
WHERE l.location_name_col like LIKE :suggest
AND l.language_code = :lang
";
$params = array(':suggest'=>"%".$this->suggest."%", ':lang'=> $this->lang);
$stmt = $this->conn->prepare($sql);
$stmt->execute($params);
}
I am getting the following erros:
PDOException' with message '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 'LIKE '%A%'
AND l.language_code = 'en'' at line 3
please help me.
Well looking at your error code the problem has to do with the 'LIKE' parameter, I see that you are using 'like' and 'LIKE'. I think it should look like this:
$sql = "SELECT l.location_id, l.location_name_col FROM
test_db.location_translations as l WHERE l.location_name_col LIKE
:suggest AND l.language_code = :lang ";
What if you run it again with the above code, what happens then?
By executing below query i getting this error message
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 'status=1' at line 1 SELECT username,useremail FROM tbl_cart where user_id= 8AND status=1
query
$query = $this->db->query('SELECT username,useremail FROM tbl_cart where
user_id= '.$this->session->userdata('userId').'AND status=1' );
$resultdata['results'] = $query->result_array();
You need to insert an space before AND
$query = $this->db->query('SELECT username,useremail FROM tbl_cart where
user_id= '.$this->session->userdata('userId').' AND status=1' );
^ here
The better way to do it with CI is
$query = $this->db->select('username, useremail')
->where('user_id', $this->session->userdata('userID'))
->where('status',1)
//instead of from CI does get
->get('tbl_cart')->result_array();
result_array() returns the results as an array of arrays while result returns query as an array of objects
if you are using CI it is better to fully take advantage of the query builder classes
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.