catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.84k stars 1.15k forks source link

[fix] Warning: preg_match(): Compilation failed: unmatched closing parenthesis at offset 58 #933

Closed yanaleksandrov closed 3 years ago

yanaleksandrov commented 3 years ago

Hi, I call the select method.

$database = new Medoo([
    'database_type' => 'mysql',
    'database_name' => 'name',
    'server' => 'localhost',
    'username' => 'your_username',
    'password' => 'your_password'
]);
$data = $database->select( 'commentmeta', '*' );

The error occurs in the line with preg_match.

protected function selectContext( $table, &$map, $join, &$columns = null, $where = null, $column_fn = null ) {
 preg_match( '/( ?<table>[a-zA-Z0-9_]+ )\s*\( ( ?<alias>[a-zA-Z0-9_]+ )\ )/i', $table, $table_match );

$table param have string commentmeta

And an error appears Warning: preg_match(): Compilation failed: unmatched closing parenthesis at offset 58 Tell me what the problem is. and how to solve it?

catfan commented 3 years ago

Did you change the code format of source code?

yanaleksandrov commented 3 years ago

Did you change the code format of source code?

I'm sorry, I didn't understand you.

catfan commented 3 years ago

We tested it and there is no problem for using $database->select("table", "*");.

But I found the code you post above is not the same as source code. https://github.com/catfan/Medoo/blob/2d675f73e23f63bbaeb9a8aa33318659a3d3c32f/src/Medoo.php#L993

It seem your Medoo code has changed. Why there is a blank space from the regex? And that absolutely not work with error.