Created
February 17, 2018 02:05
-
-
Save wyanez/a4e1b25945a021c3d58abd756504d832 to your computer and use it in GitHub Desktop.
Archivos de Prueba de la Conexión a SQL Server desde PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$serverName = "WNETBOOK-WIN7\SQLEXPRESS"; | |
$connectionInfo = array( "Database"=>"master"); | |
$conn = sqlsrv_connect( $serverName, $connectionInfo); | |
if( $conn ) echo "Conectado a la Base de Datos SQL Server!"; | |
else{ | |
echo "NO se puede conectar a la Base de Datos SQL Server"; | |
die( print_r( sqlsrv_errors(), true)); | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$serverName = "WNETBOOK-WIN7\SQLEXPRESS"; | |
$dsn = "sqlsrv:server=$serverName ; Database=master; ConnectionPooling=0"; | |
echo $dsn."</br/></br/>"; | |
try { | |
$conn = new PDO( $dsn, "", ""); | |
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); | |
$result = $conn->query("SELECT @@VERSION as version"); | |
echo print_r($result->fetch(PDO::FETCH_ASSOC))."</br></br>"; | |
$result = $conn->query("SELECT GETDATE() as hoy"); | |
echo print_r($result->fetch(PDO::FETCH_ASSOC))."</br"; | |
} | |
catch(PDOException $e){ | |
die( print_r( $e->getMessage() ) ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment