So I made the rookie mistake of putting a dash in the name of my MySQL database (ie My-Database ). After upgrading to Laravel 4.2, none of my repos worked. Here’s what I discovered:
Don’t put a dash in your db name…use an underscore. Duh.
If you have a dash in the name, and are getting errors as I did, the error is being thrown from: Illuminate\Database\Connectors\MySqlConnector line 26 using the "connect" method. This method picks up (verbatim) the database name you specified in the app/config/database.php file.
In order to bypass the error, single quotes (tilde key) must be added to the db name .
Adding the quotes to the db name within the app/config/database.php file does not work.
The following snippet within the Illuminate\Database\Connectors\MySqlConnector "connect" method solved the problem:
Original (starting at line 22):
if (isset($config['unix_socket']))
{
$connection->exec("use {$config['database']};");
}
Modified:
if (isset($config['unix_socket']))
{
$dbName = $config['database'];
if(strpos($dbName, '-')) // if the db name contains a dash
{
$config['database'] = '`'.$dbName.'`'; //add single quotes to db name
}
$connection->exec("use {$config['database']};");
}
If anyone has a tidier way of approaching this, I would love the feedback.
Thanks! Chris
You don't have to check if a dash exists, you should be able to just add the ticks regardless.
@DrPrez: I attempted a name change using a similar method to the one you posted. I actually just completed the name change successfully using the terminal with the following command line:
mysqldump -uroot -proot --protocol=socket -S mysql.sock My-Database | mysql -uroot -proot --protocol=socket -S mysql.sock my_database
I was treading lightly as I have active records that I did not want to lose, but this method worked nicely. Thanks for the feedback.
Chris
@aheinzm: I thought the same thing, but apparently the ticks are not picked up or added to the value that is placed in the app/config/database.php file. I'm learning the ropes, so everyday is a journey. Thanks for the feedback.
Chris
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community