<?php
include 'db.php';//保存数据库信息的
$query="SELECT * FROM word WHERE id='$p'";
$db = mysql_connect($dbserver,$dbid,$dbpassword);//数据库联接
mysql_select_db($dbname,$db);
$p = 2;
$result = mysql_query($query,$db);//sql查找
echo " 1 ";
echo $result;
$myrow = mysql_fetch_row($result);//存入数组
echo " 2 ";
echo $myrow;
echo " 3 ";
printf("%s",$myrow[1]);//输出标题
echo "<br/>";
?>
myrow[1]是text型的
运行后的网址:vilinov.cn/blog/1.php
其余的都正常,就是输出不出来数据库里面的内容。
æçäºä½ ç页é¢ï¼ä½ è¾åºæ²¡æå
容ï¼å¯è½æ¯SQL没ææ¾å°è®°å½ï¼ä½ çç¨åºæ¯å¯¹çã
ä½æ¯ç»ä½ çç¨åºæ个建议ï¼æä»¬å¿ é¡»å¨æ¯ä¸æ¥ä¹åæ£æµç¨åºæ§è¡ç»æï¼ææä½ çç¨åºä¿®æ¹ä¸ºï¼
<?php
include 'db.php';//ä¿åæ°æ®åºä¿¡æ¯ç
$query="SELECT * FROM word WHERE id='$p'";
$db = mysql_connect($dbserver,$dbid,$dbpassword);//æ°æ®åºèæ¥
if ($db){
if (mysql_select_db($dbname,$db)){
$result = mysql_query($query,$db);//sqlæ¥æ¾
if ($result){
$myrow = mysql_fetch_row($result);//åå ¥æ°ç»
if ($myrow) printf("%s",$myrow[1]);//è¾åºæ é¢
else echo "没ææ¾å°ID为 $p çæ°æ®è®°å½ï¼";
mysql_free_result($result);
}else echo "æ§è¡SQLè¯å¥[$query]失败ï¼é误:".mysql_error();
}else echo "æ°æ®åº $dbname ä¸åå¨ï¼";
}else echo "æ°æ®åºè¿æ¥å¤±è´¥ï¼";
echo "<br/>";
?>
ä½æ¯ç»ä½ çç¨åºæ个建议ï¼æä»¬å¿ é¡»å¨æ¯ä¸æ¥ä¹åæ£æµç¨åºæ§è¡ç»æï¼ææä½ çç¨åºä¿®æ¹ä¸ºï¼
<?php
include 'db.php';//ä¿åæ°æ®åºä¿¡æ¯ç
$query="SELECT * FROM word WHERE id='$p'";
$db = mysql_connect($dbserver,$dbid,$dbpassword);//æ°æ®åºèæ¥
if ($db){
if (mysql_select_db($dbname,$db)){
$result = mysql_query($query,$db);//sqlæ¥æ¾
if ($result){
$myrow = mysql_fetch_row($result);//åå ¥æ°ç»
if ($myrow) printf("%s",$myrow[1]);//è¾åºæ é¢
else echo "没ææ¾å°ID为 $p çæ°æ®è®°å½ï¼";
mysql_free_result($result);
}else echo "æ§è¡SQLè¯å¥[$query]失败ï¼é误:".mysql_error();
}else echo "æ°æ®åº $dbname ä¸åå¨ï¼";
}else echo "æ°æ®åºè¿æ¥å¤±è´¥ï¼";
echo "<br/>";
?>
温馨提示:答案为网友推荐,仅供参考