Skip to content Skip to sidebar Skip to footer

How To Execute A Sql-server Function From Php?

I have function in MSSQL and I need to start that from PHP. My connection is ready, but I don't know howto execute from PHP. Here's the function I try to execute: USE [database] GO

Solution 1:

mssql_execute — Executes a stored procedure on a MS SQL server database

http://php.net/manual/en/function.mssql-execute.php

http://php.net/manual/en/function.mssql-init.php

http://php.net/manual/en/function.mssql-bind.php

// Create a new statement$stmt = mssql_init('ict_es2_import_ceniku');

// Bind values
mssql_bind($stmt, '@Id_ceniku',    'Maloobchodni cenik',  SQLTEXT, false);
mssql_bind($stmt, '@return_value',    $return_value,  SQLINT, true);

// Execute the statement
mssql_execute($stmt);

// And we can free it like so:
mssql_free_statement($stmt);

echo$return_value;

Solution 2:

This works!

$username = "xxx";
$password = "xxx";
$hostname = 'xxx';
$dbname = "xxx";


$dbcon = mssql_connect($hostname, $username, $password)ordie("Unable to connect to MSSQL");
mssql_select_db($dbname, $dbcon); // vybere databázi$stmt = mssql_init('ict_es2_import_ceniku');
$variace = 'Maloobchodni cenik';
$Id_ceniku = '@Id_ceniku';
mssql_bind($stmt, $Id_ceniku, $variace,  SQLTEXT, false);
mssql_execute($stmt);
mssql_free_statement($stmt);
echo$return_value;

Post a Comment for "How To Execute A Sql-server Function From Php?"