Hi all,

Since quite some time I use generic functions in my sites, to reduce the
time needed to code a new site.
My last project may, by choice of client, either run on a MySQL or a
PostgreSQL powered site, so I modified the function a bit. After including a
global $dbType in the site configuration and making a switch to handle the
type of database it now looks like given below:

        function update_data($Query, $Table='', $Field='') {
                global $dbHostname, $dbUsername, $dbPassword, $dbDatabase, 
$dbType,
$dbPort;
                $Cnx = connect($dbHostname, $dbUsername, $dbPassword, 
$dbDatabase,
$dbType, $dbPort);
                if ($Cnx) {
                        //       echo "$Query<br />"; // uncomment to debug
                        switch (strtolower($dbType)) {
                                case 'postgresql':
                                        $Result = pg_query($Cnx, $Query);
                                        $Results["RowsAffected"] = 
pg_affected_rows($Result);
                                        pg_close($Cnx);
                                        break;
                                case 'mysql':
                                default:
                                        $Result = mysql_query($Query, $Cnx);
                                        $Results["RowsAffected"] = 
mysql_affected_rows($Cnx);
                                        mysql_close($Cnx);
                                        break;
                        }
                        $Results["PrimaryKeyValue"] = -1;
                }
                return $Results;
        }

Now I built a site, using Postgres and all was working nice. But the client
arranged some space on a MySQL driven server and hey hey: trouble.
The above given function fails to do its work on MySQL.
Uncommenting the 'echo' line I get the query echoed to screen and copy/paste
in a tool like phpMyAdmin shows the query being executed perfectly.
For what it's worth, the query looks as follows:
BEGIN;
UPDATE preferencias_empresas SET em_id=32 WHERE su_id=52 AND em_id=27;
UPDATE preferencias_empresas SET em_id=33 WHERE su_id=52 AND em_id=28;
UPDATE preferencias_empresas SET em_id=34 WHERE su_id=52 AND em_id=31;
UPDATE preferencias_empresas SET em_id=27 WHERE su_id=52 AND em_id=32;
UPDATE preferencias_empresas SET em_id=28 WHERE su_id=52 AND em_id=33;
UPDATE preferencias_empresas SET em_id=31 WHERE su_id=52 AND em_id=34;
COMMIT;

After every semicolon a "\r\n" is placed to facilitate screenreading,
obviously Postgres is not bothered by them, and actually neither is MySQL,
as removing them doesn't result in the query (the abovementioned set of 8
statements) being executed.

Mind you, if I set $dbType to 'PostgreSQL', the function works perfectly.
Would the problem be with the 'begin;...;commit;' construction? But MySQL
has no problem with that and the query runs without any messages or notices
in phpMyAdmin, but also in MySQL-front.
However, the only queries that are not executed are exactly those performed
in such blocks...

Anybody able to give me a hint on what's going on?

Marc



Community email addresses:
  Post message: [email protected]
  Subscribe:    [EMAIL PROTECTED]
  Unsubscribe:  [EMAIL PROTECTED]
  List owner:   [EMAIL PROTECTED]

Shortcut URL to this page:
  http://groups.yahoo.com/group/php-list 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-list/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to