当前位置: 首页>>代码示例>>PHP>>正文


PHP sqlsrv_prepare函数代码示例

本文整理汇总了PHP中sqlsrv_prepare函数的典型用法代码示例。如果您正苦于以下问题:PHP sqlsrv_prepare函数的具体用法?PHP sqlsrv_prepare怎么用?PHP sqlsrv_prepare使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了sqlsrv_prepare函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: prepare

 /**
  * Returns a prepared statement which can be executed multiple times
  * @param string $sql
  * @param array  $params Values to bind to placeholders in the query string
  * @return Statement
  * @throws SqlException if an error occurs
  */
 public function prepare($sql, array $params = [])
 {
     if (!($stmt = sqlsrv_prepare($this->connection, $sql, $params))) {
         throw new SqlException('Query failed', sqlsrv_errors(), $sql, $params);
     }
     return new Statement($stmt, true, $sql, $params);
 }
开发者ID:theodorejb,项目名称:peachy-sql,代码行数:14,代码来源:SqlServer.php

示例2: SaveLecturerMarks

function SaveLecturerMarks($marks)
{
    $status = array();
    include_once 'db_Connection.php';
    $conn = sqlsrv_connect($serverName, $connectionInfo);
    if ($conn) {
        $login = "0";
        $subjectid = 0;
        $subjtype = 0;
        $lectid = 0;
        $qid = 0;
        $mark = 0;
        $ldescription = "0";
        $sqlstr = " insert into [dbo].[MarkLecturer] ([Login],[subjid],[subjtype],[lectid],[qid],[mark],[ldescription]) " . " values (?,?,?,?,?,?,?) ";
        $params = array(&$login, &$subjectid, &$subjtype, &$lectid, &$qid, &$mark, &$ldescription);
        $stmt = sqlsrv_prepare($conn, $sqlstr, $params);
        if ($stmt) {
            foreach ($marks as &$data) {
                $login = $data->login;
                $subjectid = $data->subjectid;
                $subjtype = $data->subjtype;
                $lectid = $data->lectid;
                $qid = $data->qid;
                $mark = $data->mark;
                $ldescription = $data->description;
                if (!sqlsrv_execute($stmt)) {
                    array_push($status, "not inserted-L" . $login . "-S" . $subjectid . "-T" . $subjtype . "-L" . $lectid . "-Q" . $qid);
                }
            }
        }
        sqlsrv_close($conn);
    }
    return $status;
}
开发者ID:Nata12,项目名称:SocHarcum,代码行数:34,代码来源:saveLecturerMarks.php

示例3: processWalking

function processWalking($results, $fileRow)
{
    global $csvData;
    global $sqlDB;
    global $plat;
    //this is where I'm going to do things
    foreach ($results as $result) {
        $startDate = $result['DateBegan'];
        $endDate = $result['DateStopped'];
        $diff = date_diff($startDate, $endDate);
        $days = $diff->format("%a");
        $currentDate = $result['DateBegan'];
        $formattedDate = date_format($currentDate, 'm/d/y');
        $tempData = array();
        while ($currentDate <= $endDate) {
            $dayDate = $formattedDate . ' ' . "00:00:00";
            $endDay = $formattedDate . ' ' . "23:59:59";
            $querry = "SELECT TOP 1 RecID FROM vPhoneData1\n\t\t\t\tWHERE (TaskSetName = '1 PING' or TaskSetName =\n\t\t\t\t '3 REPORT CGI_OR_H2RL') AND LocalTimetag1 > ? and\n\t\t\t\t LocalTimetag1 < ? and cast(FORMDATA as varchar(max)) like\n\t\t\t\t '%" . $plat . "%'";
            $stmt = sqlsrv_prepare($sqlDB, $querry, array(&$dayDate, &$endDay));
            sqlsrv_execute($stmt);
            $fetched = sqlsrv_fetch_array($stmt);
            if (!empty($fetched)) {
                $formattedDate = date_format($currentDate, 'm/d/y');
                $fileRow['Survey Dt'] = $formattedDate;
                $fileRow['Completed By'] = $result['TechName'];
                $fileRow['Instrument'] = $result['Instrument'];
                $fileRow['Rate'] = $result['RateCode'];
                $fileRow['Survey Method'] = 'WALK';
                $tempData[] = $fileRow;
            }
            $currentDate = date_add($currentDate, date_interval_create_from_date_string('1 days'));
            $formattedDate = date_format($currentDate, 'm/d/y');
            $fetched = null;
        }
        if (!empty($tempData)) {
            $daycount = count($tempData);
            if ($result[6] > 0) {
                $dailyTotal = floor($result[6] / $daycount);
                $firstTotal = $dailyTotal + $result[6] % $daycount;
                $isFirst = TRUE;
            } else {
                $dailyTotal = 0;
            }
            foreach ($tempData as $tempRow) {
                if ($isFirst === TRUE) {
                    $tempRow['Quantity'] = $firstTotal;
                    $isFirst = FALSE;
                } elseif ($dailyTotal > 0) {
                    $tempRow['Quantity'] = $dailyTotal;
                } else {
                    $tempRow['Quantity'] = 0;
                }
                if ($tempRow['Quantity'] > 0) {
                    $csvData[] = $tempRow;
                }
            }
        }
    }
}
开发者ID:MRBednar,项目名称:Example-Code,代码行数:59,代码来源:sqlData.php

