<?php
/*
 * Created on 2010-3-3
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 $mysqli=mysqli_connect("localhost","root","x-d","news");
$sql = "SELECT * FROM news";
$res = mysqli_query($mysqli,$sql);$a = mysql_fetch_array($res);
$num = mysql_num_rows($a);echo $num;?>报下面的错 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in G:\PHP\news\select.php on line 14 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in G:\PHP\news\select.php on line 15 请大侠指导

解决方案 »

  1.   

    news 既是数据库名又是表名?
      

  2.   

    你不要把mysqli和mysql混着用.....
      

  3.   

    应该是$res = mysqli_query($mysqli,$sql)这句有问题.楼主看看手册:
    mixed mysqli_query ( mysqli $link , string $query [, int $resultmode ] )
      

  4.   

    $a = mysql_fetch_array($res);
    $num = mysql_num_rows($a);---------------------------把上面的mysql_ 换成mysqli_
      

  5.   

    发现函数混用啊,mysql和mysqli.楼主还是查查手册吧
      

  6.   

    你得保证mysqli_connect中最后一个参数news是数据库名称
    <?php
    /*
     * Created on 2010-3-3
     *
     * To change the template for this generated file go to
     * Window - Preferences - PHPeclipse - PHP - Code Templates
     */
    $mysqli=mysqli_connect("localhost","root","x-d","news");
    $sql = "SELECT * FROM news";
    $res = mysqli_query($mysqli,$sql);$a = mysqli_fetch_array($res);
    $num = mysqli_num_rows($res);echo $num;
    print_r($a);
    ?>
      

  7.   

    谢谢各位哈,小弟刚学php,还请以后多多指教!