Skip to content

update with column has restracted word #21

@andaroid

Description

@andaroid
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 ??

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions