我在这里遇到了一个奇怪的问题。我一直在努力找出几个小时的错误。我有一个函数应该更新我的数据库中的表并将“date_vente”(英语的date_sold)设置为NOW()。该查询非常简单,但它保持报告1个匹配的行,0更改。
问题是,应该更改数据。如果我手动运行查询,它工作正常,如果我从PHP应用程序运行它,它失败...
//Marque le panier comme vendu
$sqlstring = "UPDATE ".$prefix_tables_panier."paniers SET date_vente = NOW() WHERE no_panier = ".$data_panier["no_panier"];
$result = mysql_query($sqlstring, $conn_panier);
echo $sqlstring.'<br>';
echo mysql_affected_rows($conn_panier); echo '<br>';
echo mysql_error($conn_panier); echo '<br>';
echo mysql_errno($conn_panier); echo '<br>';
var_dump($conn_panier); echo '<br>';
var_dump(mysql_error($conn_panier)); echo '<br>';
var_dump(mysql_info($conn_panier)); echo '<br>';
var_dump(mysql_stat($conn_panier)); echo '<br>';
输出
UPDATE panier_paniers SET date_vente = NOW() WHERE no_panier = 840
0
0
resource(5) of type (mysql link)
string(0) ""
string(40) "Rows matched: 1 Changed: 0 Warnings: 0"
string(145) "Uptime: 1640423 Threads: 5 Questions: 39673341 Slow queries: 0 Opens: 1132 Flush tables: 1 Open tables: 235 Queries per second avg: 24.185" 7
问题是它应该将NOW值写入包含篮子的表中,但事实并非如此。不,这不是因为错误的连接,在之前的函数中使用相同的连接id(var_dumped it),调用它并且它们都具有相同的id,连接仍然是打开的并且值为“0000” -00-00 00:00:00“在我想要更新的栏目中......
任何人都可以给我一些提示吗?
由于
更新
UPDATE panier_paniers SET date_vente = NOW() WHERE no_panier = 840
0
0
resource(5) of type (mysql link)
string(0) ""
string(40) "Rows matched: 1 Changed: 0 Warnings: 0"
string(145) "Uptime: 1641927 Threads: 5 Questions: 39681590 Slow queries: 0 Opens: 1132 Flush tables: 1 Open tables: 235 Queries per second avg: 24.168"
UPDATE panier_paniers SET date_vente = "2011-12-28 12:00:17" WHERE no_panier = 840
1
0
resource(5) of type (mysql link)
string(0) ""
string(40) "Rows matched: 1 Changed: 1 Warnings: 0"
string(145) "Uptime: 1641927 Threads: 5 Questions: 39681591 Slow queries: 0 Opens: 1132 Flush tables: 1 Open tables: 235 Queries per second avg: 24.168"
go
这很奇怪,很奇怪!
更新#2
CREATE TABLE IF NOT EXISTS `panier_paniers` (
`no_panier` bigint(20) unsigned NOT NULL auto_increment,
`client_prenom` varchar(100) NOT NULL default '',
`client_nom` varchar(100) NOT NULL default '',
`client_entreprise` varchar(150) default NULL,
`client_adresse` varchar(150) NOT NULL default '',
`client_ville` varchar(150) NOT NULL default '',
`client_province_etat` char(2) default NULL,
`client_pays` char(2) NOT NULL default '',
`client_code_postal_zip` varchar(15) NOT NULL default '',
`client_telephone` varchar(20) NOT NULL default '',
`client_type_telephone` enum('domicile','travail','cellulaire') NOT NULL default 'domicile',
`client_telecopieur` varchar(20) default NULL,
`client_courriel` varchar(150) NOT NULL default '',
`client_mailinglist_from` datetime default NULL,
`client_langue` char(2) NOT NULL default '',
`client_no_client` bigint(20) unsigned default NULL,
`expedition_mode` varchar(20) NOT NULL default '',
`expedition_no_livraison` bigint(20) unsigned default NULL,
`expedition_produit` varchar(100) default NULL,
`expedition_produit_no_compte` varchar(100) default NULL,
`expedition_frais_livraison` decimal(10,2) NOT NULL default '0.00',
`expedition_frais_manut` decimal(10,2) NOT NULL default '0.00',
`expedition_assurance` char(1) NOT NULL default 'X',
`expedition_signature` char(1) NOT NULL default 'X',
`expedition_conf_livraison` char(1) NOT NULL default 'X',
`expedition_emballage` text,
`expedition_no_suivi` varchar(100) default NULL,
`expedition_prenom` varchar(100) default NULL,
`expedition_nom` varchar(100) default NULL,
`expedition_entreprise` varchar(150) default NULL,
`expedition_adresse` varchar(150) default NULL,
`expedition_ville` varchar(150) default NULL,
`expedition_province_etat` char(2) default NULL,
`expedition_pays` char(2) default NULL,
`expedition_code_postal_zip` varchar(15) default NULL,
`expedition_telephone` varchar(20) default NULL,
`expedition_type_telephone` enum('domicile','travail','cellulaire') NOT NULL default 'domicile',
`expedition_exporte_ups_connect` char(1) NOT NULL default '',
`expedition_mis_a_jour_ups_connect` char(1) NOT NULL default '',
`paiement_mode` varchar(20) NOT NULL default '',
`paiement_no_paiement` bigint(20) unsigned default NULL,
`paiement_numero_taxe_fed` bigint(20) unsigned NOT NULL default '0',
`paiement_numero_taxe_prov` bigint(20) unsigned NOT NULL default '0',
`paiement_numeros_taxes_speciales` varchar(255) NOT NULL,
`paiement_numero_po` varchar(20) default NULL,
`paiement_numero_bon` varchar(20) default NULL,
`paiement_cc_pa_trnid` varchar(10) default NULL,
`paiement_cc_pa_montant` decimal(10,2) NOT NULL default '0.00',
`paiement_cc_capture` text,
`paiement_desjardins_TxID` varchar(25) default NULL,
`paiement_desjardins_date_envoi` datetime NOT NULL default '0000-00-00 00:00:00',
`date_creation` datetime NOT NULL default '0000-00-00 00:00:00',
`ip_creation` varchar(15) NOT NULL default '',
`host_creation` varchar(255) default NULL,
`date_vente` datetime NOT NULL default '0000-00-00 00:00:00',
`date_annulee` datetime NOT NULL default '0000-00-00 00:00:00',
`date_completee` datetime NOT NULL default '0000-00-00 00:00:00',
`date_inventaire` datetime NOT NULL default '0000-00-00 00:00:00',
`date_acceptation` datetime NOT NULL default '0000-00-00 00:00:00',
`note` text,
`note_client` text,
`no_utilisateur` bigint(20) unsigned default NULL,
PRIMARY KEY (`no_panier`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=841 ;
更新#3
好的,看看这个怪异的东西:
//Marque le panier comme vendu
$sqlstring = 'UPDATE panier_paniers SET date_vente = NOW() WHERE no_panier = '.$data_panier["no_panier"];
$result = mysql_query($sqlstring, $conn_panier);
echo $sqlstring.'<br>';
echo mysql_affected_rows($conn_panier); echo '<br>';
echo mysql_error($conn_panier); echo '<br>';
echo mysql_errno($conn_panier); echo '<br>';
var_dump($conn_panier); echo '<br>';
var_dump(mysql_error($conn_panier)); echo '<br>';
var_dump(mysql_info($conn_panier)); echo '<br>';
var_dump(mysql_stat($conn_panier)); echo '<br>';
$sqlstring='UPDATE panier_paniers SET date_vente = "2011-12-28 10:09:12" WHERE no_panier = '.$data_panier["no_panier"];
mysql_query($sqlstring, $conn_panier);
echo $sqlstring.'<br>';
echo mysql_affected_rows($conn_panier); echo '<br>';
echo mysql_error($conn_panier); echo '<br>';
echo mysql_errno($conn_panier); echo '<br>';
var_dump($conn_panier); echo '<br>';
var_dump(mysql_error($conn_panier)); echo '<br>';
var_dump(mysql_info($conn_panier)); echo '<br>';
var_dump(mysql_stat($conn_panier)); echo '<br>';
如您所见,两者都应该有效,第一个不会更新任何内容,第二个会更新行。切换并再次测试:
$sqlstring='UPDATE panier_paniers SET date_vente = "2011-12-28 10:09:12" WHERE no_panier = '.$data_panier["no_panier"];
mysql_query($sqlstring, $conn_panier);
echo $sqlstring.'<br>';
echo mysql_affected_rows($conn_panier); echo '<br>';
echo mysql_error($conn_panier); echo '<br>';
echo mysql_errno($conn_panier); echo '<br>';
var_dump($conn_panier); echo '<br>';
var_dump(mysql_error($conn_panier)); echo '<br>';
var_dump(mysql_info($conn_panier)); echo '<br>';
var_dump(mysql_stat($conn_panier)); echo '<br>';
//Marque le panier comme vendu
$sqlstring = 'UPDATE panier_paniers SET date_vente = NOW() WHERE no_panier = '.$data_panier["no_panier"];
$result = mysql_query($sqlstring, $conn_panier);
echo $sqlstring.'<br>';
echo mysql_affected_rows($conn_panier); echo '<br>';
echo mysql_error($conn_panier); echo '<br>';
echo mysql_errno($conn_panier); echo '<br>';
var_dump($conn_panier); echo '<br>';
var_dump(mysql_error($conn_panier)); echo '<br>';
var_dump(mysql_info($conn_panier)); echo '<br>';
var_dump(mysql_stat($conn_panier)); echo '<br>';
结果:
UPDATE panier_paniers SET date_vente = "2011-12-28 10:09:12" WHERE no_panier = 840
1
0
resource(5) of type (mysql link)
string(0) ""
string(40) "Rows matched: 1 Changed: 1 Warnings: 0"
string(145) "Uptime: 1643141 Threads: 5 Questions: 39713580 Slow queries: 0 Opens: 1286 Flush tables: 1 Open tables: 219 Queries per second avg: 24.169"
UPDATE panier_paniers SET date_vente = NOW() WHERE no_panier = 840
1
0
resource(5) of type (mysql link)
string(0) ""
string(40) "Rows matched: 1 Changed: 1 Warnings: 0"
string(145) "Uptime: 1643141 Threads: 5 Questions: 39713581 Slow queries: 0 Opens: 1286 Flush tables: 1 Open tables: 219 Queries per second avg: 24.169"
现在两个更新都有效...我尝试了验证,修复和优化,看看它是不是腐败问题,没有任何改变......
答案 0 :(得分:1)
所以问题毕竟是逻辑和错误编码实践的问题。问题来自以前的程序员,他们喜欢在怪异的地方没有结构和地方代码。我发现错误超出了我们所寻找的范围。
我可能会说,如果你遇到这样的错误,请查找代码中的缺陷,这些缺陷可能会在当前SEEMS失败之前执行相同的查询。这样可以省去寻找与手头问题无关的解决方案的麻烦。