How can one establish a connection and execute an INSERT statement in PHP when working with Microsoft SQL Server?
To establish a connection and execute an INSERT statement in PHP when working with Microsoft SQL Server, you can use the PDO (PHP Data Objects) extension. First, you need to establish a connection to the SQL Server database using the PDO class. Then, prepare an INSERT statement using the prepare() method and bind the necessary parameters. Finally, execute the statement using the execute() method.
// Establish connection to SQL Server
$serverName = "your_server_name";
$connectionOptions = array(
"Database" => "your_database_name",
"Uid" => "your_username",
"PWD" => "your_password"
);
$conn = sqlsrv_connect($serverName, $connectionOptions);
// Prepare and execute INSERT statement
$sql = "INSERT INTO your_table_name (column1, column2) VALUES (?, ?)";
$params = array($value1, $value2);
$stmt = sqlsrv_prepare($conn, $sql, $params);
sqlsrv_execute($stmt);