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


PHP sqlsrv_fetch函数代码示例

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


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

示例1: setcookie

    echo $u_id;
    setcookie('workwithme', $u_id, time() + 60 * 60 * 24);
} else {
    $is_new = 0;
    echo 'This is an old request';
}
include 'DBConnection.php';
if ($is_new == 0) {
    echo '<br/>This is an old request';
    $tsql = "SELECT name, location, start_time, end_time FROM Event WHERE uid = '" . $u_id . "'";
    $stmt = sqlsrv_query($conn, $tsql);
    if ($stmt === false) {
        echo "Error in statement preparation/execution.\n";
        die(print_r(sqlsrv_errors(), true));
    }
    $check = sqlsrv_fetch($stmt);
    echo "<br/>The query returned: {$check}";
    if ($check) {
        $username_new = sqlsrv_get_field($stmt, 0);
        $location_new = sqlsrv_get_field($stmt, 1);
        $start_time_new = sqlsrv_get_field($stmt, 2);
        $end_time_new = sqlsrv_get_field($stmt, 3);
        echo 'Name: ' + $username_new;
        echo 'Location' + $location_new;
        echo 'Start:' + $start_time_new;
        echo 'End:' + $end_time_new;
    } else {
        $is_new = 1;
    }
    sqlsrv_free_stmt($stmt);
}
开发者ID:nikitabe,项目名称:Old-WorkWithMe-by-Nikita,代码行数:31,代码来源:update_status.php

示例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;
 }
开发者ID:rokkit,项目名称:temp,代码行数:27,代码来源:db_sqlsrv.php

示例3: seek

 public function seek($offset)
 {
     if ($this->offsetExists($offset) and sqlsrv_fetch($this->_result, $offset)) {
         // Set the current row to the offset
         $this->_current_row = $this->_internal_row = $offset;
         return TRUE;
     } else {
         return FALSE;
     }
 }
开发者ID:ryross,项目名称:kohana-database-sqlsrv,代码行数:10,代码来源:result.php

示例4: cs_sql_count

function cs_sql_count($cs_file, $sql_table, $sql_where = 0, $distinct = 0)
{
    global $cs_db;
    $row = empty($distinct) ? '*' : 'DISTINCT ' . $distinct;
    $sql_query = 'SELECT COUNT(' . $row . ') FROM ' . $cs_db['prefix'] . '_' . $sql_table;
    $sql_query .= empty($sql_where) ? '' : ' WHERE ' . $sql_where;
    $sql_query = str_replace('{pre}', $cs_db['prefix'], $sql_query);
    if (!($sql_data = sqlsrv_query($cs_db['con'], $sql_query))) {
        cs_error_sql($cs_file, 'cs_sql_count', cs_sql_error(0, $sql_query));
        return NULL;
    }
    sqlsrv_fetch($sql_data);
    $sql_result = sqlsrv_get_field($sql_data, 0);
    sqlsrv_free_stmt($sql_data);
    cs_log_sql($cs_file, $sql_query);
    return $sql_result;
}
开发者ID:aberrios,项目名称:WEBTHESGO,代码行数:17,代码来源:sqlsrv.php

示例5: query

 public static function query($queryStr = '', $objectStr = '')
 {
     $queryDB = sqlsrv_query(self::$dbConnect, $queryStr);
     if (preg_match('/insert into/i', $queryDB)) {
         sqlsrv_next_result($queryDB);
         sqlsrv_fetch($queryDB);
         self::$insertID = sqlsrv_get_field($queryDB, 0);
     }
     if ($queryDB) {
         if (is_object($objectStr)) {
             $objectStr($queryDB);
         }
         //            sqlsrv_free_stmt($queryDB);
         return $queryDB;
     } else {
         self::$error = sqlsrv_errors();
         return false;
     }
 }
开发者ID:neworldwebsites,项目名称:noblessecms,代码行数:19,代码来源:DatabaseSqlserver.php

示例6: 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 ($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;
 }
开发者ID:mudassartufail,项目名称:dhtmlx,代码行数:19,代码来源:db_sqlsrv.php

示例7: get_topic_id

