php面向对象操作mysql。我需要修改什么地方?
<?phpclassmysql{private$host;private$root;private$pass;private$table;function__constr...
<?php
class mysql{
private $host;
private $root;
private $pass;
private $table;
function __construct($host,$root,$pass,$table){
$this->host=$host;
$this->root=$root;
$this->pass=$pass;
$this->table=$table;
$this->connect();
}
function query($table){
mysql_query($table);
}
function connect(){
$xiaoguang=mysql_connect($this->host,$this->root,$this->pass)or die(mysql_error());
mysql_select_db($this->table,$xiaoguang)or die (mysql_error());
}
function fn_inset($table,$name,$value){
$this->query("insert into $table ($name) value ($value)");
}
}
$db = new mysql('localhost','root','','xiaoguang');
$db->fn_inset('table','id,table,content,time',"'','我插入的信息','我插入的内容','time()'")
?> 展开
class mysql{
private $host;
private $root;
private $pass;
private $table;
function __construct($host,$root,$pass,$table){
$this->host=$host;
$this->root=$root;
$this->pass=$pass;
$this->table=$table;
$this->connect();
}
function query($table){
mysql_query($table);
}
function connect(){
$xiaoguang=mysql_connect($this->host,$this->root,$this->pass)or die(mysql_error());
mysql_select_db($this->table,$xiaoguang)or die (mysql_error());
}
function fn_inset($table,$name,$value){
$this->query("insert into $table ($name) value ($value)");
}
}
$db = new mysql('localhost','root','','xiaoguang');
$db->fn_inset('table','id,table,content,time',"'','我插入的信息','我插入的内容','time()'")
?> 展开
3个回答
2012-05-29 · 知道合伙人软件行家
关注
展开全部
试修改代码如下:
<?php
class mysql
{
private $host;
private $root;
private $pass;
private $conn;
private $table;
function __construct($host, $root, $pass, $table)
{
$this->host = $host;
$this->root = $root;
$this->pass = $pass;
$this->table = $table;
$this->connect();
}
function connect()
{
$this->conn = mysql_connect($this->host, $this->root, $this->pass) or die(mysql_error());
mysql_select_db($this->table, $this->conn) or die(mysql_error());
}
function query($table)
{
mysql_query($table,$this->conn);
}
function fn_inset($table, $name, $value)
{
echo "insert into $table ($name) value ($value)";
//$this->query("insert into $table ($name) value ($value)");
}
}
$db = new mysql('localhost','root','','xiaoguang');
$db->fn_inset('table', 'id,table,content,time', "'','我插入的信息','我插入的内容',time()")
?>
<?php
class mysql
{
private $host;
private $root;
private $pass;
private $conn;
private $table;
function __construct($host, $root, $pass, $table)
{
$this->host = $host;
$this->root = $root;
$this->pass = $pass;
$this->table = $table;
$this->connect();
}
function connect()
{
$this->conn = mysql_connect($this->host, $this->root, $this->pass) or die(mysql_error());
mysql_select_db($this->table, $this->conn) or die(mysql_error());
}
function query($table)
{
mysql_query($table,$this->conn);
}
function fn_inset($table, $name, $value)
{
echo "insert into $table ($name) value ($value)";
//$this->query("insert into $table ($name) value ($value)");
}
}
$db = new mysql('localhost','root','','xiaoguang');
$db->fn_inset('table', 'id,table,content,time', "'','我插入的信息','我插入的内容',time()")
?>
展开全部
试修改代码如下:
<?php
class mysql
{
private $host;
private $root;
private $pass;
private $conn;
private $table;
function __construct($host, $root, $pass, $table)
{
$this->host = $host;
$this->root = $root;
$this->pass = $pass;
$this->table = $table;
$this->connect();
}
function connect()
{
$this->conn = mysql_connect($this->host, $this->root, $this->pass) or die(mysql_error());
mysql_select_db($this->table, $this->conn) or die(mysql_error());
}
function query($table)
{
mysql_query($table,$this->conn);
}
function fn_inset($table,array $field,array $value)
{
$str_field = is_array($field) ? implode(',',$field) : $field;
$str_value = is_array($value) ? implode(',',$value) : $value;
$this->query("insert into $table ($str_field ) value ($str_value )");
}
}
$db = new mysql('localhost','root','','xiaoguang');
$field = array('id','table','content','time');
$value= array( ' ','我插入的信息','我插入的内容',time());
$db->fn_inset('table', $field,$value);
?>
你这样试一下!
<?php
class mysql
{
private $host;
private $root;
private $pass;
private $conn;
private $table;
function __construct($host, $root, $pass, $table)
{
$this->host = $host;
$this->root = $root;
$this->pass = $pass;
$this->table = $table;
$this->connect();
}
function connect()
{
$this->conn = mysql_connect($this->host, $this->root, $this->pass) or die(mysql_error());
mysql_select_db($this->table, $this->conn) or die(mysql_error());
}
function query($table)
{
mysql_query($table,$this->conn);
}
function fn_inset($table,array $field,array $value)
{
$str_field = is_array($field) ? implode(',',$field) : $field;
$str_value = is_array($value) ? implode(',',$value) : $value;
$this->query("insert into $table ($str_field ) value ($str_value )");
}
}
$db = new mysql('localhost','root','','xiaoguang');
$field = array('id','table','content','time');
$value= array( ' ','我插入的信息','我插入的内容',time());
$db->fn_inset('table', $field,$value);
?>
你这样试一下!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
想要什么效果?插入中文不乱码还是怎么的?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询