I always used PHP 5.2.3 version, but now I updated PHP to version 5.3.2.
I have problem with MSSQL, I can`t connect to MSSQL server.
I have downloaded a SQL server driver for PHP 1.1
There are a lot of files, I used php_sqlsrv_53_ts_vc9. Put it on php/ext directory php_sqlsrv_53_ts_vc9.
I have added extension=php_sqlsrv_53_ts_vc9.dll (in php.ini), but it gives an error:
Call to undefined function mssql_connect() in C:\webserver\www\MSSQl\db_mssql.class.php on line 26
I have used:
$serverName = "$sql_server";
$connectionInfo = array( "Database"=>$sql_db_name,"UID"=>$sql_user,"PWD"=>$sql_pass);
$conn = sqlsrv_connect($serverName,$connectionInfo);
if( $conn === false )
{
echo "Could not connect.\n";
die( sqlsrv_errors());
}
Then all work!
Open php.ini ,just add this line
extension=php_sqlsrv_53_ts_vc9.dll
you need to know what compiler do you use
phpinfo();
Compiler MSVC9 (Visual C++ 2008)
Than Add it.
Related
I've read a few similar Q&As regarding PS and type conversions, but as far as I can see they're not the same situations.
I am attempting to use RMO classes in a Powershell script, but for some reason it thinks a conversion to the same type is necessary and fails to do so.
The code in question is basically:
$conn = New-Object "Microsoft.SqlServer.Management.Common.ServerConnection" #($server, $dbUsernm, $dbPasswd);
$publicationDb = New-Object "Microsoft.SqlServer.Replication.ReplicationDatabase"
$publicationDb.Name = $dbName;
$publicationDb.ConnectionContext = $conn;
(A similar type error occurs if I try to use the two-argument constructor.)
The error is:
Exception setting "ConnectionContext": "Cannot convert the "(..snip..)" value of type
"Microsoft.SqlServer.Management.Common.ServerConnection" to type "Microsoft.SqlServer.Management.Common.ServerConnection"."
So what's going on here? It's clearly trying to convert to the same data types. These aren't defined in PowerShell scripts so shouldn't it be able to track the type? I've also tried casting the variable to [Microsoft.SqlServer.Management.Common.ServerConnection] in its declaration and/or in the calls / member set, to no avail.
In case it is relevant, I'm loading the RMO classes this way (which appears to be the only working method, even though from what I understand LoadWithPartialName is deprecated):
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.RMO")
which says:
GAC Version Location
--- ------- --------
True v4.0.30319 C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.SqlServer.RMO\v4.0_14.0.0.0__89845dcd8080cc91\...
Does that mean it's v4.x of that class, or that it's a .NET 4.x class? If it is a .NET 4.x class, is that relevant in any way i.e. is that a problem for Powershell?
TLDR: Summary of troubleshooting: #Keilaron had executed an Import-Module SqlServer earlier on in the PowerShell session which caused the odd behavior.
Personally, I wasn't satisfied that a simple restart of the PowerShell session fixed the issue, as this kind of error shouldn't happen. When I did some further digging, I think I discovered the root cause, and discovered that this is a bigger issue that could be easily missed.
First, the code to replicate the discovered behavior:
Import-Module SqlServer
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.RMO")
$server = 'MyServer'
$dbuser = 'sa'
$dbPasswd = '1234'
$conn = New-Object "Microsoft.SqlServer.Management.Common.ServerConnection" #($server, $dbUser, $dbPasswd);
$publicationDb = New-Object "Microsoft.SqlServer.Replication.ReplicationDatabase"
$publicationDb.Name = 'RandomDatabase'
$publicationDb.ConnectionContext = $conn;
Two key things happen:
The Import-Module SqlServer loads the SqlServer .dll's included with the module, and not the GAC installed modules. This is by design, as the the module is not dependent on SQL Server being installed.
The Microsoft.SqlServer.Rmo.dll is not a part of, or loaded with the SqlServer module, as there are no Replication commands in the SqlServer module. So to use the Replication commands, we have to manually load that .dll ourselves.
The two .dll's that we care about that the Import-Module SqlServer transparently imported were the two connection dependent .dll's from the SqlServer PowerShell module location:
[System.Reflection.Assembly]::LoadFile('C:\Windows\System32\WindowsPowerShell\v1.0\Modules\SqlServer\Microsoft.SqlServer.ConnectionInfo.dll')
[System.Reflection.Assembly]::LoadFile('C:\Windows\System32\WindowsPowerShell\v1.0\Modules\SqlServer\Microsoft.SqlServer.SqlClrProvider.dll')
--> Note: These .dll's were imported as 64 bit .dll's.
The RMO .dll that we had to manually import, come from the GAC, but essentially come from:
"C:\Program Files (x86)\Microsoft SQL Server\140\SDK\Assemblies\Microsoft.SqlServer.Rmo.dll"
Note: This is a 32 bit .dll. This is why we couldn't convert a "Microsoft.SqlServer.Management.Common.ServerConnection" to type "Microsoft.SqlServer.Management.Common.ServerConnection". Even though they are the same "type", as in name, their different bitness causes them to be incompatible.
I'm trying to use SQL views with Doctrine.
Everything works fine so far, but I have a problem when running a basic fixtures load (with no options). I get the following error messages.
[Doctrine\DBAL\DBALException]
An exception occurred while executing 'DELETE FROM gp_items':
SQLSTATE[42000]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]View or function 'gp_items' is not updatable
because the modification affects multiple base tables.
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[42000]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]View or function 'gp_items' is not updatable
because the modification affects multiple base tables.
[PDOException]
SQLSTATE[42000]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]View or function 'gp_items' is not updatable
because the modification affects multiple base tables.
I looked at the code that loads the fixtures from the bundle ("doctrine/doctrine-fixtures-bundle": "^2.3") and I think I have to alter something to the ORMPurger (Doctrine\Common\DataFixtures\Purger) but I'm not sure how to go about that.
So I would like to know how to override a function in that specific class.
Cheers!
Ok,
So I decided to fork the DoctrineFixturesBundle and use my own version of it in my project.
https://github.com/jbonnier/DoctrineFixturesBundle
In order for composer to use it, I modified my composer.json file adding the following code before the last closing bracket.
,
"repositories": [
{
"type": "vcs",
"url": "https://github.com/jbonnier/DoctrineFixturesBundle"
}
]
I also change my require-dev statement to use my personnal branch.
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "dev-jbonnier",
...
}
EDIT:
Additional explanation.
I'm currently working with version v2.4.1 of the bundle.
Here's the change I made to it.
File : Command/LoadDataFixturesDoctrineCommand.php
Changed line 113
from
$purger = new ORMPurger($em);
to
$purger = new ORMPurger($em, $this->listViews($input->getOption('em')));
Add function to class after line 136
/**
* Return an array with all views names in the database.
*
* #return array
*/
protected function listViews($entityManager)
{
$em = $this->getContainer()->get('doctrine')->getManager($entityManager);
$conn = $em->getConnection();
$sm = $conn->getSchemaManager();
$views = $sm->listViews();
$rst = array();
foreach ($views as $view)
{
array_push($rst, $view->getName());
}
return $rst;
}
I had a similar problem. I was lazy so I did the workaround to load our fixtures this way.
I you find a clean solution I'm interested
bin/console -e=test doctrine:database:drop --if-exists --force
bin/console -e=test doctrine:database:create --if-not-exists --no-interaction
bin/console -e=test doctrine:migrations:migrate --no-interaction
bin/console -e=test doctrine:fixtures:load --append --no-interaction
I am running on:
Windows Server 2016 64-bit
MSSQL Server 2016 on the same server
PHP 7.1
IIS 10
I have:
Made sure I can connect to my SQL using the credentials supplied in the codes below.
Installed SQL Server Driver from for PHP from Microsoft, and chose SQLSRV40
Added extension=php_sqlsrv_7_nts_x64.dll and extension=php_pdo_sqlsrv_7_nts_x64.dll to /ext folder.
edited my php.ini and added extension=php_sqlsrv_7_nts_x64.dll and extension=php_pdo_sqlsrv_7_nts_x64.dll and restarted the server.
The following are my code to establish connection:
$connectionInfo = array( "Database"=>$db, "UID"=>$username, "PWD"=>$password);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{ //Will not execute. As such, I have no idea what error(s) am I getting
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
Executing phpinfo() does not show the sqlsrv. However, executing the following code will display a YES.
echo "Did it load? " . extension_loaded('php_sqlsrv_7_nts_x64.dll') ? "YES" : "NO";
I have worked on this for 2 days, and have followed many forums suggestions, and I have no idea what to try anymore. Would appreciate any advise from you experts! :)
Update 1:
I modified the codes below, and it shows a NO.
echo "Did it load? " . (extension_loaded('sqlsrv') ? "YES" : "NO");
echo "Did it load? " . (extension_loaded('pdo_sqlsrv') ? "YES" : "NO");
I don't understand why is it not installed correctly where the dll has already been put inside the extension folder, and specified inside php.ini as I stated earlier.
I'm working on a remote server and I can't use the console because ssh is not enabled. So I need to run aco_sync directly from the browser (or any other way that doesn't involve the shell).
I managed to sync acos on my local dev server with the following code in controller/action:
$command = ROOT . DS . APP_DIR . DS . 'Console' . DS . 'cake';
$params = ' -app ' . ROOT . DS . APP_DIR;
$params .= ' AclExtras.AclExtras';
$params .= ' aco_sync';
$result = shell_exec($command . $params);
But on the production server (with cPanel) I just get no response for about 5 minutes and then I get an internal server error (500). I simply hangs. Actually, this happened on two different VPS servers with cPanel. In the first one, I had ssh and was able to run the command from the console. But when running the quoted code from the browser, I hung just as the other server.
I found no logged errors either on php log files nor cake's log files.
The action is prefixed with "admin_" and ACL doesn't allow execution if not logged in.
'./cake' script file has execute permissions (took me a while to figure this was necessary).
I tried on Chrome and IE8.
Debug level was set to 1.
After trying to run the script, the page broke and I wasn't able to browse until I opened an incognito window or restarted the browser.
I think the server's memory gets completely consumed when I run this script. I've had to restart httpd to get the site up and running again on the server that I could control.
I've seen some implementations using $dispatcher->dispatch() and tried a bunch of them but with no luck.
Any ideas?
App::uses('ShellDispatcher', 'Console');
$command = '-app '.APP.' AclExtras.AclExtras aco_sync';
$args = explode(' ', $command);
$dispatcher = new ShellDispatcher($args, false);
if($dispatcher->dispatch()) {
echo 'OK';
} else {
echo 'Error';
}
Try this, the $dispatcher->dispatch(); seems to show something only in case of an error.
run this and check your database.
App::uses('ShellDispatcher', 'Console');
$command = '-app '.APP.' AclExtras.AclExtras aco_sync';
$args = explode(' ', $command);
$dispatcher = new ShellDispatcher($args, false);
try {
$dispatcher->dispatch();
} catch (Exception $e) {
pr($e);
}
Writing a script to get SQL Server instance names from a table, then attempting to connect to each of these instances to pull back database configuration information. All database instances involved are some version of SQL Server. If the connection fails (due to a bad password, instance is down, etc.) the intention is to print a user-defined error message ("Unable to connect to $inst, skipping.") and continue through the list. I'm having trouble suppressing the default error message from ODBC (SQL Server Native Client 10.0).
Connection is attempted like this:
eval {
my $dbh = DBI->connect(
"dbi:ODBC:Driver={SQL Server Native Client 10.0};Server=<instance_name>;Uid=<user_name>;Pwd=<password>;",
{ PrintError => 0, RaiseError => 1, AutoCommit => 1 }
);
};
It is my (probably incorrect) understanding that PrintError => 0 should suppress the error message and RaiseError => 1 will cause DBI to die if the connect method fails, at which point I can check $# for the error and print a user-defined message. I have also looked at the HandleError attribute but have not had any success.
Is this a completely unrealistic scenario, or is this a result of the ODBC driver I'm working with?
Per bohica's suggestions, working code looks like:
eval {
my $dbh = DBI->connect(
"dbi:ODBC:Driver={SQL Server Native Client 10.0};Server=<instance_name>;",
"Username",
"Password",
{ PrintError => 0, RaiseError => 1, AutoCommit => 1 }
);
};
Username and password were moved out of connection string and passed as separate parameters to DBI connect method.
Assuming you fix the problem Pedro mentions then, PrintError=>0 suppresses errors and you might want to look at PrintWarn as well. The RaiseError=>1 will cause the connect to die if the connect fails and in your example the error will be in $#.
connect is a class method; you call it with DBI->connect, which returns a db handle ($dbh in your case).