function get_topic_id($topic)
{
    $params = array($topic);
    $options = array("Scrollable" => 'static');
    $addTopicSQL = "INSERT into Topics Values (?)";
    $getTopicIDSQL = "SELECT TOP 1 TopicID FROM Topics \n                        WHERE Topic = ?\n                        ORDER BY TopicID Desc";
    $TopicID = 0;
    $addTopic = sqlsrv_query($con, $addTopicSQL, $params, $options);
    if ($addTopic === false) {
        die(print_r(sqlsrv_errors(), true));
    }
    $getTopicID = sqlsrv_query($con, $getTopicIDSQL, $params, $options);
    if ($getTopicID === false) {
        die(print_r(sqlsrv_errors(), true));
    }
    if (sqlsrv_fetch($getTopicID) === true) {
        $TopicID = sqlsrv_get_field($getTopicID, 0);
    }
    return $TopicID;
}
开发者ID:ninjamuffin,项目名称:SeniorDesignGroup5,代码行数:20,代码来源:CreateWorksheet.php

示例8: array

                                     <tr>
                                         <th>Institution</th>
                                         <th>Name</th>
                                         <th>Designation</th>
                                     </tr>
                                 </thead>
                                 
                                 <?php 
 $params = array();
 $options = array("Scrollable" => 'static');
 $adminsQuery = "\n        SELECT I.InstitutionName, A.FirstName, A.LastName, R.Designation\n        FROM Institutions as I, Administrators as A, RoleInstances as RI, Roles as R\n        WHERE A.RoleInstanceID = RI.RoleInstanceID AND\n              RI.RoleID = R.RoleID AND\n              R.Role = 'Admin' AND\n              I.InstitutionID = A.InstitutionID";
 $stmt = sqlsrv_query($con, $adminsQuery, $params, $options);
 if ($stmt === false) {
     die(print_r(sqlsrv_errors(), true));
 }
 while (sqlsrv_fetch($stmt) === true) {
     $institution = sqlsrv_get_field($stmt, 0);
     $fname = sqlsrv_get_field($stmt, 1);
     $lname = sqlsrv_get_field($stmt, 2);
     $designation = sqlsrv_get_field($stmt, 3);
     echo "<tr>";
     echo "<td>{$institution}</td>";
     echo "<td>{$fname} {$lname}</td>";
     echo "<td>{$designation}</td>";
 }
 ?>
                                     
                                 <tbody>
                                     
                                     
                                 </tbody>
开发者ID:ninjamuffin,项目名称:SeniorDesignGroup5,代码行数:31,代码来源:index.php

示例9: insert_id

 protected function insert_id($db, $result)
 {
     sqlsrv_next_result($result);
     sqlsrv_fetch($result);
     return (int) sqlsrv_get_field($result, 0);
 }
开发者ID:amanullah-1,项目名称:php-crud-api,代码行数:6,代码来源:api.php

示例10: array

 $params = array($courseID, $enrollmentID);
 $options = array("Scrollable" => SQLSRV_CURSOR_KEYSET);
 $worksheetsubmissionsSQL = "SELECT CT.CourseName, WS.WorksheetNumber, SS.StudentSubmissionID, WS.WorksheetID\n            FROM CourseTypes CT, Courses C, Enrollment ER, Worksheets WS, StudentSubmissions SS\n            WHERE C.CourseID = ? AND\n                  ER.EnrollmentID = ? AND\n\t\t\t\t  ER.CourseID = C.CourseID AND\n                  WS.CourseID = C.CourseID AND\n                  C.CourseTypesID = CT.CourseTypesID AND\n                  SS.EnrollmentID = ER.EnrollmentID AND\n                  SS.WorksheetID = WS.WorksheetID";
 $worksheetsubmissions = sqlsrv_query($con, $worksheetsubmissionsSQL, $params, $options);
 if ($worksheetsubmissions === false) {
     die(print_r(sqlsrv_errors(), true));
 }
 $resultlength = sqlsrv_num_rows($worksheetsubmissions);
 if ($resultlength == 0) {
     echo "No Submissions!";
 } else {
     $coursenames = [];
     $worksheetnumbers = [];
     $studentsubmissionids = [];
     $worksheetids = [];
     while (sqlsrv_fetch($worksheetsubmissions) === true) {
         $coursenames[] = sqlsrv_get_field($worksheetsubmissions, 0);
         $worksheetnumbers[] = sqlsrv_get_field($worksheetsubmissions, 1);
         $studentsubmissionids[] = sqlsrv_get_field($worksheetsubmissions, 2);
         $worksheetids[] = sqlsrv_get_field($worksheetsubmissions, 3);
     }
     for ($i = 0; $i < $resultlength; $i++) {
         echo "<tr><td>{$coursenames[$i]}</td><td>{$worksheetnumbers[$i]}</td><td>TBD</td><td><form method =\"post\" action=\"/Teacher/MyCourses/ViewCourse/ViewWorksheet/ViewSubmission/\" name=\"viewsubmissionlink{$i}\" id=\"viewsubmissionlink{$i}\"><input hidden type=\"text\" name=\"worksheetID\" value=\"{$worksheetids[$i]}\"><input hidden type=\"text\" name=\"submissionID\" value=\"{$studentsubmissionids[$i]}\"><button class=\"btn btn-primary\">View Submission</button></form></td></tr>";
     }
 }
 ?>
                                 </tbody>
                             </table>
                         </div>
                     </div>
                    
