Using this when not in object context in
程序员文章站
2023-12-30 18:47:16
...
问题
Using $this when not in object context in
解决方法
private $link_id;
private $sql;
private $getAll = array();
private $getOne = array();
private $qRes;
public static function _init(&$dsn, $pconnect = FALSE, $halt = TRUE) {
if(!is_array($dsn)) exit('Error, Dsn not is array');
$dsn['host'] = (isset($dsn['host']))?$dsn['host']:'localhost';
$dsn['login'] = (isset($dsn['login']))?$dsn['login']:'root';
$dsn['dbpwd'] = (isset($dsn['dbpwd']))?$dsn['dbpwd']:NULL;
$dsn['db'] = (isset($dsn['db']))?$dsn['db']:'test';
$dsn['char'] = (isset($dsn['char']))?str_replace('-', NULL, $dsn['char']):'utf8';
if($pconnect) {
if(!$this->link_id = @mysql_pconnect($dsn['host'], $dsn['login'], $dsn['dbpwd'])) {
$halt && $this->getErrorMsg(__LINE__);
}
} else {
if(!$this->link_id = @mysql_connect($dsn['host'], $dsn['login'], $dsn['dbpwd'])) {# 执行到这里出错。。
$halt && $this->getErrorMsg(__LINE__);
}
}
复制代码
参考答案
static function 中 用 self
参考答案
静态函数里用self!!!!!!!!!!!!!!!
参考答案
....我现在没用static,现在是public function 他还是报错
参考答案
那就是没这方法
Using $this when not in object context in
解决方法
private $link_id;
private $sql;
private $getAll = array();
private $getOne = array();
private $qRes;
public static function _init(&$dsn, $pconnect = FALSE, $halt = TRUE) {
if(!is_array($dsn)) exit('Error, Dsn not is array');
$dsn['host'] = (isset($dsn['host']))?$dsn['host']:'localhost';
$dsn['login'] = (isset($dsn['login']))?$dsn['login']:'root';
$dsn['dbpwd'] = (isset($dsn['dbpwd']))?$dsn['dbpwd']:NULL;
$dsn['db'] = (isset($dsn['db']))?$dsn['db']:'test';
$dsn['char'] = (isset($dsn['char']))?str_replace('-', NULL, $dsn['char']):'utf8';
if($pconnect) {
if(!$this->link_id = @mysql_pconnect($dsn['host'], $dsn['login'], $dsn['dbpwd'])) {
$halt && $this->getErrorMsg(__LINE__);
}
} else {
if(!$this->link_id = @mysql_connect($dsn['host'], $dsn['login'], $dsn['dbpwd'])) {# 执行到这里出错。。
$halt && $this->getErrorMsg(__LINE__);
}
}
复制代码
参考答案
static function 中 用 self
参考答案
静态函数里用self!!!!!!!!!!!!!!!
参考答案
....我现在没用static,现在是public function 他还是报错
参考答案
那就是没这方法
推荐阅读
-
Using this when not in object context in
-
遇到Attempt to invoke virtual method ‘java.lang.Object android.content.Context.的解决方案
-
tushare报错之解决(亲测有效):websocket._exceptions,ValueError: No ‘:‘ found when decoding object value
-
Tomcat ssl报错Connector attribute SSLCertificateFile must be defined when using SSL with APR解决方法
-
Mysql 备份数据库方法及when using LOCK TABLES错误解决方法
-
How to fix the "Missing write access" error when using npm 报错
-
一篇文章带你解决 Unable to infer base url. This is common when using dynamic servlet registra
-
[CSS3] Using CSS’s object-fit and object-position Properties(译)_html/css_WEB-ITnose
-
[CSS3] Using CSS’s object-fit and object-position Properties(译)_html/css_WEB-ITnose
-
.Net 连接FTP下载文件报错:System.InvalidOperationException: The requested FTP command is not supported when using HTTP proxy