示例4: _prepare

 /**
  * Prepares statement handle
  *
  * @param string $sql
  * @return void
  * @throws \Zend\DB\Statement\SQLSRV\Exception
  */
 protected function _prepare($sql)
 {
     $connection = $this->_adapter->getConnection();
     $this->_stmt = sqlsrv_prepare($connection, $sql);
     if (!$this->_stmt) {
         throw new Exception(sqlsrv_errors());
     }
     $this->_originalSQL = $sql;
 }
开发者ID:alab1001101,项目名称:zf2,代码行数:16,代码来源:SQLSRV.php

示例5: _prepare

 /**
  * Prepares statement handle
  *
  * @param string $sql
  * @return void
  * @throws Zend_Db_Statement_Sqlsrv_Exception
  */
 protected function _prepare($sql)
 {
     $connection = $this->_adapter->getConnection();
     $this->_stmt = sqlsrv_prepare($connection, $sql);
     if (!$this->_stmt) {
         require_once 'include/Zend/Db/Statement/Sqlsrv/Exception.php';
         throw new Zend_Db_Statement_Sqlsrv_Exception(sqlsrv_errors());
     }
     $this->_originalSQL = $sql;
 }
开发者ID:Pengzw,项目名称:c3crm,代码行数:17,代码来源:Sqlsrv.php

示例6: prepare

 public static function prepare($conn, $sqlElement, $params, $bind = true)
 {
     if ($conn && strlen($sqlElement) > 0) {
         if (is_array($params) && count($params) > 0) {
             for ($i = 0; $i < count($params); $i++) {
                 $aprm[$i] =& $params[$i];
             }
         } else {
             $aprm = $params;
         }
         $sql = sqlsrv_prepare($conn, (string) $sqlElement, $aprm);
         if (!$sql) {
             print_r(sqlsrv_errors(), true);
         }
         return $sql;
     }
     return false;
 }
开发者ID:Russell-IO,项目名称:php-syslog-ng,代码行数:18,代码来源:jqGridSqlsrv.php

示例7: preparePreparedStatement

 /**
  * (non-PHPdoc)
  * @see PreparedStatement::preparePreparedStatement()
  */
 public function preparePreparedStatement($msg = '')
 {
     if (empty($this->parsedSQL)) {
         $this->DBM->registerError($msg, "Empty SQL query");
         return false;
     }
     $GLOBALS['log']->info('QueryPrepare: ' . $this->parsedSQL);
     $num_args = count($this->fieldDefs);
     $this->bound_vars = array_fill(0, $num_args, null);
     $params = array();
     for ($i = 0; $i < $num_args; $i++) {
         $params[$i] =& $this->bound_vars[$i];
     }
     $this->stmt = sqlsrv_prepare($this->dblink, $this->parsedSQL, $params);
     if ($this->DBM->checkError(" QueryPrepare Failed: {$msg} for sql: {$this->parsedSQL} ::") || !$this->stmt) {
         return false;
     }
     return $this;
 }
开发者ID:jglaine,项目名称:sugar761-ent,代码行数:23,代码来源:SqlsrvPreparedStatement.php

示例8: array

							</tr>
							<tr>
								<?php 
