我有以下php / sql请求:
它已成功连接并成功运行更新(返回成功消息),但在phpMyAdmin中,数据库尚未更新。我做错了什么?
<?php
{ // Connect and Test MySQL and specific DB (return $dbSuccess = T/F)
$hostname = "localhost";
$username = "root";
$password = "";
$databaseName = "db_test";
$dbConnected = mysql_connect($hostname, $username, $password);
$dbSelected = mysql_select_db($databaseName,$dbConnected);
$dbSuccess = true;
if ($dbConnected) {
if (!$dbSelected) {
echo "DB connection FAILED<br /><br />";
$dbSuccess = false;
}
} else {
echo "MySQL connection FAILED<br /><br />";
$dbSuccess = false;
}
}
// Execute code ONLY if connections were successful
if ($dbSuccess) {
// SQL to change country value from UK to United Kingdom
$company_SQLupdate = "UPDATE tCompany SET ";
$company_SQLupdate .= "COUNTRY = 'United Kingdom' ";
$company_SQLupdate .= "WHERE COUNTRY = 'UK' ";
if (mysql_query($company_SQLupdate)) {
echo "UPDATE tCompany.COUNTRY - SUCCESSFUL.<br /><br />";
} else {
echo "UPDATE tCompany.COUNTRY - FAILED.<br /><br />";
}
}
&GT;
答案 0 :(得分:3)
您确定数据库中有country = 'UK'
的记录吗?
您可以更改显示完整查询的成功消息,然后尝试在phpMyAdmin中执行该语句,看看是否出现了修改。
答案 1 :(得分:1)
您是否绝对确定列名是大写字母?
我说的是“国家”。
当然不是“国家”?
答案 2 :(得分:1)
变化:
if (mysql_query($company_SQLupdate)) {
echo "UPDATE tCompany.COUNTRY - SUCCESSFUL.<br /><br />";
} else {
echo "UPDATE tCompany.COUNTRY - FAILED.<br /><br />";
}
到
if (mysql_query($company_SQLupdate)) {
echo "UPDATE tCompany.COUNTRY - SUCCESSFUL.<br /><br />";
} else {
var_dump(mysql_error());
}
查看错误
编辑1
select *
from tCompany
WHERE COUNTRY = 'UK'
查看是否有COUNTRY = 'UK'