数据库结构如下:CREATE TABLE `chat` (
`chat_id` int(11) NOT NULL auto_increment,
`posted_on` datetime NOT NULL,
`user_name` varchar(255) NOT NULL,
`message` text NOT NULL,
`color` char(7) default '#000000',
PRIMARY KEY (`chat_id`)
) ENGINE=MyISAM AUTO_INCREMENT=13 DEFAULT CHARSET=utf8;PHP代码如下:$conn=new mysqli('localhost','root','123456','test');$conn->select_db('test');$result=$conn->query("select posted_on,user_name,message,color from chat");$array=array();while($row=mysqli_fetch_array($result,MYSQL_BOTH)){
$array[]=$row;
}print_r($array);
以上代码经过本地测试,通过
`chat_id` int(11) NOT NULL auto_increment,
`posted_on` datetime NOT NULL,
`user_name` varchar(255) NOT NULL,
`message` text NOT NULL,
`color` char(7) default '#000000',
PRIMARY KEY (`chat_id`)
) ENGINE=MyISAM AUTO_INCREMENT=13 DEFAULT CHARSET=utf8;PHP代码如下:$conn=new mysqli('localhost','root','123456','test');$conn->select_db('test');$result=$conn->query("select posted_on,user_name,message,color from chat");$array=array();while($row=mysqli_fetch_array($result,MYSQL_BOTH)){
$array[]=$row;
}print_r($array);
以上代码经过本地测试,通过
$array = array('1' => array());
}明白把
如:
$query =mysql_query($sql);
下来该怎么转化
$result=$conn->query("select posted_on,user_name,message,color from chat");
就等于你的
$query =mysql_query($sql); 然后将结果集的每一行$row存入到$array,成为$array中的一个元素,这元素本身也是一个数组。