i am creating restful api, i have created my model in codeignter 4 and in controller when i try to fetch record it gives me this 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 'IS NULL
ORDER BY `id` DESC' at line 3;
am fetching like in controller
$model = new PlacesModel();
$data['places'] = $model->orderBy('id', 'DESC')->findAll();
return $this->respond($data);
i did not mentioned any null or limit then why am getting this ?
I am trying to set pagination in Laravel 5.1, here is what I am trying to do:
$bridal_requests_data = \DB::table('bridal_requests')->leftJoin('audiences', function($join) {
$join->on('bridal_requests.id', '=', 'audiences.request_id');
})
->orderBy('bridal_requests.id', 'DESC')->paginate('15', array('bridal_requests.*'));
it is giving the following error:
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 '*) as aggregate from bridal_requests left join audiences on bridal_requests' at line 1 (SQL: select count(bridal_requests.*) as aggregate frombridal_requestsleft joinaudiencesonbridal_requests.id=audiences.request_id`)
As stated above, it is not working for bridal_requests.*, but if I use brial_requests.id then it works, but I need to use get all data from bridal_requests table.
You should use:
$bridal_requests_data = \DB::table('bridal_requests')->select('bridal_requests.*')->leftJoin('audiences', function($join) {
$join->on('bridal_requests.id', '=', 'audiences.request_id');
})
->orderBy('bridal_requests.id', 'DESC')->paginate(15);
I'm trying to log errors from my codeigniter web app and I think the messages that get written to file are getting truncated. I say this because whenever the error is displayed on screen I get the file name where the error occurred whereas when I check the error logs it only says,
Query 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 24
Is there a way to have the error log return the file location of the error?
No, currently there isn't a built-in way to do this in CodeIgniter.
What you can do is to extend the core CI_Log class, override its write_log() method and use debug_backtrace() to get the appropriate file name and prepend it to the message.
// application/core/MY_Log.php
class MY_Log extends CI_Log {
public function write_log($level, $msg)
{
foreach (debug_backtrace() as $call)
{
// Somehow find the appropriate call here ...
if ( ! (/* condition to ignore error-handling calls */))
{
break;
}
$msg = '['.$call['file'].'] '.$msg;
break;
}
return parent::write_log($level, $msg);
}
}
Error comes when i run update stored procedure in laravel5 like this..
QueryException in Connection.php line 620:
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 'Sandeep,09999999999,,,sandeep#gmail.com,,,,,,,)' at line 1 (SQL: call sp_clientupdate(108, Sandeep,09999999999,,,sandeep#gmail.com,,,,,,,))
my code is....
return DB::select('call sp_clientupdate(108, Sandeep,0999999999,,,sandeep#gmail.com,,,,,,,)');
Pls anyone give me solution.....
Try this one,
DB::statement('call sp_clientupdate("108", "Sandeep","0999999999","","","sandeep#gmail.com","","","","","","",)');
It works perfectly.
You change.
return DB::select('call sp_clientupdate("108", "Sandeep","0999999999","","","sandeep#gmail.com","","","","","","",)');
Try it's working perfectly....
I've got a custom database class which extends the MySQLi class.
It connects to the database using parent in the __construct method.
Below is the portion of the query if the query is not successful, how do I return the error from the server?
$query = parent::query($querystr, $resultmode);
if (!$query) {
$error = str_replace(
'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use',
'Syntax Error',
mysqli_error(self::getInstance()));
\core\debug::sqlerrorlog($error);
} else {
\core\debug::sqlSuccess();
}
According to docs, you just need to do $this->error.
As I understand, your problem now is that you don't pass a correct intsance of mysqli to mysql_error - maybe self::getInstance() is not doing what it supposed to, but I can't tell from what I see.