本文整理汇总了PHP中mssql_field_type函数的典型用法代码示例。如果您正苦于以下问题:PHP mssql_field_type函数的具体用法?PHP mssql_field_type怎么用?PHP mssql_field_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mssql_field_type函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _performGetBlobFieldNames
function _performGetBlobFieldNames($result)
{
$blobFields = array();
for ($i = mssql_num_fields($result) - 1; $i >= 0; $i--) {
$type = mssql_field_type($result, $i);
if (strpos($type, "BLOB") !== false) {
$blobFields[] = mssql_field_name($result, $i);
}
}
return $blobFields;
}
示例2: tableInfo
/**
* Returns information about a table or a result set.
*
* NOTE: only supports 'table' and 'flags' if <var>$result</var>
* is a table name.
*
* @param object|string $result MDB2_result object from a query or a
* string containing the name of a table
* @param int $mode a valid tableInfo mode
* @return array an associative array with the information requested
* or an error object if something is wrong
* @access public
* @internal
* @see MDB2_Driver_Common::tableInfo()
*/
function tableInfo($result, $mode = null)
{
$db =& $GLOBALS['_MDB2_databases'][$this->db_index];
if ($db->options['portability'] & MDB2_PORTABILITY_LOWERCASE) {
$case_func = 'strtolower';
} else {
$case_func = 'strval';
}
if (is_string($result)) {
/*
* Probably received a table name.
* Create a result resource identifier.
*/
if (MDB2::isError($connect = $db->connect())) {
return $connect;
}
$id = @mssql_query("SELECT * FROM {$result} WHERE 1=0", $db->connection);
$got_string = true;
} else {
/*
* Probably received a result object.
* Extract the result resource identifier.
*/
$id = $result->getResource();
if (empty($id)) {
return $db->raiseError();
}
$got_string = false;
}
if (!is_resource($id)) {
return $db->raiseError(MDB2_ERROR_NEED_MORE_DATA);
}
$count = @mssql_num_fields($id);
// made this IF due to performance (one if is faster than $count if's)
if (!$mode) {
for ($i = 0; $i < $count; $i++) {
$res[$i]['table'] = $got_string ? $case_func($result) : '';
$res[$i]['name'] = $case_func(@mssql_field_name($id, $i));
$res[$i]['type'] = @mssql_field_type($id, $i);
$res[$i]['len'] = @mssql_field_length($id, $i);
// We only support flags for tables
$res[$i]['flags'] = $got_string ? $this->_mssql_field_flags($result, $res[$i]['name']) : '';
}
} else {
// full
$res['num_fields'] = $count;
for ($i = 0; $i < $count; $i++) {
$res[$i]['table'] = $got_string ? $case_func($result) : '';
$res[$i]['name'] = $case_func(@mssql_field_name($id, $i));
$res[$i]['type'] = @mssql_field_type($id, $i);
$res[$i]['len'] = @mssql_field_length($id, $i);
// We only support flags for tables
$res[$i]['flags'] = $got_string ? $this->_mssql_field_flags($result, $res[$i]['name']) : '';
if ($mode & MDB2_TABLEINFO_ORDER) {
$res['order'][$res[$i]['name']] = $i;
}
if ($mode & MDB2_TABLEINFO_ORDERTABLE) {
$res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
}
}
}
// free the result only if we were called on a table
if ($got_string) {
@mssql_free_result($id);
}
return $res;
}
示例3: copy_table_data
//.........这里部分代码省略.........
$row = mysqli_fetch_assoc($result);
$where = " where dex_row_id > '" . $row["modified"] . "'";
mysqli_free_result($result);
break;
case "dex_row_ts":
$result = mysqli_query($con, "select coalesce(max(dex_row_ts), '01/10/1970') modified from {$db}_{$table};");
if ($result === false) {
die("Error can not get last modified date. " . mysqli_error($con));
}
$row = mysqli_fetch_assoc($result);
$where = " where dex_row_ts > '" . $row["modified"] . "'";
mysqli_free_result($result);
break;
case "active":
$where = " where active = 1";
mysqli_query($con, utf8_encode("truncate table {$db}_{$table};"));
break;
default:
mysqli_query($con, utf8_encode("truncate table {$db}_{$table};"));
break;
}
$sql = "select * from {$table} {$where}";
$rset = mssql_query($sql, $gp, 5000);
if (!$rset) {
die('MSSQL error: ' . mssql_get_last_message() . "\n\n {$sql} \n\n\n");
}
$cnt = mssql_num_fields($rset);
for ($inc = 0; $inc < $cnt; $inc++) {
if ($field_names == "") {
$field_names = mssql_field_name($rset, $inc);
} else {
$field_names .= ", " . mssql_field_name($rset, $inc);
}
$ykey = trim(strtolower(mssql_field_name($rset, $inc)));
if (isset($primary[$ykey])) {
$primary[$ykey] = $inc;
}
}
$zkey = "";
foreach ($primary as $key => $value) {
if ($zkey != "") {
$zkey .= ":{$key}";
} else {
$zkey .= "{$key}";
}
}
$p_sql = "";
$radix = 0;
$counter = 0;
$xdata = "";
echo "\n\n";
do {
while ($line = mssql_fetch_row($rset)) {
$field_values = "";
$vkey = "";
foreach ($primary as $key => $value) {
if ($vkey != "") {
$vkey .= ":" . $line[$value];
} else {
$vkey .= $line[$value];
}
}
echo "Importing ({$zkey} " . $vkey . ")\r";
for ($inc = 0; $inc < $cnt; $inc++) {
if (mssql_field_type($rset, $inc) == "datetime") {
$xdata = "'" . date(DATE_ATOM, strtotime($line[$inc])) . "'";
} else {
$xdata = "'" . sanitize($line[$inc]) . "'";
}
if ($field_values == "") {
$field_values = "{$xdata}";
} else {
$field_values .= ", {$xdata}";
}
}
if ($p_sql != "") {
$p_sql .= ", ({$field_values})";
} else {
$p_sql .= "({$field_values})";
}
if ($radix == 500) {
mysqli_query($con, utf8_encode("insert into {$db}_{$table} ({$field_names}) values {$p_sql};"));
$radix = 0;
$p_sql = "";
}
$radix++;
$counter++;
#echo "$p_sql\n";
#mysqli_query($con, utf8_encode($p_sql));
}
} while (mssql_fetch_batch($rset));
if ($p_sql != "") {
mysqli_query($con, utf8_encode("insert into {$db}_{$table} ({$field_names}) values {$p_sql};"));
$radix = 0;
$p_sql = "";
}
$p_sql = "insert into sync_log (db, tbl, modified, synced, rows) values ('{$db}', '{$table}', '{$mssql_modified}', now(), '{$counter}');";
mysqli_query($con, utf8_encode($p_sql));
echo "\n\nTable {$db}_{$table} completed.\n\n";
}
示例4: IsTimestamp
function IsTimestamp($vField)
{
return $this->res > 0 && mssql_field_type($this->res, $vField) == 'datetime';
}
示例5: tableInfo
/**
* Returns information about a table or a result set
*
* NOTE: doesn't support table name and flags if called from a db_result
*
* @param mixed $resource SQL Server result identifier or table name
* @param int $mode A valid tableInfo mode (DB_TABLEINFO_ORDERTABLE or
* DB_TABLEINFO_ORDER)
*
* @return array An array with all the information
*/
function tableInfo($result, $mode = null)
{
$count = 0;
$id = 0;
$res = array();
/*
* depending on $mode, metadata returns the following values:
*
* - mode is false (default):
* $result[]:
* [0]["table"] table name
* [0]["name"] field name
* [0]["type"] field type
* [0]["len"] field length
* [0]["flags"] field flags
*
* - mode is DB_TABLEINFO_ORDER
* $result[]:
* ["num_fields"] number of metadata records
* [0]["table"] table name
* [0]["name"] field name
* [0]["type"] field type
* [0]["len"] field length
* [0]["flags"] field flags
* ["order"][field name] index of field named "field name"
* The last one is used, if you have a field name, but no index.
* Test: if (isset($result['meta']['myfield'])) { ...
*
* - mode is DB_TABLEINFO_ORDERTABLE
* the same as above. but additionally
* ["ordertable"][table name][field name] index of field
* named "field name"
*
* this is, because if you have fields from different
* tables with the same field name * they override each
* other with DB_TABLEINFO_ORDER
*
* you can combine DB_TABLEINFO_ORDER and
* DB_TABLEINFO_ORDERTABLE with DB_TABLEINFO_ORDER |
* DB_TABLEINFO_ORDERTABLE * or with DB_TABLEINFO_FULL
*/
// if $result is a string, then we want information about a
// table without a resultset
if (is_string($result)) {
$id = mssql_query("SELECT * FROM {$result}", $this->connection);
if (empty($id)) {
return $this->mssqlRaiseError();
}
} else {
// else we want information about a resultset
$id = $result;
if (empty($id)) {
return $this->mssqlRaiseError();
}
}
$count = @mssql_num_fields($id);
// made this IF due to performance (one if is faster than $count if's)
if (empty($mode)) {
for ($i = 0; $i < $count; $i++) {
$res[$i]['table'] = is_string($result) ? $result : '';
$res[$i]['name'] = @mssql_field_name($id, $i);
$res[$i]['type'] = @mssql_field_type($id, $i);
$res[$i]['len'] = @mssql_field_length($id, $i);
$res[$i]['flags'] = '';
}
} else {
// full
$res['num_fields'] = $count;
for ($i = 0; $i < $count; $i++) {
$res[$i]['table'] = is_string($result) ? $result : '';
$res[$i]['name'] = @mssql_field_name($id, $i);
$res[$i]['type'] = @mssql_field_type($id, $i);
$res[$i]['len'] = @mssql_field_length($id, $i);
$res[$i]['flags'] = '';
if ($mode & DB_TABLEINFO_ORDER) {
$res['order'][$res[$i]['name']] = $i;
}
if ($mode & DB_TABLEINFO_ORDERTABLE) {
$res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
}
}
}
// free the result only if we were called on a table
if (is_string($result)) {
@mssql_free_result($id);
}
return $res;
}
示例6: write_data_mssql
function write_data_mssql($table_name)
{
global $db;
$ary_type = $ary_name = array();
$ident_set = false;
$sql_data = '';
// Grab all of the data from current table.
$sql = "SELECT *\n\t\t\tFROM {$table_name}";
$result = $db->sql_query($sql);
$retrieved_data = mssql_num_rows($result);
$i_num_fields = mssql_num_fields($result);
for ($i = 0; $i < $i_num_fields; $i++) {
$ary_type[$i] = mssql_field_type($result, $i);
$ary_name[$i] = mssql_field_name($result, $i);
}
if ($retrieved_data) {
$sql = "SELECT 1 as has_identity\n\t\t\t\tFROM INFORMATION_SCHEMA.COLUMNS\n\t\t\t\tWHERE COLUMNPROPERTY(object_id('{$table_name}'), COLUMN_NAME, 'IsIdentity') = 1";
$result2 = $db->sql_query($sql);
$row2 = $db->sql_fetchrow($result2);
if (!empty($row2['has_identity'])) {
$sql_data .= "\nSET IDENTITY_INSERT {$table_name} ON\nGO\n";
$ident_set = true;
}
$db->sql_freeresult($result2);
}
while ($row = $db->sql_fetchrow($result)) {
$schema_vals = $schema_fields = array();
// Build the SQL statement to recreate the data.
for ($i = 0; $i < $i_num_fields; $i++) {
$str_val = $row[$ary_name[$i]];
if (preg_match('#char|text|bool|varbinary#i', $ary_type[$i])) {
$str_quote = '';
$str_empty = "''";
$str_val = sanitize_data_mssql(str_replace("'", "''", $str_val));
} else {
if (preg_match('#date|timestamp#i', $ary_type[$i])) {
if (empty($str_val)) {
$str_quote = '';
} else {
$str_quote = "'";
}
} else {
$str_quote = '';
$str_empty = 'NULL';
}
}
if (empty($str_val) && $str_val !== '0' && !(is_int($str_val) || is_float($str_val))) {
$str_val = $str_empty;
}
$schema_vals[$i] = $str_quote . $str_val . $str_quote;
$schema_fields[$i] = $ary_name[$i];
}
// Take the ordered fields and their associated data and build it
// into a valid sql statement to recreate that field in the data.
$sql_data .= "INSERT INTO {$table_name} (" . implode(', ', $schema_fields) . ') VALUES (' . implode(', ', $schema_vals) . ");\nGO\n";
$this->flush($sql_data);
$sql_data = '';
}
$db->sql_freeresult($result);
if ($retrieved_data && $ident_set) {
$sql_data .= "\nSET IDENTITY_INSERT {$table_name} OFF\nGO\n";
}
$this->flush($sql_data);
}
示例7: fieldType
/**
* mysql_field_type() wrapper
*/
function fieldType($res, $index)
{
if ($res instanceof ResultWrapper) {
$res = $res->result;
}
return mssql_field_type($res, $index);
}
示例8: db_field_type
function db_field_type($result, $i)
{
global $_josh;
db_open();
if ($_josh["db"]["language"] == "mysql") {
return mysql_field_type($result, $i);
} elseif ($_josh["db"]["language"] == "mssql") {
return mssql_field_type($result, $i);
}
}
示例9: query
function query($query)
{
// For reg expressions
$query = trim($query);
// Flush cached values..
$this->flush();
// Log how the function was called
$this->func_call = "\$db->query(\"{$query}\")";
// Keep track of the last query for debug..
$this->last_query = $query;
// Perform the query via std mssql_query function..
$this->result = @mssql_query($query, $this->dbh);
$this->num_queries++;
// Unfortunately, PHP fuctions for MS SQL currently don't offer a decent way
// to retrieve errors from MS SQL
// Make sure not to run a query between the actual query and this one !
$get_errorcode = "SELECT @@ERROR as errorcode";
$error_res = @mssql_query($get_errorcode, $this->dbh);
$errorcode = @mssql_result($error_res, 0, "errorcode");
// If there was an insert, delete or update see how many rows were affected
// (Also, If there there was an insert take note of the last OID
$query_type = array("insert", "delete", "update", "replace");
// loop through the above array
foreach ($query_type as $word) {
// This is true if the query starts with insert, delete or update
if (preg_match("/^{$word}\\s+/i", $query)) {
$this->rows_affected = @mssql_rows_affected($this->dbh);
// This gets the insert ID
if ($word == "insert" || $word == "replace") {
$get_last_ident = "SELECT @@IDENTITY as id";
$last_res = @mssql_query($get_last_ident, $this->dbh);
$this->insert_id = @mssql_result($last_res, 0, "id");
// If insert id then return it - true evaluation
return $this->insert_id;
}
// Set to false if there was no insert id
$this->result = false;
}
}
if ($errorcode != 0) {
// there is an error
$this->print_error();
} else {
// =======================================================
// Take note of column info
$i = 0;
while ($i < @mssql_num_fields($this->result)) {
$this->col_info[$i]->name = @mssql_field_name($this->result, $i);
$this->col_info[$i]->type = @mssql_field_type($this->result, $i);
$this->col_info[$i]->size = @mssql_field_length($this->result, $i);
$i++;
}
// =======================================================
// Store Query Results
$i = 0;
while ($row = @mssql_fetch_object($this->result)) {
// Store relults as an objects within main array
$this->last_result[$i] = $row;
$i++;
}
// Log number of rows the query returned
$this->num_rows = $i;
//}
@mssql_free_result($this->result);
// If this was a select..
if (preg_match("/^(select|show|desc)\\s+/i", $query)) {
// If debug ALL queries
$this->debug_all ? $this->debug() : null;
// If there were results then return true for $db->query
if ($i) {
return true;
} else {
return false;
}
} else {
// If debug ALL queries
$this->debug_all ? $this->debug() : null;
// Update insert etc. was good..
return true;
}
}
}
示例10: db_get_query_rows
/**
* Get the rows returned from a SELECT query.
*
* @param resource The query result pointer
* @param ?integer Whether to start reading from (NULL: irrelevant for this forum driver)
* @return array A list of row maps
*/
function db_get_query_rows($results, $start = NULL)
{
$out = array();
if (!function_exists('sqlsrv_num_fields')) {
$num_fields = mssql_num_fields($results);
$types = array();
$names = array();
for ($x = 1; $x <= $num_fields; $x++) {
$types[$x - 1] = mssql_field_type($results, $x - 1);
$names[$x - 1] = strtolower(mssql_field_name($results, $x - 1));
}
$i = 0;
while (($row = mssql_fetch_row($results)) !== false) {
$j = 0;
$newrow = array();
foreach ($row as $v) {
$type = strtoupper($types[$j]);
$name = $names[$j];
if ($type == 'SMALLINT' || $type == 'INT' || $type == 'INTEGER' || $type == 'UINTEGER' || $type == 'BYTE' || $type == 'COUNTER') {
if (!is_null($v)) {
$newrow[$name] = intval($v);
} else {
$newrow[$name] = NULL;
}
} else {
if ($v == ' ') {
$v = '';
}
$newrow[$name] = $v;
}
$j++;
}
$out[] = $newrow;
$i++;
}
} else {
if (function_exists('sqlsrv_fetch_array')) {
while (($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC)) !== NULL) {
$out[] = $row;
}
} else {
while (($row = mssql_fetch_row($results)) !== false) {
$out[] = $row;
}
}
}
if (function_exists('sqlsrv_free_stmt')) {
sqlsrv_free_stmt($results);
} else {
mssql_free_result($results);
}
return $out;
}
示例11: __construct
public function __construct($result_id, $x, $value)
{
try
{
$this->name = @mssql_field_name($result_id, $x);
//If can't read field name
if (!$this->name) throw new TException(TCustomMessage::GetMessage(5008), 5008);
$this->size = @mssql_field_length($result_id, $x);
//If can't read field size
if (!$this->size) throw new TException(TCustomMessage::GetMessage(5008), 5008);
$this->type = @mssql_field_type($result_id, $x);
//If can't read field type
if (!$this->type) throw new TException(TCustomMessage::GetMessage(5008), 5008);
$this->value = $value;
}
catch (TException $e)
{
//...
}
}
示例12: FieldType
function FieldType($result, $offset)
{
switch ($this->dbType) {
case "mssql":
$r = mssql_field_type($result, $offset);
break;
case "mysql":
$r = mysql_field_type($result, $offset);
break;
case "pg":
$r = pg_fieldtype($result, $offset);
break;
default:
$r = False;
break;
}
return $r;
}
示例13: tableInfo
/**
* Returns information about a table or a result set
*
* NOTE: only supports 'table' and 'flags' if <var>$result</var>
* is a table name.
*
* @param object|string $result MDB2_result object from a query or a
* string containing the name of a table.
* While this also accepts a query result
* resource identifier, this behavior is
* deprecated.
* @param int $mode a valid tableInfo mode
*
* @return array an associative array with the information requested.
* A MDB2_Error object on failure.
*
* @see MDB2_Driver_Common::tableInfo()
*/
function tableInfo($result, $mode = null)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
if (is_string($result)) {
/*
* Probably received a table name.
* Create a result resource identifier.
*/
$query = 'SELECT TOP 0 * FROM ' . $db->quoteIdentifier($result);
$id =& $db->_doQuery($query, false);
if (PEAR::isError($id)) {
return $id;
}
$got_string = true;
} elseif (MDB2::isResultCommon($result)) {
/*
* Probably received a result object.
* Extract the result resource identifier.
*/
$id = $result->getResource();
$got_string = false;
} else {
/*
* Probably received a result resource identifier.
* Copy it.
* Deprecated. Here for compatibility only.
*/
$id = $result;
$got_string = false;
}
if (!is_resource($id)) {
return $db->raiseError(MDB2_ERROR_NEED_MORE_DATA);
}
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
if ($db->options['field_case'] == CASE_LOWER) {
$case_func = 'strtolower';
} else {
$case_func = 'strtoupper';
}
} else {
$case_func = 'strval';
}
$count = @mssql_num_fields($id);
$res = array();
if ($mode) {
$res['num_fields'] = $count;
}
$db->loadModule('Datatype', null, true);
for ($i = 0; $i < $count; $i++) {
$res[$i] = array('table' => $got_string ? $case_func($result) : '', 'name' => $case_func(@mssql_field_name($id, $i)), 'type' => @mssql_field_type($id, $i), 'length' => @mssql_field_length($id, $i), 'flags' => $got_string ? $this->_mssql_field_flags($result, @mssql_field_name($id, $i)) : '');
$mdb2type_info = $db->datatype->mapNativeDatatype($res[$i]);
if (PEAR::isError($mdb2type_info)) {
return $mdb2type_info;
}
$res[$i]['mdb2type'] = $mdb2type_info[0][0];
if ($mode & MDB2_TABLEINFO_ORDER) {
$res['order'][$res[$i]['name']] = $i;
}
if ($mode & MDB2_TABLEINFO_ORDERTABLE) {
$res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
}
}
// free the result only if we were called on a table
if ($got_string) {
@mssql_free_result($id);
}
return $res;
}
示例14: run_inquirydetail
public function run_inquirydetail($criteria)
{
//select the database
mssql_select_db($this->dbname, $this->dbcon);
//SQL Select statement
$xml = new XMLHandler(XML_DIR . "inquiry.xml");
$sql_from_xml = $xml->getNode("inquiry");
$sqlselect = str_replace("FILTER_BY_PROGRAM", " WHERE SPK.NO_SPK = '" . $criteria . "' ", $sql_from_xml);
//Run the SQL query
$result = mssql_query($sqlselect);
$numfields = mssql_num_fields($result);
$string_result = "";
while ($row = mssql_fetch_row($result)) {
for ($i = 0; $i < $numfields; $i++) {
$fieldType = mssql_field_type($result, $i);
if ($fieldType == "datetime") {
if ($row[$i] != null) {
$dateVal = strtotime($row[$i]);
$string_result .= "<tr><th scope=\"row\">" . mssql_field_name($result, $i) . "</th><td>:</td><td>" . date('d-m-Y', $dateVal) . "</td></tr>";
} else {
$string_result .= "<tr><th scope=\"row\">" . mssql_field_name($result, $i) . "</th><td>:</td><td>-</td></tr>";
}
} else {
if ($i == 0) {
$string_result .= "<tr><th scope=\"row\">" . mssql_field_name($result, $i) . "</th><td>:</td><td>" . $row[$i] . " <a href='loadspk_" . $criteria . "'><button type=\"button\" class=\"btn btn-info btn-xs\">edit</button></a></td></tr>";
} else {
$string_result .= "<tr><th scope=\"row\">" . mssql_field_name($result, $i) . "</th><td>:</td><td>" . $row[$i] . "</td></tr>";
}
}
}
}
$string_result .= "<tr><th scope=\"row\" colspan=3><a href='loadspk_" . $criteria . "'><button type=\"button\" class=\"btn btn-info\">edit mode</button></a></th></tr>";
return $string_result;
}
示例15: vty_field_type
function vty_field_type($list,$i){
switch($this->vtAdi){
case 'mysql': return mysql_field_type($list,$i); break;
case 'odbc': return odbc_field_type($list,$i); break;
case 'mssql': return mssql_field_type($list,$i); break;
case 'postgresql': pg_fieldtype($list,$i); break;
}
}