mysql 截断多个表_PHP和MySQL:截断多个表

我试图截断一个表,但为什么它不起作用?数据库查询一定有问题吗?

$sql = "TRUNCATE TABLE `table_name`";

$result = $connection -> query($sql);

理想情况下,我想一次性截断所有表 – 是否可能?

如果你想知道我用来制作数据库查询的类里面是什么,这就是它,

#connects the database and handling the result

class __database {

protected $connection = null;

protected $error = null;

#make a connection

public function __construct($hostname,$username,$password,$database)

{

$this -> connection = new mysqli($hostname,$username,$password,$database);

if (mysqli_connect_errno())

{

printf("Connect failed: %s\n", mysqli_connect_error());

exit();

}

}

...

#performs a query on the database

public function query($query)

{

$result = $this -> connection -> query($query);

if($result)

{

return $result;

}

else

{

$this -> error = $this -> connection -> error;

return false;

}

}

#display error

public function get_error()

{

return $this -> error;

}

#closes the database connection when object is destroyed.

public function __destruct()

{

$this -> connection -> close();

}

}

谢谢.

编辑:

下面是我如何调用db对象,

# the host used to access DB

define('DB_HOST', 'localhost');

# the username used to access DB

define('DB_USER', 'root');

# the password for the username

define('DB_PASS', 'xxx');

# the name of your databse

define('DB_NAME', 'xxx');

$connection = new __database(DB_HOST,DB_USER,DB_PASS,DB_NAME);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值