php-migration: [Sql Server] Error migrating tables
Hello, thanks for sharing this library.
Sorry for a newbie question.
I am trying to use this library with Sql Server
but I receive this error message
-- Error migrating tables --
How to Reproduce:
Run SqlServer on docker
docker run --name sql1 -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=!@#p455qwe' -p 11433:1433 -d mcr.microsoft.com/mssql/server:2017-latest
Install Database Migrations(CLI) on mac
composer require 'byjg/migration-cli=4.0.*'
Change test_sqlserver.php like this
<?php
require __DIR__ . "/../../vendor/autoload.php";
/**
* Make sure you have a database with the user 'migrateuser' and password 'migratepwd'
*
* This user need to have grant for DDL commands;
*/
$uri = new \ByJG\Util\Uri('dblib://sa:!@#p455qwe@localhost:1433/MyDBName');
$migration = new \ByJG\DbMigration\Migration($uri, __DIR__);
$migration->registerDatabase('dblib', \ByJG\DbMigration\Database\DblibDatabase::class);
$migration->prepareEnvironment();
$migration->reset();
Run this command
~ $ vendor/bin/migrate create /Users/a/test
Created UP version: 1
Created DOWN version: 0
~ $ vendor/bin/migrate install --path /Users/a/vendor/byjg/migration/example/sql_server mssql://localhost:1433/DragonRunner
-- Error migrating tables --
I can connect to sql using this http://localhost:8080/indexSQL.php
<?php
$serverName = "172.18.0.4,1433";
$connectionInfo = array("DATABASE"=>"MyDBName","UID"=>"sa","PWD"=>"!@#p455qwe");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
?>
Question 1: Please tell step by step how to use this library with sql server, what file need to change sql user and password and server address and how to test the connection established.
Question 2:
How to find more details of this -- Error migrating tables --,
such as if the error is because the connection failed
Mac php version
$ php -v
PHP 7.3.11 (cli) (built: Jun 5 2020 23:50:40) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 18 (11 by maintainers)
I am glad to know that the solution is working.
About why
localhostis not working inside the docker container is something expected because of the containerization technology. Basically, when a container is runnning the containerization technology isolates the container from the host machine. It means the container cannot share network, folders, services with the host unless explicitly stated. When you run the container with the--portor--volumewe are saying to map container port or volume with the host. Inside the container thelocalhostis the container itself, and it explain why it works when you changed fromlocalhosttosql1.