为什么我的php不能读取mysql数据
我的代码是<?//...........基本设定$mysql_server_name="localhost";$mysql_username="root";$mysql_...
我的代码是
<?
//...........基本设定
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "123465";
$mysql_database = "datetable";
$sql = "select * from table";
//...............
$conn= mysql_connect($mysql_server_name,$mysql_username,$mysql_password);
$result= mysql_db_query($mysql_database,$sql,$conn);
$row= mysql_fetch_row($result);
//........表格开始
echo "<table border=1 cellpacing=0 cellpadding=0>\n";
//......印出栏位名称
echo "<tr>\n";
for($i=0;$i<mysql_num_fields($result);$i++)
{
echo "<td nowrap>".mysql_field_name($result,$i)."</td>\n";
}
echo "</tr>\n";
//.....将资料移回第一笔
mysql_data_seek($result,0);
//........印出资料内容
while($row= mysql_fetch_row($result))
{
echo "<tr>\n";
for($i=0;$i<mysql_num_fields($result);$i++)
{
echo "<td nowrap>$row[$i]</td>\n";
}
echo "</tr>\n";
}
//....表格结束
echo "</table>";
mysql_free_result($result);
?>
总提示这样的错误
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\Apache2.2\htdocs\a\d.php on line 18
Warning: mysql_num_fields(): supplied argument is not a valid MySQL result resource in C:\Apache2.2\htdocs\a\d.php on line 23
Warning: mysql_data_seek(): supplied argument is not a valid MySQL result resource in C:\Apache2.2\htdocs\a\d.php on line 29
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\Apache2.2\htdocs\a\d.php on line 31
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in C:\Apache2.2\htdocs\a\d.php on line 42
请高手帮帮忙,我快愁死了~~~~~~~ 展开
<?
//...........基本设定
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "123465";
$mysql_database = "datetable";
$sql = "select * from table";
//...............
$conn= mysql_connect($mysql_server_name,$mysql_username,$mysql_password);
$result= mysql_db_query($mysql_database,$sql,$conn);
$row= mysql_fetch_row($result);
//........表格开始
echo "<table border=1 cellpacing=0 cellpadding=0>\n";
//......印出栏位名称
echo "<tr>\n";
for($i=0;$i<mysql_num_fields($result);$i++)
{
echo "<td nowrap>".mysql_field_name($result,$i)."</td>\n";
}
echo "</tr>\n";
//.....将资料移回第一笔
mysql_data_seek($result,0);
//........印出资料内容
while($row= mysql_fetch_row($result))
{
echo "<tr>\n";
for($i=0;$i<mysql_num_fields($result);$i++)
{
echo "<td nowrap>$row[$i]</td>\n";
}
echo "</tr>\n";
}
//....表格结束
echo "</table>";
mysql_free_result($result);
?>
总提示这样的错误
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\Apache2.2\htdocs\a\d.php on line 18
Warning: mysql_num_fields(): supplied argument is not a valid MySQL result resource in C:\Apache2.2\htdocs\a\d.php on line 23
Warning: mysql_data_seek(): supplied argument is not a valid MySQL result resource in C:\Apache2.2\htdocs\a\d.php on line 29
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\Apache2.2\htdocs\a\d.php on line 31
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in C:\Apache2.2\htdocs\a\d.php on line 42
请高手帮帮忙,我快愁死了~~~~~~~ 展开
4个回答
展开全部
嗯,就是少了选择数据库这一部mysql_select_db($mysql_database);
然后query一下$result = mysql_query("select * from table");
其它的就差不多了
平时多看manual
然后query一下$result = mysql_query("select * from table");
其它的就差不多了
平时多看manual
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
你把 sql 语句贴出来
这些 虽说 不提倡了 不过也可以用
不至于 不能查询出结果
你把 sql 语句贴出来
这些 虽说 不提倡了 不过也可以用
不至于 不能查询出结果
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在mysql_connect后+上 mysql_select_db($mysql_database);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询