function ReaPaises($nIdPais) { $sp = mssql_init('REAPAISES'); //SP //Parámetros SP mssql_bind($sp, '@nIdPais', $nIdPais, SQLINT4); $resultado = mssql_execute($sp); //Ejecución SP $i = 0; while ($row = mssql_fetch_array($resultado)) { $html[$i]['id_pais'] = $row[0]; $html[$i]['nombre'] = $row[1]; $i++; } return $html; mssql_free_result($resultado); //Liberación del recurso mssql_free_statement($sp); //Liberación del recurso }
CREATE PROCEDURE sp_php_test AS \t-- first Query: no match \tSELECT * FROM php_test WHERE id=10000 \t-- second Query: 2 matches \tSELECT * FROM php_test EOSQL; mssql_query($sql, $conn) or die("error querying"); # one time to let sql compile and compute statistics on table $rs = mssql_query("sp_php_test", $conn) or die("error querying"); mssql_next_result($rs); mssql_next_result($rs); mssql_free_result($rs); $err = ""; $num_res = 0; $stmt = mssql_init("sp_php_test", $conn); $rs = mssql_execute($stmt); if (is_resource($rs)) { echo "fetching...\n"; do { ++$num_res; echo "Processing result {$num_res}\n"; echo "Num rows = " . mssql_num_rows($rs) . "\n"; if (!$err && $num_res == 1 && mssql_num_rows($rs) != 0) { $err = "Expected 0 rows from recordset {$num_res}"; } if (!$err && $num_res == 2 && mssql_num_rows($rs) != 2) { $err = "Expected 2 rows from recordset {$num_res}"; } // Process result } while (mssql_next_result($rs)); mssql_free_result($rs);
function _query($sql,$inputarr) { $this->_errorMsg = false; if (is_array($inputarr)) { # bind input params with sp_executesql: # see http://www.quest-pipelines.com/newsletter-v3/0402_F.htm # works only with sql server 7 and newer if (!is_array($sql)) $sql = $this->Prepare($sql); $params = ''; $decl = ''; $i = 0; foreach($inputarr as $v) { if ($decl) { $decl .= ', '; $params .= ', '; } if (is_string($v)) { $len = strlen($v); if ($len == 0) $len = 1; if ($len > 4000 ) { // NVARCHAR is max 4000 chars. Let's use NTEXT $decl .= "@P$i NTEXT"; } else { $decl .= "@P$i NVARCHAR($len)"; } $params .= "@P$i=N". (strncmp($v,"'",1)==0? $v : $this->qstr($v)); } else if (is_integer($v)) { $decl .= "@P$i INT"; $params .= "@P$i=".$v; } else { $decl .= "@P$i FLOAT"; $params .= "@P$i=".$v; } $i += 1; } $decl = $this->qstr($decl); if ($this->debug) ADOConnection::outp("<font size=-1>sp_executesql N{$sql[1]},N$decl,$params</font>"); $rez = mssql_query("sp_executesql N{$sql[1]},N$decl,$params"); } else if (is_array($sql)) { # PrepareSP() $rez = mssql_execute($sql[1]); } else { $rez = mssql_query($sql,$this->_connectionID); } return $rez; }
echo "retval = {$retval}\n"; if ($retval != 3) { echo "Expected retval 3\n"; $err = TRUE; } } // Test 4, SQLVARCHAR output // $proc = mssql_init("sp_php_test4", $conn); $test1 = ""; $retval = 0; // Bind the parameters mssql_bind($proc, "@test1", &$test1, SQLVARCHAR, TRUE, FALSE, 13); // Bind the return value mssql_bind($proc, "RETVAL", &$retval, SQLINT4); $result = mssql_execute($proc); if (!$result) { echo "Last message from SQL : " . mssql_get_last_message() . "\n"; $err = TRUE; mssql_free_statement($proc); } else { mssql_free_statement($proc); echo "test1 = >{$test1}<\n"; if ($test1 != 'xyz45678') { echo "Expected test1 >xyz45678<\n"; $err = TRUE; } echo "retval = {$retval}\n"; if ($retval != 4) { echo "Expected retval 4\n"; $err = TRUE;
/** * @see CallableStatement::executeQuery() */ function executeQuery($p1 = null, $fetchmode = null) { $params = null; if ($fetchmode !== null) { $params = $p1; } elseif ($p1 !== null) { if (is_array($p1)) { $params = $p1; } else { $fetchmode = $p1; } } if ($params) { for ($i = 0, $cnt = count($params); $i < $cnt; $i++) { $this->set($i + 1, $params[$i]); } } $this->result = mssql_execute($this->stmt); if (!$this->result) { throw new SQLException('unable to execute callable statement', mssql_get_last_message()); } return new MSSQLResultSet($this->conn, $this->result, $fetchmode, $this->offset, $this->limit); }
<?php set_time_limit(10000); require "../config/main.php"; $mdir = opendir("updates"); while ($arr = readdir($mdir)) { if (strstr(strtolower($arr), ".sql")) { $dbms_schema = 'updates/' . $arr; $sql_query = file_get_contents($dbms_schema); mssql_execute($sql_query, true); mssql_free_statement($stmt); } } echo "Se han actualizado " . $upt * 1 . " consultas en la base de datos"; function remove_comments(&$output) { $lines = explode("\n", $output); $output = ""; // try to keep mem. use down $linecount = count($lines); $in_comment = false; for ($i = 0; $i < $linecount; $i++) { if (preg_match("/^\\/\\*/", preg_quote($lines[$i]))) { $in_comment = true; } if (!$in_comment) { $output .= $lines[$i] . "\n"; } if (preg_match("/\\*\\/\$/", preg_quote($lines[$i]))) { $in_comment = false; }
$community = $_POST['community']; $school = $_POST['school']; /* echo "<p>LocID:</p>"; echo $LocID; echo "<p>SiteKey: </p>"; echo $SiteKey; echo "<p>Copy Type Key</p>"; echo $CopyTypeKey; echo "<p>Short:</p>"; echo $short; echo "<p>Location: </p>"; echo $location; echo "<p>about: </p>"; echo $about; echo "<p>community: </p>"; echo $community; echo "<p>school; </p>"; echo $school; */ mssql_bind($Copyproc, '@LocID', $LocID, SQLINT4, false, false, 10); mssql_bind($Copyproc, '@SiteKey', $SiteKey, SQLINT4, false, false, 1); mssql_bind($Copyproc, '@CopyTypeKey', $CopyTypeKey, SQLINT1, false, false, 1); mssql_bind($Copyproc, '@short', $short, SQLTEXT, false, false, 255); mssql_bind($Copyproc, '@location', $location, SQLTEXT, false, false, 255); mssql_bind($Copyproc, '@about', $about, SQLTEXT, false, false, 255); mssql_bind($Copyproc, '@community', $community, SQLTEXT, false, false, 255); mssql_bind($Copyproc, '@school', $school, SQLTEXT, false, false, 255); mssql_execute($Copyproc); mssql_close(); header("Location: http://toolkit.empire-dev.com/copy.php");
/** * method to deal with the execution of MS SQL stored proceedured * @param $string $procName The name of the proceedure to execute * @param array $paramArray An array containing entries for each paramneeded but the stored proceedure see the exampel in the code below */ function exeStoredProc($procName, $paramArray = false, $skip_results = false) { // example param array // $paramArray = array ('LocationName' => array ('VALUE' => 'the clients host name', 'TYPE' => 'SQLVARCHAR', 'ISOUTPUT' => 'false', 'IS_NULL' =>'false', 'MAXLEN' => '255' ) ); // each element in the paramArray must idetify a paramiter required by the stored proceedure and can tain an array of settings from that paramiter // see http://php.net/manual/en/function.mssql-bind.php for information on the values for these paramiters // initiate the stored proceedure $stmt = mssql_init($procName, $this->linkid); // bind paramiters if ($paramArray) { foreach ($paramArray as $paramName => $values) { mssql_bind($stmt, $paramName, $values['VALUE'], $values['TYPE'], $values['ISOUTPUT'], $values['IS_NULL'], $values['MAXLEN']); } } // execute the stored proceedure $results = mssql_execute($stmt); // if we do not get anu results return false if (!$results) { return false; // if we get results then put them in to an array and return it } else { // define the array to return $resultArray = array(); // loop throught he result set and place each result to the resultArray do { while ($row = mssql_fetch_row($stmt)) { $resultArray[] = $row; } } while (mssql_next_result($stmt)); // clean up the statment ready for the next useexec SELLING_GetLocation @LocationName='it-leigh.skilouise.com' mssql_free_statement($stmt); //returnt he result array return $resultArray; } }
function Execute() { $this->Result = mssql_execute($this->Handle); if (is_resource($this->Result)) { return $this->GetResults(); } else { return $this->Result; } }
function _query($sql,$inputarr=false) { $this->_errorMsg = false; if (is_array($inputarr)) { # bind input params with sp_executesql: # see http://www.quest-pipelines.com/newsletter-v3/0402_F.htm # works only with sql server 7 and newer $getIdentity = false; if (!is_array($sql) && preg_match('/^\\s*insert/i', $sql)) { $getIdentity = true; $sql .= (preg_match('/;\\s*$/i', $sql) ? ' ' : '; ') . $this->identitySQL; } if (!is_array($sql)) $sql = $this->Prepare($sql); $params = ''; $decl = ''; $i = 0; foreach($inputarr as $v) { if ($decl) { $decl .= ', '; $params .= ', '; } if (is_string($v)) { $len = strlen($v); if ($len == 0) $len = 1; if ($len > 4000 ) { // NVARCHAR is max 4000 chars. Let's use NTEXT $decl .= "@P$i NTEXT"; } else { $decl .= "@P$i NVARCHAR($len)"; } $params .= "@P$i=N". (strncmp($v,"'",1)==0? $v : $this->qstr($v)); } else if (is_integer($v)) { $decl .= "@P$i INT"; $params .= "@P$i=".$v; } else if (is_float($v)) { $decl .= "@P$i FLOAT"; $params .= "@P$i=".$v; } else if (is_bool($v)) { $decl .= "@P$i INT"; # Used INT just in case BIT in not supported on the user's MSSQL version. It will cast appropriately. $params .= "@P$i=".(($v)?'1':'0'); # True == 1 in MSSQL BIT fields and acceptable for storing logical true in an int field } else { $decl .= "@P$i CHAR"; # Used char because a type is required even when the value is to be NULL. $params .= "@P$i=NULL"; } $i += 1; } $decl = $this->qstr($decl); if ($this->debug) ADOConnection::outp("<font size=-1>sp_executesql N{$sql[1]},N$decl,$params</font>"); $rez = mssql_query("sp_executesql N{$sql[1]},N$decl,$params", $this->_connectionID); if ($getIdentity) { $arr = @mssql_fetch_row($rez); $this->lastInsID = isset($arr[0]) ? $arr[0] : false; @mssql_data_seek($rez, 0); } } else if (is_array($sql)) { # PrepareSP() $rez = mssql_execute($sql[1]); $this->lastInsID = false; } else { $rez = mssql_query($sql,$this->_connectionID); $this->lastInsID = false; } return $rez; }
<?php //Connect to Poolparty include_once '../includes/connection.php'; // Create a new statement $stmt = mssql_init('Classstartproc'); // Some data strings $ClassStartSchedulesID = $_POST['ClassStartSchedulesID']; $LocID = $_POST['LocID']; $ScheduleID = $_POST['ScheduleID']; // Bind values mssql_bind($stmt, '@ClassStartSchedulesID', $ClassStartSchedulesID, SQLINT1, false, false, 20); mssql_bind($stmt, '@LocID', $LocID, SQLINT1, false, false, 20); mssql_bind($stmt, '@ScheduleID', $ScheduleID, SQLTEXT, false, false, 50); // Execute the statement $result = mssql_execute($stmt); echo $result; // // And we can free it like so: // mssql_free_statement($stmt); // // echo $stmt; header("Location: http://54.209.36.245/programs.php"); exit;
public function Execute(){ if ($this->commandtype == self::C_CMDTEXT) { //Returns a TRecordset object return $this->activeconnection->Execute($this->commandtext); } elseif ($this->commandtype == self::C_CMDSTOREDPROC) { try { //Call Stored Procedure $this->stmt = @mssql_init($this->commandtext, $this->activeconnection->connection_id); //If can't call Stored Procedure if (!$this->stmt) throw new TException(TCustomMessage::GetMessage(5009, $this->commandtext), 5009); //Add the SQL Parameters to the Stored Procedure if it exists for ($x = 0; $x < $this->parameters->count; $x ++) { //Add SQL Parameter $k = @mssql_bind($this->stmt, $this->parameters->parameter($x)->name, &$this->parameters->parameter($x)->value, $this->parameters->parameter($x)->type, $this->parameters->parameter($x)->is_output, $this->parameters->parameter($x)->is_null, $this->parameters->parameter($x)->maxlen); //If can't add SQL Parameter if (!$k) throw new TException(TCustomMessage::GetMessage(5010, $this->commandtext), 5010); } //Execute Stored Procedure $this->result_id = @mssql_execute($this->stmt); //If can't execute Stored Procedure if (!$this->result_id) throw new TException(TCustomMessage::GetMessage(5011, $this->commandtext), 5011); //Returns a TRecordset object return new TRecordset($this->result_id, $this->activeconnection); } catch (TException $e) { //Set the exception $this->activeconnection->err = $e; //TCommand::Execute() failed, returns false return false; } } }
function func_mssql_query($query, $sess, &$bin, &$biVal, &$biLen, &$biRes, &$biType) { if (count($bin) >= 1) { $res = mssql_init($query); for ($i = 0; $i < count($bin); $i++) { $TypeParam = TRUE; $biRes[$i] = $biVal[$i]; if ($biLen[$i] == -1) { $TypeParam = FALSE; } if ($biType[$i] == 1) { $msType = SQLVARCHAR; } if ($biType[$i] == 2) { $msType = SQLINT4; } if ($biType[$i] == 3) { $msType = SQLFLT8; } if ($biType[$i] == 4) { $msType = SQLVARCHAR; } mssql_bind($res, $bin[$i], $biRes[$i], $msType, $TypeParam); } $resExec = mssql_execute($res); while (mssql_next_result($resExec)) { } } else { $resExec = mssql_query($query); if (!$resExec) { ErreurExecutionMSSQL(); } } return $resExec; }
public static function executeStoreProcedure($storep, $params, $type) { $database = self::GetInstance(); switch ($database->type) { case 'mysql': break; case 'mssql': if (extension_loaded('pdo_mssql')) { } else { if (extension_loaded('mssql')) { $proc = mssql_init($storep, $database->connection); $proc_result = mssql_execute($proc); if (!$result) { echo 'Error in statement execution.\\n'; die('MSSQL error: ' . mssql_get_last_message()); } return $result; } else { if (extension_loaded('sqlsrv')) { $result = sqlsrv_query($database->connection, $query, $store, $params); if ($result === false) { echo 'Error in statement execution s.\\n'; die("Problemas en el store:" . sqlsrv_errors()); } else { if ($type == "get") { $arr = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC); return $arr; } else { return $result; } } } } } break; default: // Error is triggered for all other database types //trigger_error('This database type is not supported',E_USER_ERROR); break; } }
function _query($sql, $inputarr) { $this->_errorMsg = false; if (is_array($sql)) { $rez = mssql_execute($sql[1]); } else { $rez = mssql_query($sql, $this->_connectionID); } return $rez; }
function _query($sql, $inputarr) { $this->_errorMsg = false; if (is_array($inputarr)) { # bind input params with sp_executesql: # see http://www.quest-pipelines.com/newsletter-v3/0402_F.htm # works only with sql server 7 and newer if (!is_array($sql)) { $sql = $this->Prepare($sql); } $params = ''; $decl = ''; $i = 0; foreach ($inputarr as $v) { if ($decl) { $decl .= ', '; $params .= ', '; } if (is_string($v)) { $len = strlen($v); if ($len == 0) { $len = 1; } if ($len > 4000) { // NVARCHAR is max 4000 chars. Let's use NTEXT $decl .= "@P{$i} NTEXT"; } else { $decl .= "@P{$i} NVARCHAR({$len})"; } $params .= "@P{$i}=N" . (strncmp($v, "'", 1) == 0 ? $v : $this->qstr($v)); } else { if (is_integer($v)) { $decl .= "@P{$i} INT"; $params .= "@P{$i}=" . $v; } else { if (is_float($v)) { $decl .= "@P{$i} FLOAT"; $params .= "@P{$i}=" . $v; } else { if (is_bool($v)) { $decl .= "@P{$i} INT"; # Used INT just in case BIT in not supported on the user's MSSQL version. It will cast appropriately. $params .= "@P{$i}=" . ($v ? '1' : '0'); # True == 1 in MSSQL BIT fields and acceptable for storing logical true in an int field } else { $decl .= "@P{$i} CHAR"; # Used char because a type is required even when the value is to be NULL. $params .= "@P{$i}=NULL"; } } } } $i += 1; } $decl = $this->qstr($decl); if ($this->debug) { ADOConnection::outp("<font size=-1>sp_executesql N{$sql[1]},N{$decl},{$params}</font>"); } $rez = mssql_query("sp_executesql N{$sql[1]},N{$decl},{$params}"); } else { if (is_array($sql)) { # PrepareSP() $rez = mssql_execute($sql[1]); } else { $rez = mssql_query($sql, $this->_connectionID); } } return $rez; }
$City = $_POST['City']; $State = $_POST['State']; $StateID = $_POST['StateID']; $IsTitle4 = $_POST['IsTitle4']; $PageH1 = $_POST['PageH1']; $IsTablet = $_POST['IsTablet']; $isAndroidTablet = $_POST['isAndroidTablet']; // Bind values mssql_bind($info, '@LocID', $LocID, SQLINT4, false, false, 60); mssql_bind($info, '@DmaID', $DmaID, SQLINT4, false, false, 60); mssql_bind($info, '@RegionID', $RegionID, SQLINT4, false, false, 60); mssql_bind($info, '@ZipID', $ZipID, SQLINT4, false, false, 60); mssql_bind($info, '@Lat', $Lat, SQLINT4, false, false, 100); mssql_bind($info, '@Lon', $Lon, SQLINT4, false, false, 100); mssql_bind($info, '@School', $School, SQLVARCHAR, false, false, 255); mssql_bind($info, '@Brand', $Brand, SQLVARCHAR, false, false, 255); mssql_bind($info, '@Email', $Email, SQLVARCHAR, false, false, 255); mssql_bind($info, '@Address', $Address, SQLVARCHAR, false, false, 255); mssql_bind($info, '@Phone', $Phone, SQLVARCHAR, false, false, 12); mssql_bind($info, '@URL', $URL, SQLVARCHAR, false, false, 255); mssql_bind($info, '@City', $City, SQLVARCHAR, false, false, 255); mssql_bind($info, '@State', $State, SQLVARCHAR, false, false, 50); mssql_bind($info, '@StateID', $StateID, SQLINT2, false, false, 2); mssql_bind($info, '@IsTitle4', $IsTitle4, SQLINT1, false, false, 1); mssql_bind($info, '@PageH1', $PageH1, SQLVARCHAR, false, false, 255); mssql_bind($info, '@IsTablet ', $IsTablet, SQLINT1, false, false, 1); mssql_bind($info, '@isAndroidTablet', $isAndroidTablet, SQLINT1, false, false, 1); // Execute the statement mssql_execute($info); mssql_close(); header("Location: http://toolkit.empire-dev.com/schools.php");