erand
(Erandbraho)
1
Hi All,
I am executing an SQL script this way:
public function actionMigrate(){
$connection = Yii::app()->db;
$sql = file_get_contents('migration_script.sql');
$command = $connection->createCommand($sql)->execute();
If I run the file in sql console it shows the erros (if it has any), but if I run the action above it does not show the errors…
How do I show the errors?
Bizley
(Bizley)
2
Have you tried to try-catch them?
erand
(Erandbraho)
3
Yes like this:
public function actionMigrate(){
$connection = Yii::app()->db;
try{
$sql = file_get_contents('migration_script.sql');
$command = $connection->createCommand($sql)->execute();
}
catch (Exception $e){
throw new CDbException('Test');
}
Still it does not show the error…
Bizley
(Bizley)
4
What do you see with
catch (Exception $e) {
var_dump($e->getMessage());
die();
}
erand
(Erandbraho)
5
I don’t see anything with var_dump…
The action runs as if it doesn’t catch any error at all…
Bizley
(Bizley)
6
So… are you sure there are errors?
erand
(Erandbraho)
7
Well, if I run the sql query in phpmyadmin I get the error…but if I run that action containing this query, it does not show any error…
Bizley
(Bizley)
8
Ok, so tell us what shows when you add
var_dump($sql);die();
before $command.
erand
(Erandbraho)
9
it shows the whole script…
Bizley
(Bizley)
10
Well, since I don’t have much time for this ping-pong:
-
How many queries are inside the file?
-
If more than one - can you do that? I have never tried it before.
-
I don’t know what error you got from phpmyadmin so cannot help with that.
erand
(Erandbraho)
11
Thank you Bizley for your time.
You were right, I tried with a single query and it works (it shows the error)…but the file has a lot of queries…
I can not do try-catch for each query when I have more than 100 queries!
Does anyone knows how to catch the error from a group of queries?
Bizley
(Bizley)
12
Do you need something that allows to execute queries from the file? I mean like more than once?
Google show something like this http://www.yiiframework.com/forum/index.php/topic/28947-execute-sql-file-in-migration/