//telefoon gebruiker
$sqlTel = "SELECT * FROM Gebruikerstelefoon where Gebruiker='{$user}'";
$paramsTel = array();
$optionsTel = array("Scrollable" => SQLSRV_CURSOR_KEYSET);
$stmtTel = sqlsrv_query($conn, $sqlTel, $paramsTel, $optionsTel);
$rowCountTel = sqlsrv_num_rows($stmtTel);
$actual_link = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
$getFirstEnd = end(explode('?', $actual_link));
$getSecondEnd = substr($getFirstEnd, 0, 6);
if ($getSecondEnd == 'remove') {
    $end = end(explode('?remove=', $actual_link));
    $sqlDelete = "DELETE FROM Gebruikerstelefoon WHERE Telefoonnummer = '{$end}' AND Gebruiker = '{$user}'";
    $stmtDelete = sqlsrv_prepare($conn, $sqlDelete);
    sqlsrv_execute($stmtDelete);
}
while ($rowTel = sqlsrv_fetch_array($stmtTel, SQLSRV_FETCH_ASSOC)) {
    $Teltel = $rowTel['Telefoonnummer'];
    echo '<tr> </td><td><td><input type="text" name="telefoon" placeholder="' . $Teltel . '" disabled><a style="float: right;" href="?remove=' . $Teltel . '">Verwijder&nbsp;</a></td></tr>';
    //$counter ++;
    //if ($counter == $rowCountTel || $counter <= 1){
    //}
}
echo '<tr><td> </td><td><a class="right" href="addPhoneNumber.php">Telefoonnummer toevoegen</a></td></tr>';
?>
								
							</tr>
						</table>
						</div>
开发者ID:KikiGerritsen,项目名称:iProject,代码行数:31,代码来源:profiel.php

示例9: execute

 /**
  * Executes a prepared statement
  *
  * If the prepared statement included parameter markers, you must either:
  * call PDOStatement->bindParam() to bind PHP variables to the parameter markers:
  * bound variables pass their value as input and receive the output value,
  * if any, of their associated parameter markers or pass an array of input-only
  * parameter values
  *
  *
  * @param array $params             An array of values with as many elements as there are
  *                                  bound parameters in the SQL statement being executed.
  * @return boolean                  Returns TRUE on success or FALSE on failure.
  */
 public function execute($params = null)
 {
     // bind values
     if (is_array($params)) {
         foreach ($params as $var => $value) {
             $this->bindValue($var + 1, $value);
         }
     }
     // prepare statement
     $this->statement = sqlsrv_prepare($this->connection, $query, $this->bindParams);
     if ($this->statement == false) {
         $this->handleError();
     }
     $result = sqlsrv_execute($this->statement);
     if ($result === false) {
         $this->handleError();
         return false;
     }
     return true;
 }
开发者ID:k0ka,项目名称:doctrine-sqlsrv,代码行数:34,代码来源:Sqlsrv.php

示例10: p_query

 public function p_query($sql, $params)
 {
     $prep_params = array();
     for ($x = 0; $x < count($params); $x++) {
         $prep_params[] =& $params[$x];
     }
     $stmt = sqlsrv_prepare($this->dbh, $sql, $prep_params);
     if ($stmt === false) {
         return false;
     }
     return sqlsrv_execute($stmt);
 }
开发者ID:posei,项目名称:tbs-sqlsrv,代码行数:12,代码来源:tbsDbSqlServer.class.php

示例11: prepare

 public function prepare($query, $params = array())
 {
     global $conn;
     set_error_handler(function ($errno, $errstr, $errfile, $errline, array $errcontext) {
         // error was suppressed with the @-operator
         if (0 === error_reporting()) {
             return false;
         }
         throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
     });
     try {
         $ret = sqlsrv_prepare($conn, $query, $params);
         if (!$ret) {
             error_out(var_export(sqlsrv_errors(), true));
         }
         return $ret;
     } catch (Exception $e) {
         //
     }
     restore_error_handler();
 }
开发者ID:hughlaura,项目名称:php_oracle_handytools,代码行数:21,代码来源:EngineSQLServer.class.php

示例12: execute

 /**
  * {@inheritdoc}
  */
 public function execute($params = null)
 {
     if ($params) {
         $hasZeroIndex = array_key_exists(0, $params);
         foreach ($params as $key => $val) {
             $key = $hasZeroIndex && is_numeric($key) ? $key + 1 : $key;
             $this->bindValue($key, $val);
         }
     }
     if (!$this->stmt) {
         $stmt = sqlsrv_prepare($this->conn, $this->sql, $this->params);
         if (!$stmt) {
             throw SQLSrvException::fromSqlSrvErrors();
         }
         $this->stmt = $stmt;
     }
     if (!sqlsrv_execute($this->stmt)) {
         throw SQLSrvException::fromSqlSrvErrors();
     }
     if ($this->lastInsertId) {
         sqlsrv_next_result($this->stmt);
         sqlsrv_fetch($this->stmt);
         $this->lastInsertId->setId(sqlsrv_get_field($this->stmt, 0));
     }
 }
