您的位置:首页 > 编程语言 > ASP

jsp,.net,php,asp语法不同之处粗略搜集未做整理

2014-08-08 12:01 288 查看
语言 Jsp .Net Php Asp
页面 jsp 文件 aspx文件 php文件 asp文件
代码结构 Actionform.java +Action.Java文件 Cs文件 页面php脚本 页面vb脚本
Html中代码 <% ..%> <%.. %> 也可以开启short_trag 或asp_trag标记 <%.. %>
注释 // /*..*/ // /*..*/ // /*..*/ #
输出 <%=变量/函数%>Out.println(变量/函数) <%=变量/函数%>this.response.write(变量/函数) Echo a,b Print a <%=变量/函数%>response.write(变量/函数)
变量 定义 利用 int a=0; 定义 利用 int a=0; 无需定义$a=1 无需定义 a=1; Dim a as int
字符串 Php较其它三种语言丰富 String a=”abc”;唯一表现形式 String a=”abc”;唯一表现形式 $a=’abc’; $a=”abc” $b=”$a sss” 转义模式输出格式为 abc sss 注意中间空格 $a=”/$a sss” 输出格式 $a sss Dim a as string=”abc”;唯一表现形式
数组 String[] a=new String[3]; a[0]="a"; System.out.print(a[0]); string[] a=new string[3]; a[0]= “c” $a[0]=”a”; $a=array( “one”=>”a”); a(1)=”a” Dim a(3) as string
数组与带分隔符字符串转换(Split函数) String str=""; String a="sadf,333,4344"; String arr[]=new String[3]; arr=a.split(","); for(int i=0;i<arr.length;i++) td="" <="" }="" str+="arr[i]+",";" {="">string[] arr = new string[3]; string str = sadf,344,444"; arr = str.Split(','); string b = ""; for (int i = 0; i < arr.Length; i++) { b += arr[i] + ","; } $a="as333df,3333,4344,"; //用split函数直接转换数组 $myarray=split(",",$a); //用implode函数有可以将数组转换回 $mystring=implode( ",",$myarray);
强制转换 int[] a=new int[3]; int b=0; a[0]=1; b=a[0]+1; (float)b; int a=1; float c; c=(float)a; Settype(a,int) 测试没有成功
字符转换成数字 int fv=0; try { fv=Integer.parseInt((String)val); } catch (Exception e) { fv=0; } return fv; } Try { return System.Convert.ToInt32(querystr); } Catch() { Return 0;} function strtoint($str,$def) { if (is_integer($str)) { return $str; } return $def; }
获得子字符串 String str=""; str=(String)val; if(str!=null) { if (str.length()>= len) { return str.substring(0,len)+"..."; } else { return str; } } return ""; if (str.Length>7) { return str.Substring(1,7) ; } else { return str; } function substing($str,$len) { return substr($str,0,$len); }
函数及私有变量 static public String a() { String c; c="a"; return c; } public static void main(String[] args) { System.out.print(a()); } public string a=”cc”; public string a() { String a=”cc”; Return a; } $a=”cc”; Function a() { global $a; $a=”cccc”; Return $a } dim a a="awa" function cc() a="ccc" cc=a end function response.Write(a) response.Write(cc())
大小写转换函数 string.toLowerCase() string.toUpperCase() string.ToLower(); string. ToUpper(); strtolower(): strtoupper(): usfilst():将字符串首字符转换成大写 ucwords():将字符串每个单词的首字符转换成大写
常量 final String a="c"; const string a = "cc"; this.Text = a; define("c","a"); echo c; const a="aa"
运算符 相同 相同 字符串连接 $a.$b 字符串连接a&b 不等于<> 赋值= 余数%
控制语句 if(表达式) { } if(表达式) { } if(表达式) { }else {} if表达式then else end if
循环语句一 While int i=0; while(i<9) { ; i++; } int i = 0; while(i<10) { i++; } $i=0; while($i<10) { echo $i; $i++; } int i=0; while(i<10) I=i+1 wend;
循环语句二 int i=0; do{ i++; }while(i<10) int i = 0; do{ i++; } while (i < 10) i=0 do while (i<10) response.Write("") i=i+1 loop
循环语句三 for(int i=0;i<10 ;i++) { 代码体 } for (int i = 0; i < 10; i++){ 代码体 } for($i=0;$i<10;$i++) { 代码体} for i=0 to 9 代码体 next
多重选择语句 int a=1; switch (a){ case 0: 代码体; break; case 1: 代码体; break; default: 代码体; break; } int a = 1; switch (a) { case 0: 代码体; break; case 1: 代码体; break; default : 代码体; break; } $a=1; switch($a) { case 0: 代码体; break; case 1: 代码体; break; default: 代码体; break; } a=1 select case a case 1: 代码体 case 2: 代码体 case else 代码体 end select
函数 public static int a() { 代码段 return 1; } public int a() { 代码段 return 1; } function a($c) { 代码段 Return 1 } Function a(c) 代码段 a=c endfunction
类及属性 public class employee { private String _name=""; public employee(String name) { _name=name; } public String get_name() { return _name; } public void set_name(String string) { _name = string; } } public class employee { Private string _name = ""; public string name { get { return _name; } set { _name = value; } } public employee(string name) { _name = name; } } name=$a; $this->age=$b; } function show() { echo "$this->name $this->age"; } } $ab=new employee; $ab->add_employee("aaac",100); $ab->show(); ?> class employee private manname private manage sub setmanname(a ) manname=a end sub function getmanname() getmanname=manname end function end class dim man set man=New employee man.setmanname("cccccc") response.Write(man.getmanname())
模块包含 用户控件 Include require Incldue
包含模块路径 ./ 当前目录 ../父目录 ./当前路径 ../父目录 Request.ApplicationPath+"/images/a.gif" ./当前路径 ../父目录
TXT文件读写 FileWriter fw=new FileWriter(“c:\\hello.txt”); String s=”hello”; fw.writer(s,0,s.length); fs.flush; String str=””; FileReader fr=new FileReader(“c:\\hello.txt”); char[] chr=new char[1024]; while((chr=fr.read()!=-1) { Str+=chr } System.IO.StreamWriter f=new System.IO.StreamWriter(“c:\\1.txt”); f.write(“sss”); f.flush(); f.close(); System.IO.StreamReader r=new System.IO.StreamReader(“c:\\1.txt”); r.readln(); function getcounter($filename) { if (file_exists($filename)) { $fp=fopen($filename); $count=fgets($fp,200); fclose($fp); } $fp=fopen($filename); fputs($fp,$count); fclose($fp); return $count; } set fobj=server.CreateObject("scripting.FileSystemObject") set txt=fobj.OpenTextFile(server.MapPath( "test.txt "),2,true) txt.WriteLine( "这是一个测试 ") txt.WriteLine( "这是一个测试 ") txt.close set myfileobject=server.createobject("scripting.FileSystemObject") set mytextfile=myfileobject.opentextfile(
server.MapPath( "test.txt ")) while not mytextfile.atendofstream response.write(mytextfile.readline) wend mytextfile.close
获得表单数据 Reques.getParameter(“变量”) Post get 一样 This.request.from(“变量”);post this.Request.QueryString[“变量”]get $_GET[“变量”] $_POST[“变量”] $_REQUEST[“变量”] 包含上面两种方法 request.Form(“变量”) request.QueryString(“变量”)
url中文编码 URLEncoder.encode() URLDecoder.decode() System.Web.HttpContext.Current.Server.UrlEncode() System.Web.HttpContext.Current.Server.UrlDecode() Urlencode(“中文”) urldecode(“中文”)
获得本页url request.getServletPath(); System.Web.HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"]+"" $_SERVER[“PHP_SELF”]; <%=Request.ServerVariables("SCRIPT_NAME")&""%>
Split字符分割 String[] arr; String str="sa,cc,sa"; arr= str.split(","); for(int i=0;i<arr.length td="" <="" }="" {="" system.out.println(arr[i]);="" ;i++)="">string[] arr; string str = "a,bc,c"; arr = str.Split(','); for (int i = 0; i < arr.Length; i++) { this.Response.Write(arr[i]+"

"); }
$str=”ca,cb,css,sdf”; $arr=split(“,”,$str); For($i=0;$i<count($arr);$i++) td="" <="" }="" {="" $arr[$i];="" echo="">dim arr str="a,b,c" arr=Split(str,",") for i=0 to ubound(arr) response.Write(arr(i)&"

") next
构造函数 Prvaite 对象名(){} Prvaite 对象名(){} Function __construct() { } Sub new() End sub
析构函数 Dispose(){} Function destruct(){}
继承 public class a { public a() { System.out.println("ddd"); } } public class test extends a{ public test() {System.out.println("cc"); } } class a { public string a_s = ""; public a() { a_s = "sdfa"; } } class b:a { } Class a {} Class b extends a { } 类似java 无继承 但vb.net用继承 Inherits关键词
应用父类方法 父类: abstract public class parent { public parent(String _name) { this.name=_name; } private String name=""; public String getName() { return name; } public void setName(String string) { name = string; } } 二、子类 public class person extends parent{ private String
sex=""; public person(String _name,String _sex) { super(_name); sex=_sex; } public String getSex() { return sex; } public void setSex(String string) { sex = string; } }
abstract public class parent { private string _name; public string name { get { return _name; } } public parent(string _name) { this._name = _name; } } name=$a . "parent"; } function __destruct() { } } class testclassperson extends testclass { public $age; function __construct($b,$c) { parent::__construct($b); $this->cc($c); } function cc($c) { $this->age=$c; } } $a=new testclassperson("caonimaccc",333); echo
$a->name . "

"; echo $a->age; ?>
应用继承方法 父类 必须是abstract 子类构造函数中 Super(参数) 父类 必须是abstract 子类构造函数:base(参数) 子类构造函数(参数){ parent::__construct(参数) sel::bak(); }
静态对象 public class statictest { static public String a="sss"; } System.out.println( statictest.a); getCount() . "

"; print tatictest::getCount(); ?>
class test { public static string a = "sss"; } this.label1.Text=test.a ;
抽象方法与接口abstract 与interface 定义接口 public interface aaa { public String getname(); } 接口的实现 public class bbb implements aaa { public String getname() { return "aaa";}} 定义抽象类 public abstract class aa { abstract public String getName(); //抽象方法在子类中必须实现 public String getsex(){ return "男";}}
抽象方法的实现 public class bb extends aa{ public String getName(){ return "aaa"; } } 说明:1.interface:中方法只能被定义 Abstract 方法可以定义 也可以实现方法前加abstract 在继承类中必须实现 2.interface 是abstract的特殊方法
接口的定义 interface aaa { string getName(); //接口前不能加public,private ,proctected } 二、接口的实现 class bbb :aaa { public string getName() { return "我是你爹 !"; }} //实现接口的类能能是static 与JAVA的implements关键字对应的是“:” 定义抽象类 abstract class aa { abstract public string getName(); public
string getSex() { return "公"; } } 四、抽象方法的实现 class bb:aa { override public string getName() { return "祖宗!"; } } 说明 :java中“extends”,implements 在c#中只是“:” 抽象类中抽象方法 在继承实现中方法前必须加override 关键字
一、定义接口 getName("我日你祖宗"); ?> getname("asdf"); ?> 说明:PHP接口 抽象类与java的语法很接近 无:asp原始脚本语言不是面向对象的
获得客户、服务器端信息(总结:不同开发语言的服务器提供的参考名称与类型可能有些不同从语法上看jsp 语言没有提供参数 而是每个参数对应一个方法 c#与php比较接近都是参数获得值) request.getHeader("User-Agent") 协议:request.getProtocol() 输出:HTTP/1.1 服务器信息 etServletConfig().getServletContext().getServerInfo() 输出:JavaServer Web Dev Kit/1.0 EA (JSP 1.0; Servlet 2.1; Java 1.2; Windows NT 5.0 x86; java.vendor=Sun Microsystems Inc.) 客户端IP:
request.getRemoteAddr() 输出:192.168.0.106 客户端主机名:request.getRemoteHost() 输出:abc 编码:request.getCharacterEncoding() 输出:GB2312 所发送的字节数:request.getContentLength() 输出:-1 数据类型:request.getContentType() 输出:null Authorization头:request.getAuthType() 输出:basic或者digest
请求类型:request.getMethod() 输出:通常是GET或者POST。但偶尔也会出现HEAD,PUT, Delete,OPTIONS,或者 TRACE. URL中的附加路径信息: request.getPathInfo() 输出:URL中Servlet路径之后、查询字符串之前的那部分。 request.getPathTranslated() 映射到服务器实际路径之后的路径信息。 request.getQueryString() 这是字符串形式的附加到URL后面的查询字符串,数据仍旧是URL编码的。在Servlet中很少需要用到未经解码的数据,一般使用getParameter访问各个参数。
request.getRemoteUser() 如果提供了Authorization头,则代表其用户部分。它代表发出请求的用户的名字。 request.getRequestedSessionId() 输出SessionId request.getRequestURI() 请求URL request.getServletPath() URL中调用Servlet的那一部分,不包含附加路径信息和查询字符串。 request.getHeader("Accept") 访问Accept的HTTP头。 request.getHeader("Host")??
输出:192.168.0.1:8080 request.getHeader("Referer") ????? request.getHeader("Accept-Language") request.getHeader("Accept-Encoding")??? request.getHeader("User-Agent") request.getHeader("Connection") request.getHeader("Cookie") ?? 返回协议名称:request.getScheme() 输出:HTTP
Web服务器名字:request.getServerName() 输出:192.168.0.1 服务器监听的端口:request.getServerPort() 输出:8080
this.Request.ServerVariables["HTTP_USER_AGENT"]+"") asp.net Request.ServerVariables 各参数说明集合 Request.ServerVariables("Url") 返回服务器地址 Request.ServerVariables("Path_Info") 客户端提供的路径信息 Request.ServerVariables("Appl_Physical_Path") 与应用程序元数据库路径相应的物理路径 Request.ServerVariables("Path_Translated")
通过由虚拟至物理的映射后得到的路径 Request.ServerVariables("Script_Name") 执行脚本的名称 Request.ServerVariables("Query_String") 查询字符串?容 Request.ServerVariables("Http_Referer") 请求的字符串?容 Request.ServerVariables("Server_Port") 接受请求的服务器端口号 Request.ServerVariables("Remote_Addr") 发出请求的远程主机的IP地址
Request.ServerVariables("Remote_Host") 发出请求的远程主机名称 Request.ServerVariables("Local_Addr") 返回接受请求的服务器地址 Request.ServerVariables("Http_Host") 返回服务器地址 Request.ServerVariables("Server_Name") 服务器的主机名、DNS地址或IP地址 Request.ServerVariables("Request_Method") 提出请求的方法比如GET、HEAD、POST等等
Request.ServerVariables("Server_Port_Secure") 如果接受请求的服务器端口为安全端口时,则为1,否则为0 Request.ServerVariables("Server_Protocol") 服务器使用的协议的名称和版本 Request.ServerVariables("Server_Software") 应答请求并运行网关的服务器软件的名称和版本 Request.ServerVariables("All_Http") 客户端发送的所有HTTP标头,前缀HTTP_
Request.ServerVariables("All_Raw") 客户端发送的所有HTTP标头,其结果和客户端发送时一样,没有前缀HTTP_ Request.ServerVariables("Appl_MD_Path") 应用程序的元数据库路径 Request.ServerVariables("Content_Length") 客户端发出?容的长度 Request.ServerVariables("Https") 如果请求穿过安全通道(SSL),则返回ON如果请求来自非安全通道,则返回OFF Request.ServerVariables("Instance_ID")
IIS实例的ID号 Request.ServerVariables("Instance_Meta_Path") 响应请求的IIS实例的元数据库路径 Request.ServerVariables("Http_Accept_Encoding") 返回?容如:gzip,deflate Request.ServerVariables("Http_Accept_Language") 返回?容如:en-us Request.ServerVariables("Http_Connection") 返回?容:Keep-Alive
Request.ServerVariables("Http_Cookie") 返回?容如:nVisiT%2DYum=125;ASPSESSIONIDCARTQTRA=FDOBFFABJGOECBBKHKGPFIJI;ASPSESSIONIDCAQQTSRB=LKJJPLABABILLPCOGJGAMKAM;ASPSESSIONIDACRRSSRA=DKHHHFBBJOJCCONPPHLKGHPB Request.ServerVariables("Http_User_Agent") 返回?容:Mozilla/4.0(compatible;MSIE6.0;WindowsNT5.1;SV1)
Request.ServerVariables("Https_Keysize") 安全套接字层连接关键字的位数,如128 Request.ServerVariables("Https_Secretkeysize") 服务器验证私人关键字的位数如1024 Request.ServerVariables("Https_Server_Issuer") 服务器证书的发行者字段 Request.ServerVariables("Https_Server_Subject") 服务器证书的主题字段 Request.ServerVariables("Auth_Password")
当使用基本验证模式时,客户在密码对话框中输入的密码 Request.ServerVariables("Auth_Type") 是用户访问受保护的脚本时,服务器用於检验用户的验证方法 Request.ServerVariables("Auth_User") 代证的用户名 Request.ServerVariables("Cert_Cookie") 唯一的客户证书ID号 Request.ServerVariables("Cert_Flag") 客户证书标?,如有客户端证书,则bit0为0如果客户端证书验证无效,bit1被设置为1
Request.ServerVariables("Cert_Issuer") 用户证书中的发行者字段 Request.ServerVariables("Cert_Keysize") 安全套接字层连接关键字的位数,如128 Request.ServerVariables("Cert_Secretkeysize") 服务器验证私人关键字的位数如1024 Request.ServerVariables("Cert_Serialnumber") 客户证书的序列号字段 Request.ServerVariables("Cert_Server_Issuer")
服务器证书的发行者字段 Request.ServerVariables("Cert_Server_Subject") 服务器证书的主题字段 Request.ServerVariables("Cert_Subject") 客户端证书的主题字段 Request.ServerVariables("Content_Type") 客户发送的form?容或HTTPPUT的数据类型
echo $_SERVER["HTTP_USER_AGENT"]; $_SERVER['HTTP_ACCEPT_LANGUAGE']//浏览器语言 $_SERVER['REMOTE_ADDR'] //当前用户 IP 。 $_SERVER['REMOTE_HOST'] //当前用户主机名 $_SERVER['REQUEST_URI'] //URL $_SERVER['REMOTE_PORT'] //端口。 $_SERVER['SERVER_NAME'] //服务器主机的名称。 $_SERVER['PHP_SELF']//正在执行脚本的文件名
$_SERVER['argv'] //传递给该脚本的参数。 $_SERVER['argc'] //传递给程序的命令行参数的个数。 $_SERVER['GATEWAY_INTERFACE']//CGI 规范的版本。 $_SERVER['SERVER_SOFTWARE'] //服务器标识的字串 $_SERVER['SERVER_PROTOCOL'] //请求页面时通信协议的名称和版本 $_SERVER['REQUEST_METHOD']//访问页面时的请求方法 $_SERVER['QUERY_STRING']
//查询(query)的字符串。 $_SERVER['DOCUMENT_ROOT'] //当前运行脚本所在的文档根目录 $_SERVER['HTTP_ACCEPT'] //当前请求的 Accept: 头部的内容。 $_SERVER['HTTP_ACCEPT_CHARSET'] //当前请求的 Accept-Charset: 头部的内容。 $_SERVER['HTTP_ACCEPT_ENCODING'] //当前请求的 Accept-Encoding: 头部的内容 $_SERVER['HTTP_CONNECTION']
//当前请求的 Connection: 头部的内容。例如:“Keep-Alive”。 $_SERVER['HTTP_HOST'] //当前请求的 Host: 头部的内容。 $_SERVER['HTTP_REFERER'] //链接到当前页面的前一页面的 URL 地址。 $_SERVER['HTTP_USER_AGENT'] //当前请求的 User_Agent: 头部的内容。 $_SERVER['HTTPS']//如果通过https访问,则被设为一个非空的值(on),否则返回off $_SERVER['SCRIPT_FILENAME']
#当前执行脚本的绝对路径名。 $_SERVER['SERVER_ADMIN'] #管理员信息 $_SERVER['SERVER_PORT'] #服务器所使用的端口 $_SERVER['SERVER_SIGNATURE'] #包含服务器版本和虚拟主机名的字符串。 $_SERVER['PATH_TRANSLATED'] #当前脚本所在文件系统(不是文档根目录)的基本路径。 $_SERVER['SCRIPT_NAME'] #包含当前脚本的路径。这在页面需要指向自己时非常有用。 $_SERVER['PHP_AUTH_USER']
#当 PHP 运行在 Apache 模块方式下,并且正在使用 HTTP 认证功能,这个变量便是用户输入的用户名。 $_SERVER['PHP_AUTH_PW'] #当 PHP 运行在 Apache 模块方式下,并且正在使用 HTTP 认证功能,这个变量便是用户输入的密码。 $_SERVER['AUTH_TYPE'] #当 PHP 运行在 Apache 模块方式下,并且正在使用 HTTP 认证功能,这个变量便是认证的类型
同.NET
数据类型 Int(整数) String(字符串) float(浮点数) Boolean(布尔型) public String[] arr; arr=new String[3]; int string float bool string[] arr; arr = new string[3]; arr[0] = "sss"; int string float Boolean 初始化$arr=array(‘sdaf’,’dd’) 直接使用 $arr[0]=’sadf’;
页面跳转 response.setContentType("text/html; charset=gb2312");  response.sendRedirect("/index.jsp"); System.Web.HttpContext.Current.Response.Redirect header("Location: http://www.guanwei.org");
字符串类型 ‘ 单引号 表示char “”双引号表示String ‘ 单引号 表示char “”双引号表示String ‘ 单引号 “双引号 都是字符串 “更多转义字符。字符串中带变量:(PHP独有的) $b="caonimabi"; $a="wo{$b}sss"; echo $a;
判断变量是否是指定类型 String a="aa"; boolean isObject = a instanceof String ; if(isObject) { System.out.println( "ect! "); } int a = 1; if (a.GetType().ToString() == "System.Int32") this.Response.Write(a.GetType().ToString() ); $a=1; if (is_string($a)) { echo gettype($a); }
强制转换 int a=1; float b=(float)a; System.out.print(Float.toString(b)); 样式:(类型)变量; int a = 1; float b = (float)a; this.Response.Write(b.ToString()); 样式:同java $a=13; $b=1.1; $b=(float)$a; echo $b; 样式:同java,c#
数组函数
变量作用范围 String b="sad"; public void test() { System.out.print(b); } String a=”sdf”; Public void test() { this.text=a; } $a='sadf'; function test() { global $a; //echo $GLOBALS["a"]; echo $a; } echo test(); 不同于其它语言在使用函数外的变量时 必须用global 声明
可变变量 "; echo "${$a}"."

";; echo "${0}"; ?>
Cookie 一、设置cookie Cookie myCookie = new Cookie("mycookie2", "myvalue2"); response.addCookie(myCookie); 二、得到所有的Cookie Cookie[] coos=request.getCookies(); //将计数值初始化 //out.print(Integer.toString(coos.length));for(int i=0;i<coos.length;i++) td="" <="" }="" {="" break;=""
out.println(coo.getvalue());="" if(coo.getname().equals(?mycookie2?))="" coo="coos[i];" cookie="">
一、设置cookie HttpCookie cookie = new HttpCookie("MyCook");//初使化并设置Cookie的名称 DateTime dt = DateTime.Now; TimeSpan ts = new TimeSpan(0, 0, 1, 0, 0);//过期时间为1分钟 cookie.Expires = dt.Add(ts);//设置过期时间 cookie.Values.Add("userid", "userid_value"); cookie.Values.Add("userid2",
"userid2_value2"); Response.AppendCookie(cookie); 二、输出cookie Response.Write(Request.Cookies["MyCook"]["userid"]);/
常量 Const a=”sdfsa”; Const a=”sadf”; Define(“a”,”value”);
按位运行 ~ :逻辑非 &:逻辑与 |:逻辑或 ^:逻辑异或 <<:左移位 >>:右移位
比较运算符 == 地址 Equals 地址与内容!= 不等 < <= >= == != < <= > >= == === 内容与类型或!= !==内容与类型 < <= > >=
错误处理 try { 过程} catch {} try { 过程} catch {} B=@函数();
错误屏蔽 在网站路径WEB-INF/WEB.XML 加入 javax.servlet.ServletException /error.jsp Web.config 配置键值 Php.ini 配置键值 display_errors = Off
执行外壳shell命令 try { Runtime.getRuntime().exec("cmd /c del c:\\a.doc"); } catch(Exception e) { } System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents=false; proc.StartInfo.FileName="iexplore"; proc.StartInfo.Arguments="http://www.microsoft.com"; proc.Start(); proc.WaitForExit(); MessageBox.Show("You have just visited
www.microsoft.com");
$output"; ?>
逻辑运算 && || ! && || ! And / && Or / || Xor !
获得或设置session常量
设置工作路径及session 在server.xml中配置 在web.config中 web.config关于sessionState节点的配置方案,sessionState有四种模式:off:关闭 inProc:内存依赖ASP.NET进程 StateServer:内存缓冲区中,再由单独一台机器上运行。状态服务全称是“ASP.NET State Service ”(aspnet_state.exe),计算机管理-服务 里面即可看到此服务,启动该服务 SqlServer:存在数据库中 在php.ini 中 session.save_path = "G:/www/fangweb/ession"
网站文件结构 WEB-INF/classes 二进制类文件 WEB-INF/lib 库文件 WEB-INF/ web.xml应用程序部署描述器头文件上传目录各栏目目录 Images Csss Work :工作目录 Bin :二进制类文件 Web.config 配置文件 Index.aspx头文件上传文件目录各栏目目录 Images Csss Lib :php类文件 Functions 函数库 .htaccess :URL重新文件头文件上传文件目录各栏目目录 Images Css Session :回话存在目录
连接数据库 public Connection getConnection() throws SQLException,NamingException { try { Context initContext = new InitialContext(); Context envContext = (Context)initContext.lookup("java:/comp/env"); DataSource ds = (DataSource)envContext.lookup("jdbc/mysql"); con =
ds.getConnection(); } catch(Exception e) {} return con; }
Function Openconn() As OleDbConnection Dim myconn As OleDbConnection Dim sql As String = ConfigurationSettings.AppSettings("ConnString") Dim data As Byte() = Convert.FromBase64String(sql) sql = System.Text.ASCIIEncoding.ASCII.GetString(data) sql = Replace(sql,
"z#zz", "") sql = Replace(sql, "88#8999", "") myconn = New OleDbConnection(sql) myconn.Open() Return myconn End Function
$conn=mysql_connect($this->db_hosts,$this->db_username,$this->db_password);
数据库查询 public ResultSet getResult(String sql) { ResultSet rs=null; try { stmt=con.createStatement(); rs=stmt.executeQuery(sql); } catch (Exception e) { } return rs; } public DataSet GetDataSet(string sql) {DataSet ds = new DataSet(); try { OleDbCommand cmd = new OleDbCommand(sql, conn); cmd.CommandTimeout = 20; System.Data.OleDb.OleDbDataAdapter adapter = new OleDbDataAdapter(cmd); adapter.Fill(ds, "tempTable"); }catch (Exception
e) { ds = null; } finally {this.Close();}return ds; }
function getsqlrs($sql) { if (""==$sql){errmessage($this->error->db_sqlisnull_err);} $this->sql=$sql; $this->rs=mysql_db_query($this->db_database,$this->sql,$this->conn); return $this->rs; }
数据库更新 public int executeUpdate(String sql) throws SQLException { int result=0; try {stmt=con.createStatement(); result=stmt.executeUpdate(sql); } catch (Exception e) {e.printStackTrace(); } return result; } OleDbCommand cmd = new OleDbCommand(sql, conn); cmd.CommandTimeout = 20; if (this.Open()) cnt = cmd.ExecuteNonQuery(); function sqlexec($sql) { if (""==$sql){ errmessage($this->error->db_sqlisnull_err);} $this->sql=$sql; if (!mysql_db_query($this->db_database,$this->sql,$this->conn)) { return false; } return true; }
数据存储过程查询 public CallableStatement 过程名(int p_page_now , int p_page_size String _Key_string,int d) { CallableStatement callprc=null; try { dbBasis dbbasis=new dbBasis(); Connection con= dbbasis.getConnection(); String st="{call 数据库存储过程(?,?,?,?,?,?,?)}"; callprc=con.prepareCall(st);
callprc.setInt(1,p_page_now); callprc.setInt(2,p_page_size); callprc.registerOutParameter(7,Types.INTEGER); callprc.execute(); return callprc; } 不能关闭连接
DataTable Tb =new DataTable(); pageCount=0; recordCount=0; try { OleDbCommand comm = new OleDbCommand(sql, conn); comm.Parameters.Add(new OleDbParameter("@PageIndex", OleDbType.Integer)); comm.Parameters[0].Value = pageIndex; comm.Parameters.Add(new OleDbParameter("@PageSize",
OleDbType.Integer)); comm.Parameters[2].Direction = ParameterDirection.Output; ccomm.CommandType = CommandType.StoredProcedure; OleDbDataAdapter dbApt = new OleDbDataAdapter(comm); dbApt.Fill(Tb); recordCount = Convert.ToInt32 (comm.Parameters[2].Value.ToString())
; this.Close(); //可以关闭连接 } return Tb;
Php要想实现返回数据集rs与获得输出参数OUT的功能必须采用mysqli类建立 $connli = new mysqli($this->db_hosts,$this->db_username,$this->db_password, $this->db_database); sql="call procname (参考1,参数2)”; $this->connli->multi_query($this->sql); $this->rs=$this->connli->store_result(); $this->connli->next_result();
$rs=$this->connli->store_result(); while (($row =$rs->fetch_assoc())==true) { $rc= $row["ROWS_TOTAL"]; } return $this->rs; 需要说明下out参数其实是以数据集的形式给出的 及在存储过程中 Select* from查询的表 Select @row_cout ; 要想在php中显示返回数据集并返回out参数我目前没有实现但我应用返回两个数据集可以达到同样的效果。
数据存储过程更新 dbBasis dbbasis=new dbBasis(); Connection con= dbbasis.getConnection(); String st="{call 过程名(?)}"; callprc=con.prepareCall(st); callprc.setString(1,PrimaryKey); rows=callprc.executeUpdate(); OleDbCommand comm = new OleDbCommand(sql, conn); comm.Parameters.Add(new OleDbParameter("@id", OleDbType.Integer)); comm.Parameters["@id"].Value = id; comm.Parameters.Add(new OleDbParameter("@CurrtId", OleDbType.Integer)); comm.Parameters["@CurrtId"].Direction
= ParameterDirection.Output; comm.CommandType = CommandType.StoredProcedure;comm.ExecuteNonQuery() ; CurrtId = onvert.ToInt32(comm.Parameters["@CurrtId"].Value.ToString()) ; return CurrtId;
function sqlproc($procname,$arr,$type) { $this->sql="call `" . $procname . "` (". $parm . $type .")"; if (! mysql_db_query($this->db_database,$this->sql,$this->conn)) { return false; } return true; } 就是执行sql语句
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: