PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > INSERT works in phpMyAdmin but not in PHP
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
INSERT works in phpMyAdmin but not in PHP

Réponse
 
LinkBack Outils de la discussion
Vieux 26/09/2007, 20h31   #1
billbois at gmail dot com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut INSERT works in phpMyAdmin but not in PHP

I've got several SQL statements that run in succession. If I paste
them into a phpMyAdmin SQL window, they run quickly and correctly.
However, when I use them in a .PHP script, they run without error but
one fails to do it's job.

My PHP code is:

$sql = "TRUNCATE TABLE TransactionRptTrans;";
$dummy = $this->db->r_query($sql);

$sql = "TRUNCATE TABLE TransactionRptDetail;";
$dummy = $this->db->r_query($sql);

$sql = "INSERT INTO TransactionRptTrans(TransactionID, DomainID,
DomainName, Amount, ShipAmount, ShipSurcharge) SELECT t.TransactionID,
t.DomainID, d.DomainName, t.Amount, t.ShipAmount, d.ShipSurcharge FROM
Transaction t LEFT OUTER JOIN Domain d ON t.DomainID=d.DomainID WHERE
DATE_FORMAT(TransactionDate, '%Y-%m-%d') BETWEEN '".$from_date."' AND
'".$to_date."';";
$dummy = $this->db->r_query($sql);

$ssql = "INSERT INTO TransactionRptDetail(TransactionID, DomainID,
TransactionDetailID, ProductCode, Price, Qty, charge_fee,
merch_amount, fc_amount) SELECT t.TransactionID, t.DomainID,
td.TransactionID, td.ProductCode, td.Price, td.Qty, if(p.ReqShipping=1
AND p.FreeShipping=0, 1, 0) AS charge_fee, 0 AS merch_amount, 0 AS
fc_amount FROM TransactionRptTrans t INNER JOIN TransactionDetail td
ON t.TransactionID = td.TransactionID LEFT JOIN Product p ON
td.ProductID=p.ProductID;";
$dummy = $this->db->r_query($sql);

There's more after this but the last INSERT statement doesn't insert
anything, and no records in that table, it doesn't matter what happens
afterward.

I tried putting BEGIN TRANSACTION's and COMMIT's around each statement
and that made no difference. I also checked for errors and there
weren't any.

Can anyone see why the last INSERT doesn't insert?

Thanks,
Bill

  Réponse avec citation
Vieux 26/09/2007, 21h25   #2
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: INSERT works in phpMyAdmin but not in PHP

billbois at gmail dot com wrote:
> I've got several SQL statements that run in succession. If I paste
> them into a phpMyAdmin SQL window, they run quickly and correctly.
> However, when I use them in a .PHP script, they run without error but
> one fails to do it's job.
>
> My PHP code is:
>
> $sql = "TRUNCATE TABLE TransactionRptTrans;";
> $dummy = $this->db->r_query($sql);
>
> $sql = "TRUNCATE TABLE TransactionRptDetail;";
> $dummy = $this->db->r_query($sql);
>
> $sql = "INSERT INTO TransactionRptTrans(TransactionID, DomainID,
> DomainName, Amount, ShipAmount, ShipSurcharge) SELECT t.TransactionID,
> t.DomainID, d.DomainName, t.Amount, t.ShipAmount, d.ShipSurcharge FROM
> Transaction t LEFT OUTER JOIN Domain d ON t.DomainID=d.DomainID WHERE
> DATE_FORMAT(TransactionDate, '%Y-%m-%d') BETWEEN '".$from_date."' AND
> '".$to_date."';";
> $dummy = $this->db->r_query($sql);
>
> $ssql = "INSERT INTO TransactionRptDetail(TransactionID, DomainID,
> TransactionDetailID, ProductCode, Price, Qty, charge_fee,
> merch_amount, fc_amount) SELECT t.TransactionID, t.DomainID,
> td.TransactionID, td.ProductCode, td.Price, td.Qty, if(p.ReqShipping=1
> AND p.FreeShipping=0, 1, 0) AS charge_fee, 0 AS merch_amount, 0 AS
> fc_amount FROM TransactionRptTrans t INNER JOIN TransactionDetail td
> ON t.TransactionID = td.TransactionID LEFT JOIN Product p ON
> td.ProductID=p.ProductID;";
> $dummy = $this->db->r_query($sql);
>
> There's more after this but the last INSERT statement doesn't insert
> anything, and no records in that table, it doesn't matter what happens
> afterward.
>
> I tried putting BEGIN TRANSACTION's and COMMIT's around each statement
> and that made no difference. I also checked for errors and there
> weren't any.
>
> Can anyone see why the last INSERT doesn't insert?
>
> Thanks,
> Bill
>