开发者ID:doctrine,项目名称:dbal,代码行数:28,代码来源:SQLSrvStatement.php

示例13: array

 /**
  * (non-PHPdoc)
  * @see classes/connectionengine/Connect_STH#procedure($procedureName, $params)
  */
 public function &procedure($procedureName = 0, $params = array())
 {
     $objReturned = null;
     $result = null;
     if ($procedureName != 0) {
         throw new ConnectionengineException('$procedureName is null.', __FILE__, __LINE__, sqlsrv_errors());
     }
     $callString = sprintf('EXEC %s ', $procedureName);
     if (count($params) > 0) {
         //$callString .= ' (';
         for ($index = 0, $indexMax = count($params); $index < $indexMax; $index++) {
             if ($index != $indexMax - 1) {
                 $callString .= $params[$index][0] . ',';
             } else {
                 $callString .= $params[$index][0];
             }
         }
         // foreach
         //$callString .= ' )';
     }
     // if
     //$callString .= ' }';
     /* Create the statement. */
     $stmt = sqlsrv_prepare($this->connection, $callString, null);
     if (!$stmt) {
         throw new ConnectionengineException('Error in preparing statement.', __FILE__, __LINE__, sqlsrv_errors());
     }
     $result = sqlsrv_execute($stmt);
     if ($this->debug == true) {
         echo Logger::Log($callString);
     }
     // Traitement erreurs
     if ($result === false && $procedureName != 'sp_start_job') {
         print_r(sqlsrv_errors());
         //echo "Error in query preparation/execution.\n";
         throw new ConnectionengineException('Error on query (KO):' . $callString, __FILE__, __LINE__, sqlsrv_errors());
     } else {
         $objReturned = true;
     }
     //	$objReturned = new Sqlsrv_result_STH ( & $result , $this->defaultAssocType, $query );
     //	$objReturned->debug = $this->debug;
     return $objReturned;
 }
开发者ID:BGCX067,项目名称:faireconnaitre-svn-to-git,代码行数:47,代码来源:Sqlsrv_Connect_STH.class.php

示例14: setActive

 /**
  * Get the record from the specified table using the given $tableName, $searchFieldName and $searchValue
  *  and set the "Active" field to $value
  * @param $tableName :  string - name of the table
  * @param $searchFieldName :  The fieldname of the record you want to do the search on
  * @param $searchValue : either integer(only) or alphanumeric
  * @param $Active : Sets the 'Active' field to TRUE or FALSE
  * @return bool: Returns TRUE or FALSE.
  */
 function setActive($tableName, $searchFieldName, $searchValue, $Active)
 {
     if ($Active === true) {
         $active = 'TRUE';
     } else {
         $active = 'FALSE';
     }
     if (is_numeric($searchValue)) {
         // Finds whether a variable is a number or a numeric string
         $sql = 'UPDATE' . $tableName . 'SET Active =' . $active . 'WHERE' . $searchFieldName . ' = ' . $searchValue;
     } else {
         $sql = 'UPDATE' . $tableName . 'SET Active =' . $active . 'WHERE' . $searchFieldName . " = '" . $searchValue . "'";
     }
     //prepare statement
     $stmt = sqlsrv_prepare(Database::getConnection(), $sql);
     if (!$stmt) {
         return false;
     }
     $result = sqlsrv_execute($stmt);
     return $result;
 }
开发者ID:beingsane,项目名称:BusinessEntity,代码行数:30,代码来源:BaseDB.class.php

示例15: user_is_role

function user_is_role($email, $role)
{
    $return_value = 0;
    $user_id = user_exist_sqlsrv($email);
    $role_id = role_to_roleid($role);
    global $conn;
    $qry = "SELECT count(*) AS count FROM user_role WHERE user_id = ? AND role_id = ? AND active = 1";
    $params = array(&$user_id, &$role_id);
    $rst = sqlsrv_prepare($conn, $qry, $params);
    sqlsrv_execute($rst);
    sqlsrv_fetch($rst);
    error_log("checked {$email} for role {$role} using {$user_id} and {$role_id}");
    $return_value = sqlsrv_get_field($rst, 0);
    sql_errors_display("from user is role");
    return $return_value;
}
开发者ID:rickbanghart,项目名称:ttracker,代码行数:16,代码来源:ttrack_functions.php


注:本文中的sqlsrv_prepare函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。