1、MySQL 是最流行的开源数据库服务器;
2、连接MySql数据库:mysql_connect(servername, username, password);//servername默认localhost:3306;username默认用户名;password默认是空;
关闭连接:mysql_close($con);
建库建表:mysql_query(sql, $con);mysql_select_db(dbname, $con);
错误消息:die("error" . mysql_error());if()
增删改查:mysql_query();mysql_fetch_array();
ODBC:通过一个 ODBC 连接,您可以连接到您的网络中的任何计算机上的任何数据库,只要 ODBC 连接是可用的
odbc_connect()
odbc_exec()
odbc_fetch_row()
odbc_result()
odbc_close()
3、XML解析:Expat解析器(基于事件)
基于树的解析器:这种解析器把 XML 文档转换为树型结构。它分析整篇文档,并提供了 API 来访问树种的元素,例如文档对象模型 (DOM)
基于事件的解析器:将 XML 文档视为一系列的事件。当某个具体的事件发生时,解析器会调用函数来处理
<?php
//Initialize the XML parser
$parser=xml_parser_create();
//Function to use at the start of an element
function start($parser,$element_name,$element_attrs)
{
switch($element_name)
{
case "NOTE":
echo "-- Note --<br />";
break;
case "TO":
echo "To: ";
break;
case "FROM":
echo "From: ";
break;
case "HEADING":
echo "Heading: ";
break;
case "BODY":
echo "Message: ";
}
}
//Function to use at the end of an element
function stop($parser,$element_name)
{
echo "<br />";
}
//Function to use when finding character data
function char($parser,$data)
{
echo $data;
}
//Specify element handler
xml_set_element_handler($parser,"start","stop");
//Specify data handler
xml_set_character_data_handler($parser,"char");
//Open XML file
$fp=fopen("test.xml","r");
//Read data
while ($data=fread($fp,4096))
{
xml_parse($parser,$data,feof($fp)) or
die (sprintf("XML Error: %s at line %d",
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser)));
}
//Free the XML parser
xml_parser_free($parser);
?>
DOM解析器(基于树)
Core DOM - 为任何结构化文档定义标准的对象集
XML DOM - 为 XML 文档定义标准的对象集
HTML DOM - 为 HTML 文档定义标准的对象集
SimpleXML:
<?php
$xml = simplexml_load_file("test.xml");
echo $xml-getName() . "<br />";
foreach($xml->children() as $child){
echo $child->getName() . ":" . $child . "<br />";
}
?>
4、PHP和AJAX:AJAX = Asynchronous JavaScript And XML(异步 JavaScript 及 XML)
XMLHttpRequest 对象使 AJAX 成为可能
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
js:
var xmlHttp
function showHint(str)
{
if (str.length==0)
{
document.getElementById("txtHint").innerHTML=""
return
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="gethint.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
js:
var xmlHttp
function showCD(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="getcd.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
5、JavaScript:JavaScript 是世界上最流行的脚本语言 Brendan Eich
document.write("<h1>This is a heading</h1>");
alert("Welcome");
x = document.getElementById("demo");
x.innerHTML = "Hello JavaScript";
element = document.getElementById('myimage');
if(element.src.match("bulbon")){
element.src = "/i/eg_bulboff.gif";
}
x = document.getElementById("demo");
x.style.color = '#ff0000';
if isNaN(x){alert('not numeric');}
6、基本语法:
<script type="text/javascript">
function myFunction(){
document.getElementById("demo").innerHTML="My First JavaScript Function";
}
</script>
或:<script src="myscript.js" />
7、各种细节:
document.getElementById("demo").innerHTML = "Hello World";
document.write("hello");
var name = "Hello";
// /**/
var flag = false;
var cars = new Array();
cars[0] = "Audi";
var cars = new Array("Audi", "BMW", "Volvo");
var cars = ["Audi", "BMW", "Volvo"];
var person = {
firstname : "Gates";
lastname : "Bill"
id : 5566;
};
name = person.lastname;
name = person["lastname"];
cars = null;
person = null;
var carname = new String;
var x = new Number;
var y = new Boolean;
var cars = new Array;
var person = new Object;
for(x in person)
try catch throw
var x = document.getElementById("main");
var y = x.getElementsByTagName("p");
document.getElementById(id).style.property = newStyle;
8、DOM元素节点:
增加:
var para=document.createElement("p");
var node=document.createTextNode("这是新段落。");
para.appendChild(node);
var element=document.getElementById("div1");
element.appendChild(para);
删除:
var parent=document.getElementById("div1");
var child=document.getElementById("p1");
parent.removeChild(child);
9、访问对象的属性:objectName.propertyName
访问对象的方法:objectName.methodName()
person=new Object();
person.firstname="Bill";
person.lastname="Gates";
person.age=56;
person.eyecolor="blue";
person={firstname:"John",lastname:"Doe",age:50,eyecolor:"blue"};
function person(firstname,lastname,age,eyecolor){
this.firstname=firstname;
this.lastname=lastname;
this.age=age;
this.eyecolor=eyecolor;
}
var myFather=new person("Bill","Gates",56,"blue");
10、 我有网我怕谁