Premetto che so abbastanza poco di php ed mysql, giusto giusto le basi.
Detto questo vi illustro il mio problema...
Io ho un database online (con più tabelle) in cui io voglio inserire dei record, questi record dovranno essere inseriti in più tabelle.
Ho provato con il seguente codice:
Codice: Seleziona tutto
try {
// First of all, let's begin a transaction
$db->beginTransaction();
// A set of queries; if one fails, an exception should be thrown
$db->query("'INSERT INTO tb_Items(Name,Address,Phone,Website,Mail,Facebook,Latitude,Longitude)
VALUES ('ProvaNome','ProvaIndirizzo','ProvaNumero','ProvaSito','ProvaMail','ProvaFacebook','ProvaLatitude','ProvaLongitude');'
SET @ItemID = LAST_INSERT_ID();");
$db->query("INSERT INTO tb_ItemResources(ResourcePath,ResourceName,ResourceType,ResourceVersion) VALUES('ResourcePath1','ResourceName1','jpg',1);
SET @ImageID = LAST_INSERT_ID();
INSERT INTO tb_ResourcesForItem(Item_ID,ItemResource_ID) VALUES (@ItemID, @ImageID);");
$db->query("INSERT INTO tb_ItemResources(ResourcePath,ResourceName,ResourceType,ResourceVersion) VALUES('ResourcePath2','ResourceName2','jpg',1);
SET @ImageID = LAST_INSERT_ID();
INSERT INTO tb_ResourcesForItem(Item_ID,ItemResource_ID) VALUES (@ItemID, @ImageID);");
$db->query("INSERT INTO tb_ItemDescriptions(Language_ID,Item_ID,ItemName,ItemDescription)VALUES(1, @ItemID,'ProvaNome','descrizioneITA');");
$db->query("INSERT INTO tb_ItemDescriptions(Language_ID,Item_ID,ItemName,ItemDescription)VALUES(2, @ItemID,'ProvaName','descrizioneENG');");
$db->query("INSERT INTO tb_ItemCategory(Item_ID,Category_ID,ItemOrder)VALUES(@ItemID,1,0);");
$db->query("INSERT INTO tb_ItemCategory(Item_ID,Category_ID,ItemOrder)VALUES(@ItemID,2,1);");
// If we arrive here, it means that no exception was thrown
// i.e. no query has failed, and we can commit the transaction
$db->commit();
} catch (Exception $e) {
// An exception has been thrown
// We must rollback the transaction
$db->rollback();
echo "failed";
}
Codice: Seleziona tutto
$db->beginTransaction();
Fatal error: Call to a member function beginTransaction() on a non-object in /web/htdocs/www.thebubblecompany.com/home/wordpress/comuni/test.php on line 19
Ho provato ad informarmi per conto mio ma tutti usano il PDO che io non conosco e che , se posso, eviterei di usare.
Avete suggerimenti?
Grazie mille a tutti!