-1

I need to create a crud in PHP with the SQLSERVER database for a college job, connect the bank in PHP I got it, now execute no instructions, please help me, I am very difficult ..?

my code

<? php
$ server = "DESKTOP-RA9T588";
$ conectioninfo = array ("Database" => "Banca_de_Revista", "UID" => "Arthur", "PWD" => "inter190744");
$ result = sqlsrv_connect ($ server, $ conectioninfo);
$ bank = "Banca_de_Revista";
$ db = mssql_select_db ($ bank, $ conmssql);
if ($ result && $ db) {
    echo "Congratulations !! The connection to the database has occurred normally!";
} else {
    echo ("Could not connect.");
    die (print_r (sqlsrv_errors (), true));
}
?>

problema que está aparecendo:

Fatal error: Call to undefined function mssql_select_db()

Thank you in advance.

Zhorov
  • 28,486
  • 6
  • 27
  • 52

1 Answers1

2

Functions sqlsrv_connect() and mssql_select_db() are from two different PHP extensions. Function sqlsrv_connect() is from SQLSRV extension (PHP Driver for MS SQL Server), while function mssql_select_db() is from MSSQL extension which is not available anymore on Windows with PHP 5.3 or later.

This is very simple script, that shows how to connect to MS SQL Server and execute simple query:

<?php
$server = "DESKTOP-RA9T588";
$cinfo = array(
    "Database" => "Banca_de_Revista", 
    "UID" => "Arthur", 
    "PWD" => "inter190744"
);
$conn = sqlsrv_connect($server, $cinfo);
if( $conn === false )
{
    echo "Error (sqlsrv_connect): ".print_r(sqlsrv_errors(), true);
    exit;
}

$sql = 
    "SELECT 'SUSER_SNAME' AS [NAME], CONVERT(varchar(128), SUSER_SNAME()) AS [VALUE]".
    "UNION ALL ".
    "SELECT 'SUSER_NAME' AS [NAME], CONVERT(varchar(128), SUSER_NAME()) AS [VALUE]".
    "UNION ALL ".
    "SELECT 'USER_NAME' AS [NAME], CONVERT(varchar(128), USER_NAME()) AS [VALUE]".
    "UNION ALL ".
    "SELECT 'USER_ID' AS [NAME], CONVERT(varchar(128), USER_ID()) AS [VALUE]";
$stmt = sqlsrv_query($conn, $sql);
if( $stmt === false ) {
    echo "Error (sqlsrv_query): ".print_r(sqlsrv_errors(), true);
    exit;
}

while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
    echo $row['NAME'].": ".$row['VALUE']."</br>";
}

sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
?>

For more information check here.

Zhorov
  • 28,486
  • 6
  • 27
  • 52