?php
成都创新互联公司10多年成都企业网站建设服务;为您提供网站建设,网站制作,网页设计及高端网站定制服务,成都企业网站建设及推广,对资质代办等多个行业拥有多年的网站维护经验的网站建设公司。
//phpinfo();
$link = @sybase_connect('test', 'sa', '')
or die("Could not connect !"); //连接数据库,第一空必须写服务名称,不能是ip;
echo "Connected successfullybr";
$db = @sybase_select_db("andkylee",$link) //连接数据库
or die("数据库没有选择");
echo "数据库选择成功br";
$sql= "select user_name(uid) as owner,* from dbo.sysobjects where type='U' order by id";
$rs = sybase_query($sql,$link); //查询表
if (!$rs)
{
echo "SQL:".$sql."执行失败!";
exit;
}
//$sybase = sybase_fetch_array($rs);
//print_r($sybase);//结束
echo 'table border="1"trtdID/tdtdNAME/tdtdCOUNT(*)/td';
while ($row = sybase_fetch_array($rs)) {
$id = $row["id"];
$name = $row["name"];
$owner = $row["owner"];
$sql_tablecount = "select count(*) as cnt from ".$owner.".".$name;
$rs_tablecount = sybase_query($sql_tablecount,$link);
$row_tablecount = sybase_fetch_array($rs_tablecount);
$cnt = $row_tablecount["cnt"];
echo 'trtd'.$id.'/tdtd'.$name.'/tdtd'.$cnt.'/td/tr';
}
echo '/table';
sybase_free_result($rs);
sybase_close($link);
?
下面是一个php连接数据库操作的测试代码,你可以参考:
?php
$id = mysql_connect("localhost", "root", "123456") or die(mysql_error());
$ok = mysql_select_db("zf2", $id) or die(mysql_error());
if ($ok) {
echo "ok";
} else {
echo "no";
}
$rs = mysql_query("select * from album order by artist asc");
if ($rs) {
echo "sdfasf";
} else {
echo "fail";
}
if (mysql_num_rows($rs) != 0) {
while($row = mysql_fetch_array($rs)) {
print_r($row['id'] . "br");
}
}
unset($row);
mysql_free_result($rs);
mysql_close($id);
语句是没错,,不知道你安装时MYSQL模块打开了没!!可能是扩展没弄吧!!