本文整理汇总了PHP中sqlsrv_errors函数的典型用法代码示例。如果您正苦于以下问题:PHP sqlsrv_errors函数的具体用法?PHP sqlsrv_errors怎么用?PHP sqlsrv_errors使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sqlsrv_errors函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例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: dbGetErrorMsg
function dbGetErrorMsg()
{
$retVal = sqlsrv_errors();
$retVal = $retVal[0]["message"];
$retVal = preg_replace('/\\[Microsoft]\\[SQL Server Native Client [0-9]+.[0-9]+](\\[SQL Server\\])?/', '', $retVal);
return $retVal;
}
示例4: 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;
}
示例5: AttemptConnection
public function AttemptConnection()
{
if (empty($this->type)) {
return false;
} elseif ($this->type == "MySQL") {
$this->connection = mysqli_connect($this->address, $this->username, $this->password, $this->database);
if (!$this->connection) {
$this->lastErrorMessage = "Error: Unable to connect to MySQL." . PHP_EOL . "Debugging errno: " . mysqli_connect_errno() . PHP_EOL . "Debugging error: " . mysqli_connect_error() . PHP_EOL;
return false;
}
//SQL Server
} elseif ($this->type == "MSSQL") {
$connectionInfo = array("Database" => $this->database, "UID" => $this->username, "PWD" => $this->password);
$this->connection = sqlsrv_connect($this->address, $connectionInfo);
if (!$this->connection) {
$errorString = "";
if (($errors = sqlsrv_errors()) != null) {
foreach ($errors as $error) {
$errorString .= PHP_EOL . "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" . PHP_EOL;
$errorString .= "SQLSTATE: " . $error['SQLSTATE'] . PHP_EOL;
$errorString .= "code: " . $error['code'] . PHP_EOL;
$errorString .= "message: " . $error['message'] . PHP_EOL;
}
}
$this->lastErrorMessage = "Error: Unable to connect to SQL Server." . PHP_EOL . "Debugging error: " . $errorString . PHP_EOL;
$this->lastError = $errorString;
return false;
}
}
return $this->connection;
}
示例6: begin_trans
function begin_trans()
{
if (sqlsrv_begin_transaction($this->conn) == false) {
echo "Could not begin transaction.\n";
die(print_r(sqlsrv_errors(), true));
}
$this->in_trans = true;
}
示例7: begin_trans
function begin_trans()
{
if (mysql_query("BEGIN") == false) {
echo "Could not begin transaction.\n";
die(print_r(sqlsrv_errors(), true));
}
$this->in_trans = true;
}
示例8: query
/**
* Enviar query para servidor SQL
*
* @param string $query sql query
*
* @return void
*/
public function query($query)
{
$query = filter_var($query, FILTER_SANITIZE_STRING);
$this->_query = sqlsrv_query($this->conn, $query);
if (!$this->_query) {
die(print_r(sqlsrv_errors(), true));
}
}
示例9: errors
/**
* Returns all errors as a string
*
* @return string
*/
protected function errors()
{
$string = '';
foreach (sqlsrv_errors() as $error) {
$string .= '[' . $error[0] . ':' . $error[1] . ']: ' . $error[2] . ', ';
}
return substr($string, 0, -2);
}
示例10: query
public function query($sql)
{
$this->connect();
$this->stmt = sqlsrv_query($this->conn, $sql);
if ($this->stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
}
示例11: loadEventsByLocation
public function loadEventsByLocation(int $location)
{
$query = 'SELECT event.name AS name, event.description AS description FROM event INNER JOIN location ON event.fk_location = location.id_location WHERE location.id_location = ?';
$stmt = sqlsrv_query($this->connection, $query, [$location]);
if (sqlsrv_errors()) {
http_response_code(500);
}
return $stmt;
}
示例12: __construct
public function __construct($dbName = "ecs")
{
$dbHost = ".";
$connectionInfo = array("Database" => $dbName, "UID" => "sa", "PWD" => "sa");
$this->conn = sqlsrv_connect($dbHost, $connectionInfo);
if (!$this->conn) {
exit('Connect Error (' . sqlsrv_errors() . ') ' . sqlsrv_errors());
}
}
示例13: loadLocationsByIdAndName
/**
* Lädt die Orte, welche den mitgegebenen String im Namen enthalten.
* Offset: Beim wievielten Datensatz das Laden beginnt
* Rows: Wie viele Datensätze geladen werden
* @param int $offset
* @param int $rows
* @param string $location
* @return bool|resource
*/
public function loadLocationsByIdAndName(int $offset, int $rows, string $location)
{
$query = "SELECT \n id_location AS id_location,\n name AS name, \n description AS description\n FROM location\n WHERE location.name LIKE ?\n ORDER BY id_location\n OFFSET {$offset} ROWS \n FETCH NEXT {$rows} ROWS ONLY";
$stmt = sqlsrv_query(Database::getConnection(), $query, ['%' . $location . '%']);
if (sqlsrv_errors()) {
http_response_code(500);
}
return $stmt;
}
示例14: query
/**
* Executes the SQL query.
* @param string SQL statement.
* @return IDibiResultDriver|NULL
* @throws DibiDriverException
*/
public function query($sql)
{
$this->resultSet = sqlsrv_query($this->connection, $sql);
if ($this->resultSet === FALSE) {
$info = sqlsrv_errors();
throw new DibiDriverException($info[0]['message'], $info[0]['code'], $sql);
}
return is_resource($this->resultSet) ? clone $this : NULL;
}
示例15: getErrors
/**
* Get SQL errors
*
* @return string
*/
public function getErrors()
{
$errors = null;
$errorAry = sqlsrv_errors();
foreach ($errorAry as $key => $value) {
$errors .= 'SQLSTATE: ' . $value['SQLSTATE'] . ', CODE: ' . $value['code'] . ' => ' . stripslashes($value['message']) . PHP_EOL;
}
return $errors;
}