以下是工作中收集几个的数据库连接程序,可用于测试数据库。 access 2003连接程序(asp): % dim dbpath,connstr,conn dbpath="#bjbaidu.mdb" connstr="DRIVER=Microsoft Access Driver (*.mdb);DBQ="server.mappath(dbpath) Set conn = Server.CreateObject(
以下是工作中收集几个的数据库连接程序,可用于测试数据库。
access 2003连接程序(asp):
dim dbpath,connstr,conn
dbpath="#bjbaidu.mdb"
connstr="DRIVER=Microsoft Access Driver (*.mdb);DBQ="&server.mappath(dbpath)
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open connstr
%>
access 2007连接程序(asp):
dim dbpath,connstr,conn
dbpath="123.accdb"
connstr="DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ="&server.mappath(dbpath)
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open connstr
%>
access连接(php):
/*
* 创建ADO连接
*/
$conn = @new COM("ADODB.Connection") or die ("ADO Connection faild.");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("#bjbaidu.mdb");
$conn->open($connstr);
/*
* 创建记录集
*/
$rs = @new COM("ADODB.RecordSet");
$rs->open("select * from bj_link",$conn,1,3);
/*
* 循环读取数据
*/
while(!$rs->eof){
echo $rs->fields['Title']->Value;
echo "
";
$rs->movenext(); //将记录集指针下移
}
$rs->close();
?>
mysql连接(php):
header("Content-type: text/html; charset=utf-8");
$mysql_server_name="222.76.214.216"; //数据库服务器名称
$mysql_username="sunhillscn"; // 连接数据库用户名
$mysql_password="123"; // 连接数据库密码
$mysql_database="sunhillscn"; // 数据库的名字
// 连接到数据库
$conn=mysql_connect($mysql_server_name, $mysql_username,
$mysql_password);
// 从表中提取信息的sql语句
$strsql="select * from cnscms_article limit 5";
// 执行sql查询
$result=mysql_db_query($mysql_database, $strsql, $conn);
// 获取查询结果
$row=mysql_fetch_row($result);
echo '
';
echo '';
// 显示字段名称
echo "\n
\n";
for ($i=0; $i {
echo ''. mysql_field_name($result, $i); echo " | \n";
}
echo "
\n";
// 定位到第一条记录
mysql_data_seek($result, 0);
// 循环取出记录
while ($row=mysql_fetch_row($result))
{
echo "\n";
for ($i=0; $i {
echo ''; echo "$row[$i]"; echo ' | ';
}
echo "
\n";
}
echo "
\n";
echo "";
// 释放资源
mysql_free_result($result);
// 关闭连接
mysql_close();
?>
如需更多数据库连接代码,请访问http://www.connectionstrings.com/。
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn