我的数据库连接代码是
public function open()
{
$db = new Data_Mysql();
return $db;
}
function __construct($pconnect = 0)
{
try {
$func = $pconnect==0 ? 'mysql_connect' : 'mysql_pconnect';
$this->link = @$func($this->dbhost, $this->dbuser, $this->dbpw, 1);
$charset1 = $this->dbcharset == '' ? $this->charset : "GB2312";
if(!empty($charset1))
{
if(function_exists('mysql_set_charset'))
{
@mysql_set_charset($charset1, $this->link);
}
else
{
$collation_query = "SET NAMES '{$charset1}'";
$this->Query($collation_query);
}
}
$this->dbname && @mysql_select_db($this->dbname, $this->link);
} catch (Exception $e) {
if ($this->errno())
{
throw new Common_MyException("Can't connect to database./数据库服务器连接失败 ");
}
}
}
function Query($sql)//执行代码
{
try
{
if(!($result = @mysql_query($sql, $this->link)))
{
throw new Common_MyException($this->error());
}
}
catch (Common_MyException $e)
{
die($e->showStackTrace());
}
return $result;
}
function __destruct()//断开连接
{
if (!$this->errno())
{
$this->close();
}
}
//释放结果集所占用的内存
function free_result($query) {
return mysql_free_result($query);
}
//返回多条记录
public function FetchAll($sql)
{
$returnRows=array();
try
{
if($sql==null) {
throw new MyException("查询语句为空.");
}
if(!($result = $this->Query($sql)))
{
throw new Common_MyException($this->error());
}
while ($rows=$this->fetch_array($result))
{
$returnRows[]=$rows;
}
return $returnRows;
}
catch (Common_MyException $e)
{
die($e->showStackTrace());
}
}
function FetchRow($sql)//返回单条记录
{
$rows=null;
try
{
if($sql==null || $sql=="") {
throw new MyException("查询语句为空.");
}
if(!($result = $this->Query($sql)))
{
throw new Common_MyException($this->error());
}
$rows = $this->fetch_array($result);
}
catch (Common_MyException $e)
{
die($e->showStackTrace());
}
return $rows;
}
function error() {
return (($this->link) ? mysql_error($this->link) : mysql_error());
}
function errno() {
return intval(($this->link) ? mysql_errno($this->link) : mysql_errno());
}
function select_db($dbname) {
return mysql_select_db($dbname, $this->link);
}
function close() {
return mysql_close($this->link);
}
function num_rows($query) {
$query = mysql_num_rows($query);
return $query;
}
function result($query, $row = 0) {
$query = @mysql_result($query, $row);
return $query;
}
function insert_id() {
return ($id = mysql_insert_id($this->link)) >= 0 ? $id : $this->result($this->query("SELECT last_insert_id()"), 0);
}
function fetch_array($query, $result_type = MYSQL_ASSOC) {
return mysql_fetch_array($query, $result_type);
}可是网站都是频繁报错
Warning: mysql_set_charset() expects parameter 2 to be resource, boolean given in D:\webSite\wwwz2gcomcn\Inc\Data\Mysql.php on line 37Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\webSite\wwwz2gcomcn\Inc\Data\Mysql.php on line 62
或者
Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in D:\webSite\wwwz2gcomcn\Inc\Data\Mysql.php on line 151
哪位高手能帮我解决下呀,小弟在这不胜感激
public function open()
{
$db = new Data_Mysql();
return $db;
}
function __construct($pconnect = 0)
{
try {
$func = $pconnect==0 ? 'mysql_connect' : 'mysql_pconnect';
$this->link = @$func($this->dbhost, $this->dbuser, $this->dbpw, 1);
$charset1 = $this->dbcharset == '' ? $this->charset : "GB2312";
if(!empty($charset1))
{
if(function_exists('mysql_set_charset'))
{
@mysql_set_charset($charset1, $this->link);
}
else
{
$collation_query = "SET NAMES '{$charset1}'";
$this->Query($collation_query);
}
}
$this->dbname && @mysql_select_db($this->dbname, $this->link);
} catch (Exception $e) {
if ($this->errno())
{
throw new Common_MyException("Can't connect to database./数据库服务器连接失败 ");
}
}
}
function Query($sql)//执行代码
{
try
{
if(!($result = @mysql_query($sql, $this->link)))
{
throw new Common_MyException($this->error());
}
}
catch (Common_MyException $e)
{
die($e->showStackTrace());
}
return $result;
}
function __destruct()//断开连接
{
if (!$this->errno())
{
$this->close();
}
}
//释放结果集所占用的内存
function free_result($query) {
return mysql_free_result($query);
}
//返回多条记录
public function FetchAll($sql)
{
$returnRows=array();
try
{
if($sql==null) {
throw new MyException("查询语句为空.");
}
if(!($result = $this->Query($sql)))
{
throw new Common_MyException($this->error());
}
while ($rows=$this->fetch_array($result))
{
$returnRows[]=$rows;
}
return $returnRows;
}
catch (Common_MyException $e)
{
die($e->showStackTrace());
}
}
function FetchRow($sql)//返回单条记录
{
$rows=null;
try
{
if($sql==null || $sql=="") {
throw new MyException("查询语句为空.");
}
if(!($result = $this->Query($sql)))
{
throw new Common_MyException($this->error());
}
$rows = $this->fetch_array($result);
}
catch (Common_MyException $e)
{
die($e->showStackTrace());
}
return $rows;
}
function error() {
return (($this->link) ? mysql_error($this->link) : mysql_error());
}
function errno() {
return intval(($this->link) ? mysql_errno($this->link) : mysql_errno());
}
function select_db($dbname) {
return mysql_select_db($dbname, $this->link);
}
function close() {
return mysql_close($this->link);
}
function num_rows($query) {
$query = mysql_num_rows($query);
return $query;
}
function result($query, $row = 0) {
$query = @mysql_result($query, $row);
return $query;
}
function insert_id() {
return ($id = mysql_insert_id($this->link)) >= 0 ? $id : $this->result($this->query("SELECT last_insert_id()"), 0);
}
function fetch_array($query, $result_type = MYSQL_ASSOC) {
return mysql_fetch_array($query, $result_type);
}可是网站都是频繁报错
Warning: mysql_set_charset() expects parameter 2 to be resource, boolean given in D:\webSite\wwwz2gcomcn\Inc\Data\Mysql.php on line 37Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\webSite\wwwz2gcomcn\Inc\Data\Mysql.php on line 62
或者
Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in D:\webSite\wwwz2gcomcn\Inc\Data\Mysql.php on line 151
哪位高手能帮我解决下呀,小弟在这不胜感激
解决方案 »
- java.sql.SQLException: [Microsoft][ODBC Microsoft Access 驱动程序] 参数不足,期待是 1。
- 求教:mysql插入数据错误
- sql语句中password句的困惑,求高手解答
- 十万火急!关于MYODBC远程连接MYSQL的问题,大家帮忙
- 求救:怎么我在Redhat9.0下无法启动mysql呀!!!
- 麻烦给解释一下mysql的表类型的区别及什么情况下使用何种类型!!
- 编辑数据库时报错 read only, 如何解决?
- 求教MySQL C++连接时程序崩溃时的异常处理问题
- 我可不可以用这样一个组合?? JSP + MYSQL + Liunx ???????
- Mysql启动后过几秒钟就自动停止了怎么解决啊?
- 能建一张表,其中一个字段作为外键参照到的是表中的另一个字段么??
- grall all 给 192.168.10.%赋予最大权限给某个库 但是更新失败
InnoDB: a new database to be created!
100419 1:30:31 InnoDB: Setting file .\ibdata1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
100419 1:30:31 InnoDB: Log file .\ib_logfile0 did not exist: new to be created
InnoDB: Setting log file .\ib_logfile0 size to 23 MB
InnoDB: Database physically writes the file full: wait...
100419 1:30:32 InnoDB: Log file .\ib_logfile1 did not exist: new to be created
InnoDB: Setting log file .\ib_logfile1 size to 23 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Doublewrite buffer created
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
100419 1:30:32 InnoDB: Started; log sequence number 0 0
100419 1:30:32 [Note] C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt: ready for connections.
Version: '5.0.45-community-nt' socket: '' port: 3306 MySQL Community Edition (GPL)
100420 13:40:35 [Note] C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt: Normal shutdown100420 13:40:35 InnoDB: Starting shutdown...
100420 13:40:39 InnoDB: Shutdown completed; log sequence number 0 160805925
100420 13:40:39 [Note] C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt: Shutdown complete100420 13:45:31 InnoDB: Started; log sequence number 0 160805925
100420 13:45:32 [Note] C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt: ready for connections.
Version: '5.0.45-community-nt' socket: '' port: 3306 MySQL Community Edition (GPL)
MYSQL里的日志是这样的,我也看不懂,能帮我解释下吗?是代码问题还是程序问题呀