本文整理汇总了PHP中mssql_field_length函数的典型用法代码示例。如果您正苦于以下问题:PHP mssql_field_length函数的具体用法?PHP mssql_field_length怎么用?PHP mssql_field_length使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mssql_field_length函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例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 DB_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 DB_Error object on failure.
*
* @see DB_common::tableInfo()
*/
function tableInfo($result, $mode = null)
{
if (is_string($result)) {
/*
* Probably received a table name.
* Create a result resource identifier.
*/
if (!@mssql_select_db($this->_db, $this->connection)) {
return $this->mssqlRaiseError(DB_ERROR_NODBSELECTED);
}
$id = @mssql_query("SELECT * FROM {$result} WHERE 1=0", $this->connection);
$got_string = true;
} elseif (isset($result->result)) {
/*
* Probably received a result object.
* Extract the result resource identifier.
*/
$id = $result->result;
$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 $this->mssqlRaiseError(DB_ERROR_NEED_MORE_DATA);
}
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
$case_func = 'strtolower';
} else {
$case_func = 'strval';
}
$count = @mssql_num_fields($id);
$res = array();
if ($mode) {
$res['num_fields'] = $count;
}
for ($i = 0; $i < $count; $i++) {
if ($got_string) {
$flags = $this->_mssql_field_flags($result, @mssql_field_name($id, $i));
if (DB::isError($flags)) {
return $flags;
}
} else {
$flags = '';
}
$res[$i] = array('table' => $got_string ? $case_func($result) : '', 'name' => $case_func(@mssql_field_name($id, $i)), 'type' => @mssql_field_type($id, $i), 'len' => @mssql_field_length($id, $i), 'flags' => $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 ($got_string) {
@mssql_free_result($id);
}
return $res;
}
示例3: 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;
}
示例4: 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)
{
if (is_string($result)) {
return parent::tableInfo($result, $mode);
}
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$resource = MDB2::isResultCommon($result) ? $result->getResource() : $result;
if (!is_resource($resource)) {
return $db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 'Could not generate result resource', __FUNCTION__);
}
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($resource);
$res = array();
if ($mode) {
$res['num_fields'] = $count;
}
$db->loadModule('Datatype', null, true);
for ($i = 0; $i < $count; $i++) {
$res[$i] = array('table' => '', 'name' => $case_func(@mssql_field_name($resource, $i)), 'type' => @mssql_field_type($resource, $i), 'length' => @mssql_field_length($resource, $i), 'flags' => '');
$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;
}
}
return $res;
}
示例5: 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;
// Perform the query via std mssql_query function..
if (substr($query, 0, 7) == 'SELECT ') {
$this->result_check = @mssql_query($query, $this->dbh);
} elseif (substr($query, 0, 7) == 'INSERT ') {
} elseif (substr($query, 0, 7) == 'UPDATE ') {
$this->result_check = @mssql_query($query, $this->dbh);
} elseif (substr($query, 0, 7) == 'DELETE ') {
} elseif (substr($query, 0, 7) == 'CREATE ') {
} elseif (substr($query, 0, 5) == 'SHOW ') {
}
// 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");
// ERROR LIST
// 402 : The data types text and varchar are incompatible in the equal to operator.
// 306 : The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.
if ($errorcode == '402') {
$query_two = str_replace(' = ', ' LIKE ', $query);
/* NEED MORE IMPROVEMENT HERE */
} else {
$query_two = $query;
}
dbug($query, $errorcode, 'green');
$this->result = @mssql_query($query_two, $this->dbh);
$this->num_queries++;
// 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_arr = @mssql_fetch_array($this->result)) {
$row = array_to_object($row_arr);
$this->last_result[$i] = $row;
// Store relults as an objects within main array
$i++;
}
if ($i == 0) {
$this->last_result = array();
}
//pre($this->last_result);
// 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;
}
}
}
示例6: query
function query($query)
{
//去掉查询语句的前后空格
$query = trim($query);
//初始化返回值为0
$return_val = 0;
//清空缓存..
$this->flush();
//记录此函数如何被调用,用于调试...
$this->func_call = "\$db->query(\"{$query}\")";
//跟踪最后查询语句,用于调试..
$this->last_query = $query;
//通过mysql_query函数执行查询操作..
$this->result = @mssql_query($query, $this->dbh);
$this->num_queries++;
//php现在还不支持从sqlserver服务器获取错误信息
#这里以后要进行讨论,改进。
$get_errorcode = "SELECT @@ERROR as errorcode";
$error_res = @mssql_query($get_errorcode, $this->dbh);
$errorcode = @mssql_result($error_res, 0, "errorcode");
//执行insert, delete, update, replace操作
if (preg_match("/^(insert|delete|update|replace)\\s+/i", $query)) {
$this->rows_affected = @mssql_rows_affected($this->dbh);
$return_val = $this->rows_affected;
//获取操作所影响的记录行数
if (preg_match("/^(insert|replace)\\s+/i", $query)) {
$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");
//$return_val = $this->insert_id;
}
}
if ($errorcode != 0) {
//如果有错误
$this->print_error();
} else {
//获取字段信息
$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++;
}
//获取查询结果
$i = 0;
while ($row = @mssql_fetch_object($this->result)) {
//取得包含数组的结果对象
$this->last_result[$i] = $row;
$i++;
}
//获取查询结果行数
$this->num_rows = $i;
@mssql_free_result($this->result);
//返回选中的结果行数
$return_val = $this->num_rows;
}
//是否显示所有的查询信息
$this->debug_all ? $this->debug() : null;
return $return_val;
}
示例7: 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;
}
}
}
示例8: __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)
{
//...
}
}
示例9: FieldLength
function FieldLength($result, $offset)
{
switch ($this->dbType) {
case "mssql":
$r = mssql_field_length($result, $offset);
break;
case "mysql":
$r = mysql_field_len($result, $offset);
break;
case "pg":
$r = pg_fieldsize($result, $offset);
break;
default:
$r = False;
break;
}
return $r;
}
示例10: 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;
}
示例11: vty_field_len
function vty_field_len($list,$i){
switch($this->vtAdi){
case 'mysql': return mysql_field_len($list,$i); break;
case 'odbc': return odbc_field_len($list,$i); break;
case 'mssql': return mssql_field_length($list,$i); break;
case 'postgresql': pg_field_len($list,$i); break;
}
}