Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update with column has restracted word #21

Open
andaroid opened this issue Nov 16, 2023 · 2 comments
Open

update with column has restracted word #21

andaroid opened this issue Nov 16, 2023 · 2 comments

Comments

@andaroid
Copy link

andaroid commented Nov 16, 2023

use \InitPHP\Database\Facade\DB;
$data = [
    'title'     => 'New Title',
    'order'     => '1',
'content'   => 'New Content',
];

$isUpdate = DB::from('post')
                ->where('id', 13)
                ->update($data);
    
/**
* This executes the following query.
* 
* UPDATE post 
* SET title = "New Title", content = "New Content"
* WHERE id = 13
*/
if ($isUpdate) {
    // Success
} else {
    $errors = DB::getError();
    foreach ($errors as $errMsg) {
        echo $errMsg;
    }
}

Firstly thanks for nice library :D and please keep good updating of it

this code above will give error
Fatal error: Uncaught InitPHP\Database\Exceptions\SQLQueryExecuteException: 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 'order = 1

the problem is column "order" is restracted in mysql and must escaped with ``
how to do that with update function ??

@muhammetsafak
Copy link
Member

I will deal with it as soon as possible.

@muhammetsafak
Copy link
Member

Hello, you can get a quick reaction to solve your problem as follows.

$data = [
    'title'          => 'New Title',
    '`order`'       => '1',
    'content'    => 'New Content',
];

$isUpdate = DB::from('post')
                ->where('id', 13)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants