这个例程简单演示了 php 通过 odbc 访问数据库. 只需要通过 控制面板->ODBC 数据源->添加数据源(WebTest)即可. |
操作 | ||||||
操作 | ||||||
|
if(strcmp($verb,"")!=0){
if(strcmp($verb,"Create Table")==0){$sql_string="create table testtb (n integer, name char(40))";$err_msg="创建数据表时出错, 该表已经存在?";
}else if(strcmp($verb,"Drop Table")==0){$sql_string="drop table testtb";$err_msg="Drop数据表时出错, 该表不存在?";
}else if(strcmp($verb,"Insert")==0){$sql_string="insert into testtb values ($n,'$name')";$err_msg="添加新记录时出错, 请检查您填写的数据.";
}else if(strcmp($verb,"Delete")==0){$sql_string="delete from testtb where n = $n";$err_msg="删除记录时出错, 请检查您填写的数据.";
}else if(strcmp($verb,"Update")==0){$sql_string="update testtb set name = '$name' where n = $n";$err_msg="更新记录时出错, 请检查您填写的数据.";$err_msg="更新记录时出错, 请检查您填写的数据.";
}
print$sql_string;
if(!odbc_exec($con_id,$sql_string))
echo$err_msg;
}
if($result=odbc_exec($con_id,"select n, name from testtb")){?>
查询结果 | |
编号 | 名称 |
,odbc_result($result,2));?>
printf("
%d%sn",odbc_result($result,1)}else
echo"查询失败, 请确认正确数据表存在.";odbc_close($con_id);
}else
echo"连接数据库失败, 请检查您是否正确的配置了 ODBC 数据源.";?>