开发者ID:ninjamuffin,项目名称:SeniorDesignGroup5,代码行数:30,代码来源:index.php

示例11: query

 function query($query)
 {
     //if flag to convert query from MySql syntax to MS-Sql syntax is true
     //convert the query
     if ($this->convertMySqlToMSSqlQuery == true) {
         $query = $this->ConvertMySqlToMSSql($query);
     }
     // Initialise return
     $return_val = 0;
     // Flush cached values..
     $this->flush();
     // For reg expressions
     $query = trim($query);
     // Log how the function was called
     $this->func_call = "\$db->query(\"{$query}\")";
     // Keep track of the last query for debug..
     $this->last_query = $query;
     // Count how many queries there have been
     $this->num_queries++;
     // Use core file cache function
     if ($cache = $this->get_cache($query)) {
         return $cache;
     }
     // If there is no existing database connection then try to connect
     if (!isset($this->dbh) || !$this->dbh) {
         $this->connect($this->dbuser, $this->dbpassword, $this->dbname, $this->dbhost);
     }
     // Perform the query via std mssql_query function..
     $this->result = @sqlsrv_query($this->dbh, $query);
     // If there is an error then take note of it..
     if ($this->result === false) {
         $errors = sqlsrv_errors();
         if (!empty($errors)) {
             $is_insert = true;
             foreach ($errors as $error) {
                 $sqlError = "ErrorCode: " . $error['code'] . " ### State: " . $error['SQLSTATE'] . " ### Error Message: " . $error['message'] . " ### Query: " . $query;
                 $this->register_error($sqlError);
                 $this->show_errors ? trigger_error($sqlError, E_USER_WARNING) : null;
             }
         }
         return false;
     }
     // Query was an insert, delete, update, replace
     $is_insert = false;
     if (preg_match("/^(insert|delete|update|replace)\\s+/i", $query)) {
         $this->rows_affected = @sqlsrv_rows_affected($this->dbh);
         // Take note of the insert_id
         if (preg_match("/^(insert|replace)\\s+/i", $query)) {
             $identityresultset = @sqlsrv_query($this->dbh, "select SCOPE_IDENTITY()");
             if ($identityresultset != false) {
                 $identityrow = @sqlsrv_fetch($identityresultset);
                 $this->insert_id = $identityrow[0];
             }
         }
         // Return number of rows affected
         $return_val = $this->rows_affected;
     } else {
         // Take note of column info
         $i = 0;
         foreach (@sqlsrv_field_metadata($this->result) as $field) {
             foreach ($field as $name => $value) {
                 $name = strtolower($name);
                 if ($name == "size") {
                     $name = "max_length";
                 } else {
                     if ($name == "type") {
                         $name = "typeid";
                     }
                 }
                 $col->{$name} = $value;
             }
             $col->type = $this->get_datatype($col);
             $this->col_info[$i++] = $col;
             unset($col);
         }
         // Store Query Results
         $num_rows = 0;
         while ($row = @sqlsrv_fetch_object($this->result)) {
             // Store relults as an objects within main array
             $this->last_result[$num_rows] = $row;
             $num_rows++;
         }
         @sqlsrv_free_stmt($this->result);
         // Log number of rows the query returned
         $this->num_rows = $num_rows;
         // Return number of rows selected
         $return_val = $this->num_rows;
     }
     // disk caching of queries
     $this->store_cache($query, $is_insert);
     // If debug ALL queries
     $this->trace || $this->debug_all ? $this->debug() : null;
     return $return_val;
 }
开发者ID:raphealdabney,项目名称:ezSQL,代码行数:94,代码来源:ez_sql_sqlsrv.php

示例12: _fetch

 /**
  * @brief 결과를 fetch
  **/
 function _fetch($result)
 {
     if (!$this->isConnected() || $this->isError() || !$result) {
         return;
     }
     $c = sqlsrv_num_fields($result);
     $m = null;
     $output = array();
     while (sqlsrv_fetch($result)) {
         if (!$m) {
             $m = sqlsrv_field_metadata($result);
         }
         unset($row);
         for ($i = 0; $i < $c; $i++) {
             $row->{$m[$i]['Name']} = sqlsrv_get_field($result, $i, SQLSRV_PHPTYPE_STRING('utf-8'));
         }
         $output[] = $row;
     }
     if (count($output) == 1) {
         return $output[0];
     }
     return $output;
 }
开发者ID:hottaro,项目名称:xpressengine,代码行数:26,代码来源:DBMssql.class.php

示例13: checkDBSettings


//.........这里部分代码省略.........
                } else {
                    $errno = mysql_errno();
                    $error = mysql_error();
                }
                $errors['ERR_DB_ADMIN'] = $mod_strings['ERR_DB_ADMIN'] . $errno . ": {$error}).";
                installLog("ERROR:: {$errors['ERR_DB_ADMIN']}");
            }
        } else {
            if ($_SESSION['setup_db_type'] == 'mssql') {
                installLog("Testing priviliged account...");
                $connect_host = "";
                $_SESSION['setup_db_host_instance'] = trim($_SESSION['setup_db_host_instance']);
                if (empty($_SESSION['setup_db_host_instance'])) {
                    $connect_host = $_SESSION['setup_db_host_name'];
                } else {
                    $connect_host = $_SESSION['setup_db_host_name'] . "\\" . $_SESSION['setup_db_host_instance'];
                }
                if (isset($_SESSION['mssql_type'])) {
                    $connect_params = array("UID" => $_SESSION['setup_db_sugarsales_user'], "PWD" => $_SESSION['setup_db_sugarsales_password'], "MultipleActiveResultSets" => false);
                    $link = sqlsrv_connect($connect_host, $connect_params);
                } else {
                    $link = @mssql_connect($connect_host, $_SESSION['setup_db_admin_user_name'], $_SESSION['setup_db_admin_password']);
                }
                if ($link) {
                    installLog("Connection made for Privileged admin account using  host: {$_SESSION['setup_db_host_name']}, usr: {$_SESSION['setup_db_admin_user_name']}");
                    // database admin credentials are valid--can continue check on stuff
                    $tbl_exists_qry = "SELECT name FROM master..sysdatabases WHERE name = N'{$_SESSION['setup_db_database_name']}'";
                    if (isset($_SESSION['mssql_type'])) {
                        $res = sqlsrv_query($link, $tbl_exists_qry);
                    } else {
                        $res = mssql_query($tbl_exists_qry);
                    }
                    $db_exists = false;
                    if (isset($_SESSION['mssql_type']) && sqlsrv_fetch($res) == 1) {
                        $db_exists = true;
                        installLog("DB Exists and selected, will reuse {$_SESSION['setup_db_database_name']}");
                    } elseif (!isset($_SESSION['mssql_type']) && mssql_num_rows($res) == 1) {
                        $db_exists = true;
                        installLog("DB Exists and selected, will reuse {$_SESSION['setup_db_database_name']}");
                    } else {
                        installLog("No DB Selected, will create {$_SESSION['setup_db_database_name']}");
                    }
                    if ($silent == false && $db_exists && $_SESSION['setup_db_create_database'] && (!isset($_SESSION['setup_db_drop_tables']) || !$_SESSION['setup_db_drop_tables'])) {
                        $errStr = $mod_strings['ERR_DB_EXISTS_PROCEED'];
                        $errors['ERR_DB_EXISTS_PROCEED'] = $errStr;
                        installLog("ERROR:: {$errors['ERR_DB_EXISTS_PROCEED']}");
                    } else {
                        if (!$db_exists && !$_SESSION['setup_db_create_database']) {
                            $errors['ERR_DB_EXISTS_NOT'] = $mod_strings['ERR_DB_EXISTS_NOT'];
                            installLog("ERROR:: {$errors['ERR_DB_EXISTS_NOT']}");
                        }
                    }
                    // check for existing SugarCRM database user if create flag is set,
                    //user name has been given, and database has been selected (reusing db, not creating new one)
                    if ($_SESSION['setup_db_create_sugarsales_user'] && $_SESSION['setup_db_sugarsales_user'] != '') {
                        if (isset($_SESSION['mssql_type'])) {
                            $mssql_db_selected = (bool) sqlsrv_query($link, 'USE master');
                            $user = $_SESSION['setup_db_sugarsales_user'];
                            $query = "select count(*) from sys.sql_logins where name ='{$user}'";
                            $result = sqlsrv_query($link, $query);
                            if (!$result) {
                                $errors['ERR_DB_ADMIN'] = $mod_strings['ERR_DB_ADMIN'];
                                installLog("ERROR:: {$errors['ERR_DB_ADMIN']}");
                            } else {
                                $row = sqlsrv_fetch_array($result);
                                if ($row[0] == 1) {
开发者ID:rgauss,项目名称:sugarcrm_dev,代码行数:67,代码来源:checkDBSettings.php

示例14: fetchColumn

 /**
  * Returns a single column from the next row of a result set.
  *
  * @param int $col OPTIONAL Position of the column to fetch.
  * @return string
  * @throws \Zend\DB\Statement\Exception
  */
 public function fetchColumn($col = 0)
 {
     if (!$this->_stmt) {
         return false;
     }
     if (!sqlsrv_fetch($this->_stmt)) {
         if (null !== ($error = sqlsrv_errors())) {
             throw new Exception($error);
         }
         // If no error, there is simply no record
         return false;
     }
     $data = sqlsrv_get_field($this->_stmt, $col);
     //0-based
     if ($data === false) {
         throw new Exception(sqlsrv_errors());
     }
     return $data;
 }
开发者ID:alab1001101,项目名称:zf2,代码行数:26,代码来源:SQLSRV.php

示例15: get_recordset_sql

 /**
  * Get a number of records as a moodle_recordset using a SQL statement.
  *
  * Since this method is a little less readable, use of it should be restricted to
  * code where it's possible there might be large datasets being returned.  For known
  * small datasets use get_records_sql - it leads to simpler code.
  *
  * The return type is like:
  * @see function get_recordset.
  *
  * @param string $sql the SQL select query to execute.
  * @param array $params array of sql parameters
  * @param int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set).
  * @param int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set).
  * @return moodle_recordset instance
  * @throws dml_exception A DML specific exception is thrown for any errors.
  */
 public function get_recordset_sql($sql, array $params = null, $limitfrom = 0, $limitnum = 0)
 {
     list($limitfrom, $limitnum) = $this->normalise_limit_from_num($limitfrom, $limitnum);
     if ($limitfrom or $limitnum) {
         if ($limitnum >= 1) {
             // Only apply TOP clause if we have any limitnum (limitfrom offset is handled later)
             $fetch = $limitfrom + $limitnum;
             if (PHP_INT_MAX - $limitnum < $limitfrom) {
                 // Check PHP_INT_MAX overflow
                 $fetch = PHP_INT_MAX;
             }
             $sql = preg_replace('/^([\\s(])*SELECT([\\s]+(DISTINCT|ALL))?(?!\\s*TOP\\s*\\()/i', "\\1SELECT\\2 TOP {$fetch}", $sql);
         }
     }
     $result = $this->do_query($sql, $params, SQL_QUERY_SELECT, false, (bool) $limitfrom);
     if ($limitfrom) {
         // Skip $limitfrom records
         sqlsrv_fetch($result, SQLSRV_SCROLL_ABSOLUTE, $limitfrom - 1);
     }
     return $this->create_recordset($result);
 }
开发者ID:mongo0se,项目名称:moodle,代码行数:38,代码来源:sqlsrv_native_moodle_database.php


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