vendredi 27 mai 2016

DB::select returning different results than mysql command line

I'm trying to rename some columns in a MySQL database, but unfortunately the table contains an enum so doctrine\dbal throws an error. I decided to write my own rename function using raw sql, but some of the checks I'm putting into place are failing and I don't know why.

When I'm in the MySQL CLI, I run this query:

select table_name from information_schema where table_name = "my_table" and table_schema = "my_schema";

This returns one row with the table name, as expected. So I figured in my migration, I could do this:

$exists = Schema::hasTable('my_table');

but that returned false. Weird, I thought, so let's take the whole Schema thing out of the equation and just try straight sql against information_schema.

$result = DB::select('select table_name from information_schema where table_name = ? and table_schema = ?', ['my_table', 'my_schema']);

However, when I run that statement, the value of $result is []. I thought maybe the compiled sql might be wrong, so I dumped out the return from DB::getQueryLog(), but it all looks correct:

array:1 [
    0 => array:3 [
        "query" => "select table_name from information_schema.tables where table_name = ? and table_schema = ?;"
        "bindings" => array:2 [
            0 => "my_table"
            1 => "my_schema"
        ]
        "time" => 0.01
    ]
]

I should point out that when I run php artisan tinker and run that same DB::select() statement, I get the results I'm looking for, so it seems that it's not working just within the migration file.

I'm at a loss. Why would DB::select() return different results than running the exact same query on the MySQL CLI?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire