php自学代码汇总

Roc posted @ 2011年11月07日 23:47 in C# with tags php oracle , 2126 阅读

开始自学php,代码是自己从网上找的,写在这里作为笔记翻看。

我有SSH整合的经验,也有基础的jdbc知识,学php照猫画虎吧。

查询功能:

 

<?php
//设置页面编码格式
header ( "content-Type: text/html; charset=GBK" );
//生成连接对象$conn,三个参数分别是数据库的用户名,密码,以及sid
$conn = oci_connect ( 'testphp', '123', 'ORACLE11' );
//sql语句
$sql = "select * from userinfo";
//这句话相当于jdbc的preparestatement对象
$statement = oci_parse ( $conn, $sql );
//执行,返回值类型为boolean
if (oci_execute ( $statement )) {
//OCI_BOTH是数字和列名同时索引,如$row[1]和$row['username']的意义是相同的
	while ( ($row = oci_fetch_array ( $statement, OCI_BOTH )) ) {
		echo $row ['USERNAME'] . " " . $row ['PASSWORD'] . "<br>";
		
	}
}
//释放以及关闭资源
oci_free_statement ( $statement );
oci_close ( $conn );
?> 

插入功能:

 

<?php
header ( "content-Type: text/html; charset=GBK" );
?>
<script type="text/javascript">
function validate(){
	var username=document.getElementById("username").value;
	var password=document.getElementById("password").value;
	var pwd=document.getElementById("pwd").value;

	
		document.getElementById("form1").submit();
	
	
	
}
</script>
<form id="form1" action="insertUserinfo.php" method="post">
<table>
	<tr>
		<td>用户名</td>
		<td><input type="text" id="username" name="username"></td>
	</tr>
	<tr>
		<td>密码</td>
		<td><input type="password" id="password" name="password"></td>
	</tr>
	<tr>
		<td>确认密码</td>
		<td><input type="password" id="pwd" name="pwd"></td>
	</tr>
	<tr>
		<td><input type="button" onclick="validate()" id="ok" value="提交"></td>
		<td></td>
	</tr>
</table>
</form>

后台处理:

 

<?php
header ( "content-Type: text/html; charset=GBK" );

$username = $_POST ["username"];
$password = $_POST ["password"];
//mb_convert_encoding($username,"utf-8");

$conn = oci_connect ( 'testphp', '123', 'ORACLE11' );

$statement = oci_parse ( $conn, "insert into userinfo values(idauto.nextval,:username,:password) RETURNING ROWID INTO :id" );

$rowid = oci_new_descriptor ( $conn, OCI_D_ROWID );

oci_bind_by_name ( $statement, ":username", $username, SQL_VARCHAR );
oci_bind_by_name ( $statement, ":password", $password, SQL_VARCHAR );
oci_bind_by_name ( $statement, ":id", $rowid, - 1, OCI_B_ROWID );
if(oci_execute ( $statement)){
	echo $username." ".$password;
}
oci_commit ( $conn );
$rowid->free ();
oci_free_statement ( $statement );
oci_close ( $conn );
?>

这个insert我看了N久的代码,oci上面写的还比较完整,网友也给予一些提示。

为什么页面是GBK格式?因为我插入Oracle的话,utf-8是乱码,GBK就没事,这个问题先这样解决,以后想想如何在utf-8的页面格式下插入数据库

insert语句插入数据库时传参方式和hibernate有点相似,也是冒号:设置参数,不同的是处理sequence上,hibernate在配置文档中写好,php写在sql语句中,估计用到框架的话,也不用再写idauto.nextval了,id是sequence的值,需要我们用oci_new_descriptor 规定一个新的描述,oci_bind_by_name 相当于hibernate的setQuery语句进行传参复制,我甚至怀疑php天生就是防注入的。好了就是这样,update和delete再准备做实验

Avatar_small
babysitting services 说:
2019年10月24日 21:51

Simultaneously residential and additionally commercial properties must contain sparkling sparkling floors. Beyond professional huge cleaning, you could perhaps engage for regular cleaning are crucial the floors you should never turn evasive or tarnished. Given guidelines a portion of the safest and additionally quickest tactic to complete any daily surface cleaning bind.

Avatar_small
maid agency dubai 说:
2021年8月26日 14:16

Making use of the a doormat in the house which is to fight considering the dust airborne debris. Normally per each home there ought to be Doormats to freshen up up that dust easily. In-order to fix dust based on outside, ticket holes and even windows, you may use the doormats designed for preventive activities. Also present clean that dirt and even remove the unnecessary things as a result !.

Avatar_small
monthly cleaning ser 说:
2021年9月29日 17:48

Company cleaning nowadays could be of a number of different types. A company could be contracted in the future in monthly or to do main clean-up work like ground waxing, dusting, draperies and additional major work. Often businesses that employ in professionals monthly are having a person maintain the home during another parts from the month.

Avatar_small
NCERT Geography Samp 说:
2022年9月26日 01:46

Each 6th class student who wants to give their best in every Geography examination conducted by the any Central Education Board in Term-1 & Term-2 such as SA1, SA2, FA1, FA2, FA3, FA4 and Assignments and other types of exams can download NCERT 6th Class Geography Sample Paper 2023 with answers for regular practising by mock tests and revisions. NCERT Geography Sample Paper Class 6 Each 6th class student who wants to give their best in every Geography examination conducted by the any Central Education Board in Term-1 & Term-2 such as SA1, SA2, FA1, FA2, FA3, FA4 and Assignments and other types of exams can download NCERT 6th Class Geography Sample Paper 2023 with answers for regular practising by mock tests and revisions.

Avatar_small
monthly cleaning ser 说:
2023年8月31日 18:29

Inquire by what screening and background records searches the house maid company carries out on individuals. Ask generally if the maids can be employees and subcontractors belonging to the maid product. A house maid service utilising subcontractors will be more unsafe. These citizens are often not necessary to are accountable to work any specific particular precious time, might not have the schooling employees contain, and insurance plans liability will be sketchy.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter