我试图让我的头围绕mysql。谁能告诉我为什么这个MySQL查询无法正常工作?我收到以下错误:
警告:mysqli_error()期望恰好有1个参数,第11行的/home/freebet2/public_html/test.php中给出的参数为0
test.php
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/includes/db.php'); $conn = db_connect(); $result = $conn->query("ALTER TABLE users ADD COLUMN refer_old INT(10) AFTER refer_id"); if(!$result){ echo "Error with MySQL Query: ".mysqli_error(); } ?>
db.php
<?php function db_connect() { $result = new mysqli('localhost', 'user', 'password', 'db'); if (!$result) { throw new Exception('Could not connect to database server'); } else { return $result; } } ?>
如果我将alter string更改为:之类的$result = $conn->query("SELECT * FROM users refer_id");原因,我不会收到任何错误。
$result = $conn->query("SELECT * FROM users refer_id");
就sql错误而言,“用户”是否具有更改表的权限?