菜鸟写的一个操作MYSQL数据库的类,异常重重。请指正或者求类似的代码

WBOY
Release: 2016-06-13 13:49:57
Original
773 people have browsed it

初学者写的一个操作MYSQL数据库的类,错误重重。请指正或者求类似的代码
  class   TDbOpr
{
      public   var   $cn   =   new   mysqli( 'localhost ',   'root ',   'sa ',   'test ');
      //连接数据库
      function   Connected()
      {
          return   $cn-> mysqli_connect_errno   ==   0;
      }
      //执行SQL语句
      function   Execute($S)
      {
          $cn-> query($S);
          return   $cn-> errno   ==   0;
      }
      //读取数据
      function   ReadData($S,   &$ResultData)
      {
          $ResultData   =   $cn-> query($S);
          return   $cn-> errno   ==   0;
      }
      //关闭连接
      function   Close()
      {
          $cn-> close();
      }
//调用实例
    var   $db   =   new   TDbOpr();
    if   ($db-> Connected())
    {
        echo   "数据库连接成功。 ";
    }  
    else
    {
        echo   "数据库连接失败。 ";
    }
  ?>

------解决方案--------------------

class TDbOpr
{
public var $cn = new mysqli( 'localhost ', 'root ', 'sa ', test);
//连接数据库
function Connected()
{
return $cn-> connect_errno 0;
}
//执行SQL语句
function Execute($S)
{
$cn-> query($S);
return $cn-> errno 0;
}
//读取数据
//执行SQL语句
function ReadData($S, &$ResultData)
{
ResultData = $cn-> query($S);
print_r($ResultData);
echo '
';
echo $cn-> errno;
return $cn-> errno 0;
}
//关闭连接
function Close()
{
$cn-> close();
}
}

?>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!