1

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
DECLARE     @return_value int
EXEC  @return_value = [dbo].[ict_es2_import_ceniku]
@Id_ceniku = N'Maloobchodni cenik'
SELECT      'Return Value' = @return_value
GO

2 Answers 2

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;
Sign up to request clarification or add additional context in comments.

13 Comments

Yes it will definitely correct way to call stored procedure. +1 from me
I find it too, but I can not use it.
Hari Swaminathan: $stmt = mssql_init('@return_value'); // Execute the statement mssql_execute($stmt); // And we can free it like so: mssql_free_statement($stmt);¨
@Bojkas $stmt = mssql_init('<you stored procedure name>'); you need to give the sp name as parameter to mssql_init method
I dont realy know. :-/ Procedure name is "ict_es2_import_ceniku" and parametr "Maloobchodni cenik" Only one thing, where can i write parameter?
|
0

This works!

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


$dbcon = mssql_connect($hostname, $username, $password)or die("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;

1 Comment

Its good you find the solution, Just for my understanding how will you get the $return_value. (Is it $return_value=mssql_execute($stmt);)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.