function query($sql) {
$this->sql = $sql;
$result = mysql_query($sql,$this->conn) or die(mysql_error());
if (!$result) {
$this->show("错误SQL语句",$sql);
} else {
$this->result = $result;
}
}
function select($table, $columnName = "*", $condition = '') {
$condition = $condition ? ' WHERE ' . $condition : NULL;
$this->query("SELECT $columnName FROM $table $condition");
}
function fetch_array() {
if(!mysql_fetch_array($this->result)){
$this->show("错误执行");
}else{
return mysql_fetch_array($this->result);
}
}
$this->sql = $sql;
$result = mysql_query($sql,$this->conn) or die(mysql_error());
if (!$result) {
$this->show("错误SQL语句",$sql);
} else {
$this->result = $result;
}
}
function select($table, $columnName = "*", $condition = '') {
$condition = $condition ? ' WHERE ' . $condition : NULL;
$this->query("SELECT $columnName FROM $table $condition");
}
function fetch_array() {
if(!mysql_fetch_array($this->result)){
$this->show("错误执行");
}else{
return mysql_fetch_array($this->result);
}
}
return mysql_fetch_array(mysql_query($this->sql,$this->conn));
function fetch_array() {
if(!mysql_fetch_array($this->result)){
$this->show("错误执行");
}else{
return mysql_fetch_array($this->result);
}
正因为 mysql_fetch_array($this->result); 得不到数据
所以 fetch_array 才得不到数据的
$this->sql = $sql;
$result = mysql_query($sql,$this->conn) or die(mysql_error());
if (!$result) {
$this->show("错误SQL语句",$sql);
} else {
$this->result = $result;
}
}
这个$this->result = $result;不可以这么写是吗?
private $host;
private $name;
private $pwd;
private $dBase;
private $coding;
private $result;
private $conn;
private $sql;
function __construct($host,$name,$pwd,$dBase,$coding)
{
$this->host = $host;
$this->name = $name;
$this->pwd = $pwd;
$this->dBase = $dBase;
$this->coding = $coding;
$this->connect();
}
function connect() {
$this->conn = mysql_connect($this->host, $this->name, $this->pwd);
@mysql_select_db($this->dBase, $this->conn);
mysql_query("SET NAMES $this->coding");
}
function query($sql) {
$this->sql = $sql;
$result = mysql_query($sql,$this->conn) or die(mysql_error());
if (!$result) {
$this->show("错误SQL语句",$sql);
} else {
$this->result = $result;
}
}
function select($table, $columnName = "*", $condition = '') {
$condition = $condition ? ' WHERE ' . $condition : NULL;
$this->query("SELECT $columnName FROM $table $condition");
}
function fetch_array() {
if(!mysql_fetch_array($this->result)){
$this->show("错误执行");
}else{
return mysql_fetch_array($this->$result);
}
}
function free() {
mysql_free_result($this->result);
}
全部就是这样的
$Conn -> select("admin","adminName","adminId=1");
$ConnResult = $Conn -> fetch_array();
$adminName = $ConnResult["adminName"];
return mysql_fetch_array($this->$result);
换成return mysql_fetch_array(mysql_query($this->sql,$this->conn));
就能得到数据function query($sql) {
$this->sql = $sql;
$result = mysql_query($sql,$this->conn) or die(mysql_error());
if (!$result) {
$this->show("错误SQL语句",$sql);
} else {
$this->result = $result;
}这里面的$this->result = $result;不起作用
if(!mysql_fetch_array($this->result)){
$this->show("错误执行");
}else{return mysql_fetch_array($this->$result);
}result 吧?
if(! $this->result){
$this->show("错误执行");
}else{
return mysql_fetch_array($this->$result);
}
if(! $this->result){
$this->show("错误执行");
}else{
return mysql_fetch_array($this->$result);
}这样写会报错$this->$resultfunction fetch_array() {
if(!mysql_fetch_array($this->result)){
$this->show("错误执行");
}else{
return mysql_fetch_array($this->result);
}
}这样写还是读不到数据
if(! $this->result){
$this->show("错误执行");
}else{
return mysql_fetch_array($this->$result);
}
这个可以的