sql - SQLSERV and PHP not working... Cannot create a connection to the database -
i have gone through this, , knowledge works. (phpinfo() shows on list of added extensions)
i have code got msdn. made modifications work sql server , database. database there, , running.
here code:
<?php ini_set('display_startup_errors', 1); ini_set('display_errors', 1); error_reporting(-1); ?> ^^ in <head> block. no errors reported.
<?php $servername = "(local)"; $database = "{db}"; // uid , pwd application-specific files. $uid = "{user}"; $pwd = "{pass}"; seek { $conn = new pdo( "sqlsrv:server=$servername;database = $database", $uid, $pwd); $conn->setattribute( pdo::attr_errmode, pdo::errmode_exception ); } catch( pdoexception $e ) { die( "error connecting sql server" ); } echo "connected sql server\n"; $query = 'select * {table}'; $stmt = $conn->query( $query ); while ( $row = $stmt->fetch( pdo::fetch_assoc ) ){ print_r( $row ); } // free statement , connection resources. $stmt = null; $conn = null; ?>
here var_dump() of $e in grab block.
pdoexception object ( [message:protected] => sqlstate[28000]: [microsoft][sql server native client 11.0][sql server]login failed user 'sa'. [string:exception:private] => [code:protected] => 28000 [file:protected] => c:\inetpub\wwwroot\sandbox\sfactor\sandbox.php [line:protected] => 20 [trace:exception:private] => array ( [0] => array ( [file] => c:\inetpub\wwwroot\sandbox\sfactor\sandbox.php [line] => 20 [function] => __construct [class] => pdo [type] => -> [args] => array ( [0] => sqlsrv:server=;database=sfactor [1] => sa [2] => 7536sql ) ) ) [previous:exception:private] => [errorinfo] => array ( [0] => 28000 [1] => 18456 [2] => [microsoft][sql server native client 11.0][sql server]login failed user 'sa'. ) ) connected sql server notice: undefined variable: conn in c:\inetpub\wwwroot\sandbox\sfactor\sandbox.php on line 31 fatal error: phone call fellow member function query() on non-object in c:\inetpub\wwwroot\sandbox\sfactor\sandbox.php on line 31
so it's fixed.. problem $servername = "(local)"; giving problems.
all had was, $servername = "localhost\mssql2014";
thanks everyone.
php sql sql-server
No comments:
Post a Comment