<?phpfunction db_connect()
{
   $result = new mysqli('localhost', 'root', '1212923456'); 
   if (!$result)
     throw new Exception('Could not connect to database server');
   else
     return $result;
}?>
$result = new mysqli('localhost', 'root', '1212923456');这行报错内容是Fatal error: Class 'mysqli' not found in D:\AppServ\www\26\db_fns.php on line 5

解决方案 »

  1.   

    Installation on Windows SystemsMySQLi is not enabled by default, so the php_mysqli.dll DLL must be enabled inside of php.ini. Also, PHP needs access to the MySQL client library. A file named libmysql.dll is included in the Windows PHP distribution and in order for PHP to talk to MySQL this file needs to be available to the Windows systems PATH. See the FAQ titled "How do I add my PHP directory to the PATH on Windows" for information on how to do this. Although copying libmysql.dll to the Windows system directory also works (because the system directory is by default in the system's PATH), it's not recommended. MySQLi不是默认打开得,你要在php.ini中手动打开!
      

  2.   

    <?phpfunction db_connect()
    {
       $result = new mysqli('localhost', 'root', '1212923456'); 
       if (!$result)
         throw new Exception('Could not connect to database server');
       else
         return $result;
    }$conn=db_connect();
    $result=$conn->query("insert into user values('whh94k','1212923456','[email protected]')");
    ?>
    这样写向数据库增加记录杂没有反应啊 哪错了 
      

  3.   

    你在PHP.ini里面定位到#extension=php_mysql.dll,看看#号有没有被去掉,#是注释,你需要把mysql.dll解开PHP才能加载mysql模块
      

  4.   

    注意!你用的mysqli函数是否在PHP。INI下启动了
    另外
    你这样连接是不对的
    <?php function   db_connect() 

          $result   =   new   mysqli('localhost',   'root',   '1212923456');   
          if   (!$result) 
              throw   new   Exception('Could   not   connect   to   database   server'); 
          else 
              return   $result; 
    } ?> 
    $result   =   new   mysqli('localhost',   'root',   '1212923456');因为你实现声明了一个函数,函数名为db_connect()
    这个函数的工作思路是利用$result得到一个连接数据库的对象
    如果非$re就抛出一个异常。否则返回连接后的
    那么你应该在具体的应用时候
    直接插入 db_connect();
    即可