Check the result of your query for errors.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
  Réponse avec citation
Vieux 26/09/2007, 21h41   #3
billbois at gmail dot com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: INSERT works in phpMyAdmin but not in PHP

>
> Check the result of your query for errors.
>


Have done, and there aren't any. It's almost like the last query runs
before the previous one.

Thanks,
Bill

  Réponse avec citation
Vieux 27/09/2007, 00h37   #4
Rik Wasmus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: INSERT works in phpMyAdmin but not in PHP

On Wed, 26 Sep 2007 21:31:12 +0200, billbois at gmail dot com
<bbois@hotmail.com> wrote:

> I've got several SQL statements that run in succession. If I paste
> them into a phpMyAdmin SQL window, they run quickly and correctly.
> However, when I use them in a .PHP script, they run without error but
> one fails to do it's job.
>
> My PHP code is:
>
> $sql = "TRUNCATE TABLE TransactionRptTrans;";
> $dummy = $this->db->r_query($sql);
>
> $sql = "TRUNCATE TABLE TransactionRptDetail;";
> $dummy = $this->db->r_query($sql);
>
> $sql = "INSERT INTO TransactionRptTrans(TransactionID, DomainID,
> DomainName, Amount, ShipAmount, ShipSurcharge) SELECT t.TransactionID,
> t.DomainID, d.DomainName, t.Amount, t.ShipAmount, d.ShipSurcharge FROM
> Transaction t LEFT OUTER JOIN Domain d ON t.DomainID=d.DomainID WHERE
> DATE_FORMAT(TransactionDate, '%Y-%m-%d') BETWEEN '".$from_date."' AND
> '".$to_date."';";
> $dummy = $this->db->r_query($sql);
>
> $ssql = "INSERT INTO TransactionRptDetail(TransactionID, DomainID,
> TransactionDetailID, ProductCode, Price, Qty, charge_fee,
> merch_amount, fc_amount) SELECT t.TransactionID, t.DomainID,
> td.TransactionID, td.ProductCode, td.Price, td.Qty, if(p.ReqShipping=1
> AND p.FreeShipping=0, 1, 0) AS charge_fee, 0 AS merch_amount, 0 AS
> fc_amount FROM TransactionRptTrans t INNER JOIN TransactionDetail td
> ON t.TransactionID = td.TransactionID LEFT JOIN Product p ON
> td.ProductID=p.ProductID;";
> $dummy = $this->db->r_query($sql);


Hmmm, shouldn't that be:
$dummy = $this->db->r_query($ssql);

$ssql != $sql
--
Rik Wasmus
  Réponse avec citation
Vieux 27/09/2007, 01h11   #5
billbois at gmail dot com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: INSERT works in phpMyAdmin but not in PHP

On Sep 26, 6:37 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote:
> On Wed, 26 Sep 2007 21:31:12 +0200, billbois at gmail dot com
>
> > $dummy = $this->db->r_query($sql);

>
> Hmmm, shouldn't that be:
> $dummy = $this->db->r_query($ssql);
>


D'oh! OK, where's my dunce cap?

Thanks very much!
Bill

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h03.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10990 seconds with 13 queries