catfan / Medoo

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

How do you fix ' SELECT .. WHERE ' 0? #651

Closed devhalfdog closed 7 years ago

devhalfdog commented 7 years ago

hi.

My Source

in dbtest.php

$where = "'no[<]' = 1";
$dbTest = new Medoo\Medoo([
    'database_type' => 'mysql',
    'database_name' => 'tester',
    'server' => 'localhost',
    'username' => 'test',
    'password' => 'test',

    'logging' => true
]);

$dbTest->select('test', [
    'name'
], [
    $where
]);

output Logging

array(1) { [0]=> string(55) "SELECT "name" FROM "test1" WHERE "0" = '\'no[>]\' => 1'" }

Why does the 'WHERE' section contain a $ where variable that will print 'WHERE "0" ...' in the output.

catfan commented 7 years ago

Your $where is an array with string 'no[<]' = 1 only. Check out the basic PHP array syntax.

$where = [
    'no[<]' => 1
];

$dbTest->select('test', [
    'name'
], $where);