我遇到了简单的插入数据到表的问题。
我收到了这段代码:
// Create connection
$dbConnection = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($dbConnection->connect_error) {
die("Connection failed: " . $dbConnection->connect_error);
}
//Check if keyword exist
$keyword = "test";
$stmt = $dbConnection->prepare('SELECT keyword FROM keywords WHERE keyword=?');
$stmt->bind_param('s', $keyword);
$stmt->execute();
echo 'good';
$rowCount = $stmt->num_rows;
if($rowCount <= 0) {
echo 'rekord nie istnieje';
//if not add new one
$keyword = "test";
$stmt = $dbConnection->prepare('INSERT INTO keywords (keyword) VALUES (?)');
$stmt->bind_param('s', $keyword);
$stmt->execute();
}
SELECT查询工作正常,num_row计数也一样,但是插入到数据库而不是我得到错误:
PHP Fatal error: Call to a member function bind_param() on boolean in
是关于插入查询的行$stmt->bind_param('s', $keyword);
。
请一些建议,表得到id(A_I)(INT 11)和关键字(VARCHAR 100)。