導航:首頁 > 編程語言 > php獲取hostname

php獲取hostname

發布時間:2022-08-22 09:47:37

『壹』 怎樣利用php獲取資料庫中指定的記錄

1.增刪改只在SQL語句上不同。都使用的是PHP的query函數。如果是MSSQL資料庫那麼query函數就是mssql_query($sql);如果是MYSQL那就是mysql_query($sql);2.操作原理就是(1)首先建立與資料庫伺服器的連接(2)選擇要操作的資料庫(3)利用資料庫的會話句柄來對所選擇的資料庫進行SQL語句查詢給你舉例。查詢XXX表的所有數據-----建立資料庫連接部分---<?php$hostname="資料庫所在的計算機名或者IP地址";$dbuser="sa";//資料庫的用戶名$dbpass=""; //資料庫密碼$dbname="test";//要訪問的資料庫名 $link=@mssql_connect($hostname,$dbuser,$dbpass) or die ("連接資料庫出錯"); //$link就是以後查詢用到的會話句柄。@mssql_select_db($dbname);//進行增刪改的查詢$sql="select * from XXX";@mssql_query($sql,$link);?>到此,SQL語句就執行完了。

『貳』 php如何獲取本機計算機名

源代碼如下:
@echo off
for /f "tokens=2 delims=:" %%i in ('ipconfig /all ^| findstr /i /c:"ip address"') do set ip=%%i
set Nip=%ip:~1,15%
@echo off
for /f "tokens=2 delims=:" %%i in ('ipconfig /all ^| findstr /i /c:"Host Name"') do set Hostname=%%i
set Name=%Hostname:~1,15%
@echo off
title 查看計算機信息
color 0A
%net config workstation%
@echo

『叄』 使用PHP寫一個類和一個控制器

<?php
/**
*以下代碼用於資料庫操作類的封裝
*
* @author rex<[email protected]>
* @version 1.0
* @since 2015
*/

class Mysql{

//資料庫連接返回值
private $conn;

/**
* [構造函數,返回值給$conn]
* @param [string] $hostname [主機名]
* @param [string] $username[用戶名]
* @param [string] $password[密碼]
* @param [string] $dbname[資料庫名]
* @param [string] $charset[字元集]
* @return [null]

*/

function __construct($hostname,$username,$password,$dbname,$charset='utf8'){
$conn = @mysql_connect($hostname,$username,$password);
if(!$conn){
echo '連接失敗,請聯系管理員';
exit;
}
$this->conn = $conn;
$res = mysql_select_db($dbname);
if(!$res){
echo '連接失敗,請聯系管理員';
exit;
}
mysql_set_charset($charset);
}
function __destruct(){
mysql_close();
}
/**
* [getAll 獲取所有信息]
* @param [string] $sql [sql語句]
* @return [array] [返回二維數組]
*/
function getAll($sql){
$result = mysql_query($sql,$this->conn);
$data = array();
if($result && mysql_num_rows($result)>0){
while($row = mysql_fetch_assoc($result)){
$data[] = $row;
}
}
return $data;
}
/**
* [getOne 獲取單條數據]
* @param [string] $sql [sql語句]
* @return [array] [返回一維數組]
*/
function getOne($sql){
$result = mysql_query($sql,$this->conn);
$data = array();
if($result && mysql_num_rows($result)>0){
$data = mysql_fetch_assoc($result);
}
return $data;
}

/**
* [getOne 獲取單條數據]
* @param [string] $table [表名]
* @param [string] $data [由欄位名當鍵,屬性當鍵值的一維數組]
* @return [type] [返回false或者插入數據的id]
*/

function insert($table,$data){
$str = '';
$str .="INSERT INTO `$table` ";
$str .="(`".implode("`,`",array_keys($data))."`) ";
$str .=" VALUES ";
$str .= "('".implode("','",$data)."')";
$res = mysql_query($str,$this->conn);
if($res && mysql_affected_rows()>0){
return mysql_insert_id();
}else{
return false;
}
}
/**
* [update 更新資料庫]
* @param [string] $table [表名]
* @param [array] $data [更新的數據,由欄位名當鍵,屬性當鍵值的一維數組]
* @param [string] $where [條件,『欄位名』=『欄位屬性』]
* @return [type] [更新成功返回影響的行數,更新失敗返回false]
*/
function update($table,$data,$where){
$sql = 'UPDATE '.$table.' SET ';
foreach($data as $key => $value){
$sql .= "`{$key}`='{$value}',";
}
$sql = rtrim($sql,',');
$sql .= " WHERE $where";
$res = mysql_query($sql,$this->conn);
if($res && mysql_affected_rows()){
return mysql_affected_rows();
}else{
return false;
}
}

/**
* [delete 刪除數據]
* @param [string] $table [表名]
* @param [string] $where [條件,『欄位名』=『欄位屬性』]
* @return [type] [成功返回影響的行數,失敗返回false]
*/
function del($table,$where){
$sql = "DELETE FROM `{$table}` WHERE {$where}";
$res = mysql_query($sql,$this->conn);
if($res && mysql_affected_rows()){
return mysql_affected_rows();
}else{
return false;
}
}
}

實例化類:

<?php

//包含資料庫操作類文件
include 'mysql.class.php';

//設置傳入參數
$hostname='localhost';
$username='root';
$password='123456';
$dbname='aisi';
$charset = 'utf8';

//實例化對象

$db = new Mysql($hostname,$username,$password,$dbname);

//獲取一條數據

$sql = "SELECT count(as_article_id) as count FROM as_article where as_article_type_id=1";
$count = $db->getOne($sql);

//獲取多條數據

$sql = "SELECT * FROM as_article where as_article_type_id=1 order by as_article_addtime desc limit $start,$limit";
$service = $db->getAll($sql);

//插入數據

$arr = array(
'as_article_title'=>'資料庫操作類',
'as_article_author'=>'rex',
);
$res = $db->insert('as_article',$arr);

//更新數據

$arr = array(
'as_article_title'=>'實例化對象',
'as_article_author'=>'Lee',
);
$where = "as_article_id=1";
$res = $db->update('as_article',$arr,$where);

//刪除數據

$where = "as_article_id=1";
$res = $db->del('as_article',$where);

?>

getOne方法傳入$sql的sql語句用於查詢單條數據並返回一維數組;getAll方法同樣傳入sql語句,用於查詢多條數據,並返回二維數組;insert方法傳入表名和關聯數組,返回boolen型或者插入數據對應索引;update方法傳入表名、關聯數組和條件,返回boolen或者影響的行數;del方法傳入表名和條件,返回boolen型。

『肆』 如何用php 獲取域名對應的IP

gethostbyname (PHP 3, PHP 4, PHP 5)

gethostbyname -- 獲取指定機器名的IP地址

函數格式說明:
string gethostbyname ( string hostname )

返回 hostname 的IP地址

例 1. A simple gethostbyname() example

<?php
$ip = gethostbyname('www.example.com');

echo $ip;
?>

『伍』 PHP或JS或html獲取當前url

<!doctypehtml>
<html>
<head>
<metacharset="utf-8">
<title>test</title>
<script>
/.com$/i.test(location.hostname)?alert('安全'):alert('來路不正確');
</script>
</head>
<body>
<pid="htmltest">test</p>
</body>
</html>

『陸』 gethostbyaddr()的PHP函數

(PHP 3, PHP 4 )
gethostbyaddr -- Get the Internet host name corresponding to a given IP address string gethostbyaddr ( string ip_address)
Returns the host name of the Internet host specified byip_addressor a string containing the unmodifiedip_addresson failure. 例子 1. A simplegethostbyaddr()example
<?php
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
echo $hostname;
?> See alsogethostbyname().
由於PHP是用C寫的腳本語言,借鑒了很多C語言的特性和函數,因此有很多相似之處。但是C語言更底層,更高效。

『柒』 php怎樣獲取本機的ipv4地址

// 通過$_SERVER變數
echo $_SERVER['SERVER_ADDR'];
// 通過執行操作符,等同於在命令行下執行該命令,要獲取ip的根據返回內容截取
$output = `ipconfig`;
echo '<pre>'.$output.'</pre>';
// 通過system函數,功能與執行操作符一樣
echo '<pre>';
$last_line = system('ipconfig', $retval);

echo '
</pre>
<hr />Last line of the output: ' . $last_line . '
<hr />Return value: ' . $retval;

『捌』 PHP中的超級全局變數$_ENV["HOSTNAME"]怎麼輸出不了

<?php
if(isset($_ENV["HOSTNAME"])){
echo$_ENV["HOSTNAME"];
}else{
echo'沒有值';
}
?>

望採納 Thx

閱讀全文

與php獲取hostname相關的資料

熱點內容
pdf手寫筆 瀏覽:173
別永遠傷在童年pdf 瀏覽:984
愛上北斗星男友在哪個app上看 瀏覽:414
主力散戶派發源碼 瀏覽:665
linux如何修復伺服器時間 瀏覽:55
榮縣優途網約車app叫什麼 瀏覽:473
百姓網app截圖是什麼意思 瀏覽:222
php如何嵌入html 瀏覽:811
解壓專家怎麼傳輸 瀏覽:743
如何共享伺服器的網路連接 瀏覽:132
程序員簡易表白代碼 瀏覽:167
什麼是無線加密狗 瀏覽:63
國家反詐中心app為什麼會彈出 瀏覽:68
cad壓縮圖列印 瀏覽:102
網頁打開速度與伺服器有什麼關系 瀏覽:863
android開發技術文檔 瀏覽:65
32單片機寫程序 瀏覽:52
三星雙清無命令 瀏覽:839
漢壽小程序源碼 瀏覽:345
易助erp雲伺服器 瀏覽:533