唉,我无法理解这一点。我有一个与mySQL数据库的连接:
function db_connect() {
static $connection;
if(!isset($connection)) {
$config = parse_ini_file($_SERVER['DOCUMENT_ROOT'] . "/cfi/config.ini");
$connection = mysqli_connect('localhost',$config['username'],$config['password'],$config['dbname']);
}
if($connection === false) {
return mysqli_connect_error();
}
return $connection;
}
我这样运行:
$connection = db_connect();
然后我尝试像这样运行一个INSERT:
if (mysqli_query($connection, "INSERT INTO pending ('aw_id','in_stock') VALUES ('1','yes')")) {
echo "success";
} else {
echo "fail";
}
但它总是失败......我错过了什么?
我不确定它是否有帮助,但$ connection的var_dump是:
object(mysqli)#1 (19) { ["affected_rows"]=> int(0) ["client_info"]=> string(79) "mysqlnd 5.0.11-dev - 20120503 - $Id: bf9ad53b11c9a57efdb1057292d73b928b8c5c77 $" ["client_version"]=> int(50011) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["field_count"]=> int(0) ["host_info"]=> string(25) "Localhost via UNIX socket" ["info"]=> NULL ["insert_id"]=> int(0) ["server_info"]=> string(6) "5.6.23" ["server_version"]=> int(50623) ["stat"]=> string(147) "Uptime: 684382 Threads: 3 Questions: 5532897 Slow queries: 14 Opens: 287168 Flush tables: 37 Open tables: 1024 Queries per second avg: 8.084" ["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(184926) ["warning_count"]=> int(0) }
GRRRR !!
答案 0 :(得分:3)
INSERT INTO pending ('aw_id','in_stock') VALUES ('1','yes')
替换为
INSERT INTO pending (aw_id,in_stock) VALUES ('1','yes')