本文整理匯總了PHP中sqlsrv_query函數的典型用法代碼示例。如果您正苦於以下問題:PHP sqlsrv_query函數的具體用法?PHP sqlsrv_query怎麽用?PHP sqlsrv_query使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了sqlsrv_query函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: sql_query
function sql_query($sqltype, $query, $con)
{
if ($sqltype == 'mysql') {
if (class_exists('mysqli')) {
return $con->query($query);
} elseif (function_exists('mysql_query')) {
return mysql_query($query);
}
} elseif ($sqltype == 'mssql') {
if (function_exists('sqlsrv_query')) {
return sqlsrv_query($con, $query);
} elseif (function_exists('mssql_query')) {
return mssql_query($query);
}
} elseif ($sqltype == 'pgsql') {
return pg_query($query);
} elseif ($sqltype == 'oracle') {
return oci_execute(oci_parse($con, $query));
} elseif ($sqltype == 'sqlite3') {
return $con->query($query);
} elseif ($sqltype == 'sqlite') {
return sqlite_query($con, $query);
} elseif ($sqltype == 'odbc') {
return odbc_exec($con, $query);
} elseif ($sqltype == 'pdo') {
return $con->query($query);
}
}
示例2: query
public function query($sql)
{
LogMaster::log($sql);
if ($this->start_from) {
$res = sqlsrv_query($this->connection, $sql, array(), array("Scrollable" => SQLSRV_CURSOR_STATIC));
} else {
$res = sqlsrv_query($this->connection, $sql);
}
if ($res === false) {
$errors = sqlsrv_errors();
$message = array();
foreach ($errors as $error) {
$message[] = $error["SQLSTATE"] . $error["code"] . $error["message"];
}
throw new Exception("SQLSrv operation failed\n" . implode("\n\n", $message));
}
if ($this->insert_operation) {
sqlsrv_next_result($res);
$last = sqlsrv_fetch_array($res);
$this->last_id = $last["dhx_id"];
sqlsrv_free_stmt($res);
}
if ($this->start_from) {
$data = sqlsrv_fetch($res, SQLSRV_SCROLL_ABSOLUTE, $this->start_from - 1);
}
return $res;
}
示例3: get_count
function get_count($MID)
{
$query = "SELECT * FROM riot4.users WHERE logged_MID = ?";
$params = array($MID);
$statement = sqlsrv_query($conn, $query, $params);
return sqlsrv_num_rows($statement);
}
示例4: RetrieveEmployeesByPosition
function RetrieveEmployeesByPosition($employeePosition1 = null, $employeePosition2 = null, $employeePosition3 = null)
{
$dtoArray = array();
$subQuery = "SELECT posId FROM OHPS";
if (!empty($employeePosition1)) {
$subQuery = $subQuery . " WHERE name LIKE '%" . $employeePosition1 . "%'";
}
if (!empty($employeePosition2)) {
$subQuery = $subQuery . " OR name LIKE '%" . $employeePosition2 . "%'";
}
if (!empty($employeePosition3)) {
$subQuery = $subQuery . " OR name LIKE '%" . $employeePosition3 . "%'";
}
$query = "SELECT empID, firstName, middleName, lastName FROM OHEM WHERE position IN (" . $subQuery . ") ORDER BY firstName DESC";
$recordSet = sqlsrv_query($this->sqlserverConnection, $query);
$index = 0;
while ($record = sqlsrv_fetch_array($recordSet, SQLSRV_FETCH_ASSOC)) {
$dto = new EmployeeDTO();
$dto->empID = $record["empID"];
$dto->firstName = $record["firstName"];
$dto->middleName = $record["middleName"];
$dto->lastName = $record["lastName"];
$dtoArray[$index] = $dto;
$index++;
}
sqlsrv_free_stmt($recordSet);
return $dtoArray;
}
示例5: RetrieveRecordArray
function RetrieveRecordArray($filter = null)
{
$dtoArray = array();
$query = "SELECT Address, AddrType, Street, StreetNo, Building, ZipCode, Block, City, State, Country, U_Secretaria FROM CRD1 WHERE " . $filter;
if (empty($filter)) {
$query = "SELECT Address, AddrType, Street, StreetNo, Building, ZipCode, Block, City, State, Country, U_Secretaria FROM CRD1 WHERE Address IS NOT NULL";
}
$recordSet = sqlsrv_query($this->sqlserverConnection, $query);
$index = 0;
while ($record = sqlsrv_fetch_array($recordSet, SQLSRV_FETCH_ASSOC)) {
$dto = new PartnerAddressDTO();
$dto->addressLabel = $record["Address"];
$dto->addrType = $record["AddrType"];
$dto->street = $record["Street"];
$dto->streetNo = $record["StreetNo"];
$dto->building = $record["Building"];
$dto->zipCode = $record["ZipCode"];
$dto->block = $record["Block"];
$dto->city = $record["City"];
$dto->state = $record["State"];
$dto->country = $record["Country"];
$dto->locationRef = $record["U_Secretaria"];
$dtoArray[$index] = $dto;
$index++;
}
sqlsrv_free_stmt($recordSet);
return $dtoArray;
}
示例6: checkUserSession
public function checkUserSession()
{
if (!isset($this->SessionID)) {
return array(false, "Session key empty");
}
$SessionID = $this->SessionID;
$sql = "SELECT Email FROM Sessions WHERE SessionID = ?";
$params = array($SessionID);
global $conn;
if ($conn) {
$stmt = sqlsrv_query($conn, $sql, $params);
if ($stmt === false) {
return array(false, "Connection to server failed.");
} else {
if (sqlsrv_has_rows($stmt) > 0) {
$email = '';
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
$email = $row['Email'];
}
return array(true, $email);
} else {
return array(false, "Failed to authenticate");
}
}
}
}
示例7: GetFacultyQuestions
function GetFacultyQuestions($groupid)
{
include_once 'db_Connection.php';
$conn = sqlsrv_connect($serverName, $connectionInfo);
$questionvalues = array();
$questions = array();
$faculty = array();
$facultyquestions = array();
if ($conn) {
//----get acadyear-------------------
$acid = 0;
$sqlstr = " SELECT [AcadYearID] FROM [dbo].[Groups] where [groupid]=? ";
$params = array($groupid);
$sqlquery = sqlsrv_query($conn, $sqlstr, $params);
if ($sqlquery) {
while ($row = sqlsrv_fetch_array($sqlquery, SQLSRV_FETCH_ASSOC)) {
$acid = $row['AcadYearID'];
}
sqlsrv_free_stmt($sqlquery);
}
$sqlstr = " SELECT [questionTypeId],[value],[text] " . " FROM [dbo].[QuestionValues] " . " order by questionTypeId ";
// $params = array ($acid);
$sqlquery = sqlsrv_query($conn, $sqlstr);
if ($sqlquery) {
while ($row = sqlsrv_fetch_object($sqlquery)) {
$questionvalues[] = $row;
}
sqlsrv_free_stmt($sqlquery);
}
//----get question array-------------------
$sqlstr = " SELECT [QuestionID],[QueastionText],[questionType],[maxmark],-1 as mark,'' as description " . " FROM [dbo].[Questions] " . " where [QuestionLecturer]=0 " . " and [Acadyear]=? ";
$params = array($acid);
$sqlquery = sqlsrv_query($conn, $sqlstr, $params);
if ($sqlquery) {
while ($row = sqlsrv_fetch_object($sqlquery)) {
$row->questionValues = array();
foreach ($questionvalues as &$questValue) {
if ($questValue->questionTypeId === $row->questionType) {
array_push($row->questionValues, $questValue);
}
}
$questions[] = $row;
}
sqlsrv_free_stmt($sqlquery);
}
//----get faculty-------------------
$sqlstr = " SELECT [FacultyID],[FacultyName] FROM [dbo].[Groups] " . " where [groupid]=? ";
$params = array($groupid);
$sqlquery = sqlsrv_query($conn, $sqlstr, $params);
if ($sqlquery) {
while ($row = sqlsrv_fetch_object($sqlquery)) {
$row->quests = $questions;
$faculty[] = $row;
}
$facultyquestions = array("result" => 0, "data" => $faculty);
}
sqlsrv_close($conn);
}
return $facultyquestions;
}
示例8: exec
public function exec($query, $security = NULL)
{
if (empty($query)) {
return false;
}
return sqlsrv_query($this->connect, $query);
}
示例9: dbcall
function dbcall()
{
session_start();
$seubid = (string) session_id();
$server = "bamsql2";
$options = array("UID" => "genes", "PWD" => "Genes12", "Database" => "genes");
$conn = sqlsrv_connect($server, $options);
if ($conn === false) {
die("<pre>" . print_r(sqlsrv_errors(), true));
}
$rno = $_POST['Rnumber'];
$name = $_POST['name'];
$email = $_POST['email'];
$gender = $_POST['gender'];
$sql = "insert INTO dbo.contactinfo values('{$rno}','{$name}','{$email}','{$gender}')";
$query = sqlsrv_query($conn, $sql);
if ($query === false) {
exit("<pre>" . print_r(sqlsrv_errors(), true));
}
#while ($row = sqlsrv_fetch_array($query))
# { echo "<p>Hello, $row[ascore]!</p>";
#}
sqlsrv_free_stmt($query);
sqlsrv_close($conn);
}
示例10: execute_query
public function execute_query($sql, $cursortype = SQLSRV_CURSOR_FORWARD)
{
$sqldirective = strtoupper(substr($sql, 0, strpos($sql, ' ')));
switch ($sqldirective) {
case 'SELECT':
$type = SQL_QUERY_SELECT;
break;
case 'INSERT':
$type = SQL_QUERY_INSERT;
break;
case 'UPDATE':
$type = SQL_QUERY_UPDATE;
break;
case 'DELETE':
$type = SQL_QUERY_UPDATE;
break;
default:
print_error('unknownsqldirective', 'block_vmoodle');
return false;
}
$this->query_start($sql, null, $type);
$result = sqlsrv_query($this->sqlsrv, $sql, null, array('Scrollable' => $cursortype));
$this->query_end($result);
return $result;
}
示例11: RetrieveRecordArray
function RetrieveRecordArray($filter = null)
{
$dtoArray = array();
$query = "SELECT * FROM ( ";
$query .= "SELECT EQP.customer AS codigoCliente, CLI.cardName + ' (' + CLI.cardCode + ')' AS nomeCliente, EQP.insID AS codigoEquipamento, EQP.manufSN AS serieEquipamento, MDL.id AS codigoModelo, MDL.modelo AS tagModelo, ";
$query .= "FAB.FirmName AS fabricante, CHAM.id AS numeroChamado, CHAM.tempoAtendimento, MONTH(CHAM.dataAtendimento) AS mesReferencia, YEAR(CHAM.dataAtendimento) AS anoReferencia ";
$query .= "FROM MYSQL...chamadoServico CHAM ";
$query .= "JOIN OINS EQP ON CHAM.cartaoEquipamento = EQP.insID ";
$query .= "JOIN OCRD CLI ON EQP.customer = CLI.cardCode ";
$query .= "JOIN MYSQL...modeloEquipamento MDL ON EQP.U_Model = MDL.id ";
$query .= "JOIN OMRC FAB ON MDL.fabricante = FAB.FirmCode ";
$query .= " ) LABOREXPENSES ";
if (isset($filter) && !empty($filter)) {
$query = $query . " WHERE " . $filter;
}
$recordSet = sqlsrv_query($this->sqlserverConnection, $query . " ORDER BY nomeCliente, serieEquipamento");
$index = 0;
while ($record = sqlsrv_fetch_array($recordSet, SQLSRV_FETCH_ASSOC)) {
$dto = new LaborExpenseDTO();
$dto->codigoCliente = $record["codigoCliente"];
$dto->nomeCliente = $record["nomeCliente"];
$dto->codigoEquipamento = $record["codigoEquipamento"];
$dto->serieEquipamento = $record["serieEquipamento"];
$dto->codigoModelo = $record["codigoModelo"];
$dto->tagModelo = $record["tagModelo"];
$dto->fabricante = $record["fabricante"];
$dto->numeroChamado = $record["numeroChamado"];
$dto->tempoAtendimento = $record["tempoAtendimento"];
$dtoArray[$index] = $dto;
$index++;
}
sqlsrv_free_stmt($recordSet);
return $dtoArray;
}
示例12: existeTabla
/**
*
* @param resource $conn
* Recurso que contiene la conexión SQL.
* @param string $tabla
* @param boolean $comprobar
* Si está a true (valor por defecto) siempre hace la comprobación.
* Si se pone el valor a false sólo hace la comprobación cuando es
* día 1.
* @return mixed array si hay un error SQL. Si la tabla no existe false. Si la
* tabla existe true.
*/
function existeTabla($conn, $tabla, $comprobarTabla = 1)
{
$hoy = getdate();
if ($hoy["mday"] == 1 or $comprobarTabla) {
global $respError;
$sql = "select * from dbo.sysobjects where id = object_id(N'{$tabla}')";
// Ejecutar una consulta SQL para saber si existe la tabla de auditoría
//////////////////////////////////////////////////////
$stmt = sqlsrv_query($conn, $sql);
if ($stmt === false) {
if (($errors = sqlsrv_errors()) != null) {
$SQLSTATE = $errors[0]["SQLSTATE"];
$Cerror = $errors[0]["code"];
$Merror = utf8_encode($errors[0]["message"]);
if ($farmacia == FARMACIA_DEBUG or strlen(FARMACIA_DEBUG) == 0) {
if (DEBUG & DEBUG_ERROR_SQL) {
$mensaje = "--[" . date("c") . "] código: {$Cerror} mensaje: {$Merror} \n";
$mensaje .= "--Error en el fichero: " . __FILE__ . ", en la línea: " . __LINE__;
error_log($mensaje . $sql . "\r\n", 3, DIRECTORIO_LOG . __FUNCTION__ . "_" . date("YmdH") . ".log");
}
}
// Error al hacer la consulta
return $respError->errorSQL($SQLSTATE, $Cerror, $Merror);
}
}
if (sqlsrv_has_rows($stmt) === false) {
// La tabla no existe.
return false;
}
}
// La tabla existe o no hay que comprobarlo
return true;
}
示例13: RetrieveOther
function RetrieveOther($filter = null)
{
$dtoArray = array();
$query = "SELECT OINV.Serial, INV1.Usage, OINV.CardCode, OINV.CardName, OINV.DocTotal, ORCT.CashSum, ORCT.CheckSum, ORCT.TrsfrSum, ORCT.DocDueDate, OSLP.SlpCode, OSLP.SlpName, OINV.U_demFaturamento FROM ORCT ";
$query .= "JOIN RCT2 ON RCT2.DocNum = ORCT.DocEntry ";
$query .= "JOIN OINV ON OINV.DocEntry = RCT2.DocEntry ";
$query .= "JOIN INV1 ON INV1.DocEntry = OINV.DocEntry ";
$query .= "JOIN OSLP ON OSLP.SlpCode = OINV.SlpCode ";
if (!empty($filter)) {
$query .= " WHERE " . $filter;
}
$recordSet = sqlsrv_query($this->sqlserverConnection, $query);
$index = 0;
while ($record = sqlsrv_fetch_array($recordSet, SQLSRV_FETCH_ASSOC)) {
$dto = new InvoicePaymentDTO();
$dto->serial = $record['Serial'];
$dto->tipo = $record['Usage'];
$dto->cardCode = $record['CardCode'];
$dto->cardName = $record['CardName'];
$dto->valorNotaFiscal = $record['DocTotal'];
$dto->valorDinheiro = $record['CashSum'];
$dto->valorCheque = $record['CheckSum'];
$dto->valorDeposito = $record['TrsfrSum'];
$dto->date = $record['DocDueDate'];
$dto->slpCode = $record['SlpCode'];
$dto->slpName = $record['SlpName'];
$dto->demFaturamento = $record['U_demFaturamento'];
$dtoArray[$index] = $dto;
$index++;
}
sqlsrv_free_stmt($recordSet);
return $dtoArray;
}
示例14: RetrieveRecordArray
function RetrieveRecordArray($filter = null)
{
$dtoArray = array();
// Procura na tabela OCRD (Partner Card)
$query = "SELECT CardCode, CardName, CardFName, frozenFor, CntctPrsn, Phone1, IndustryC FROM OCRD WHERE " . $filter;
if (empty($filter)) {
$query = "SELECT CardCode, CardName, CardFName, frozenFor, CntctPrsn, Phone1, IndustryC FROM OCRD WHERE CardName IS NOT NULL ORDER BY cardName";
}
$recordSet = sqlsrv_query($this->sqlserverConnection, $query);
$index = 0;
while ($record = sqlsrv_fetch_array($recordSet, SQLSRV_FETCH_ASSOC)) {
$dto = new BusinessPartnerDTO();
$dto->cardCode = $record['CardCode'];
$dto->cardName = $record['CardName'];
$dto->cardFName = $record['CardFName'];
$dto->inactive = $record['frozenFor'];
$dto->contactPerson = $record['CntctPrsn'];
$dto->telephoneNumber = $record['Phone1'];
$dto->industry = $record['IndustryC'];
$dtoArray[$index] = $dto;
$index++;
}
sqlsrv_free_stmt($recordSet);
return $dtoArray;
}
示例15: Query
public function Query($Procedimiento, $RetornaDatos, $arrayValores = "")
{
$parametros = array();
$NombreServidor = constant("sqlHost");
$InfoConexion = array("UID" => constant("sqlUsuario"), "PWD" => constant("sqlContrasena"), "Database" => $this->NombreBaseDatos);
$conn = sqlsrv_connect($NombreServidor, $InfoConexion);
if (is_array($arrayValores)) {
$stringInterrogacion = "(?";
for ($i = 1; $i < count($arrayValores); $i++) {
$stringInterrogacion .= ",?";
}
$stringInterrogacion .= ")";
$Procedimiento = "{call " . $Procedimiento . " " . $stringInterrogacion . "}";
for ($i = 0; $i < count($arrayValores); $i++) {
array_push($parametros, array($arrayValores[$i], SQLSRV_PARAM_IN));
}
} else {
$Procedimiento = "{call " . $Procedimiento . "}";
}
$stmt3 = sqlsrv_query($conn, $Procedimiento, $parametros);
if ($RetornaDatos) {
$array = array();
while ($obj = sqlsrv_fetch_array($stmt3, SQLSRV_FETCH_ASSOC)) {
$array[] = $obj;
}
return $array;
sqlsrv_free_stmt($stmt3);
}
sqlsrv_close($conn);
}