$name = '123'
$sql = "SELECT name FROM order WHERE name ='".$name."'"
$res = mysqli_query($conn,$sql)//也可以直接用 $res = mysqli_query($sql)
$arr = array()
if($res && is_object($res)){
while($row=mysql_fetch_assoc($res)){
$arr[] = $row
}
}
print_r($arr)
$sql = 'SELECT COUNT( * ) FROM DAY WHERE id_u =1'$resault = $db->getAll($sql)
//
function getAll($sql)
{
$res = $this->query($sql)
if ($res !== false)
{
$arr = array()
while ($row = mysql_fetch_assoc($res))
{
$arr[] = $row
}
return $arr
}
else
{
return false
}
}
//
function query($sql, $type = '')
{
if ($this->link_id === NULL)
{
$this->connect($this->settings['dbhost'], $this->settings['dbuser'], $this->settings['dbpw'], $this->settings['dbname'], $this->settings['charset'], $this->settings['pconnect'])
$this->settings = array()
}
if ($this->queryCount++ <= 99)
{
$this->queryLog[] = $sql
}
if ($this->queryTime == '')
{
if (PHP_VERSION >= '5.0.0')
{
$this->queryTime = microtime(true)
}
else
{
$this->queryTime = microtime()
}
}
/* 当当前的时间大于类初始化时间的时候,自动执行 ping 这个自动重新连接 *** 作 */
if (PHP_VERSION >= '4.3' &&time() >$this->starttime + 1)
{
mysql_ping($this->link_id)
}
if (!($query = mysql_query($sql, $this->link_id)) &&$type != 'SILENT')
{
$this->error_message[]['message'] = 'MySQL Query Error'
$this->error_message[]['sql'] = $sql
$this->error_message[]['error'] = mysql_error($this->link_id)
$this->error_message[]['errno'] = mysql_errno($this->link_id)
$this->ErrorMsg()
return false
}
if (defined('DEBUG_MODE') &&(DEBUG_MODE &8) == 8)
{
$logfilename = $this->root_path . DATA_DIR . '/mysql_query_' . $this->dbhash . '_' . date('Y_m_d') . '.log'
$str = $sql . "\n\n"
if (PHP_VERSION >= '5.0')
{
file_put_contents($logfilename, $str, FILE_APPEND)
}
else
{
$fp = @fopen($logfilename, 'ab+')
if ($fp)
{
fwrite($fp, $str)
fclose($fp)
}
}
}
return $query
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)