Re: mixing and matching mysql mssql whileloop within an if case

2012-05-04 Thread Rik Wasmus
 I could suggest a number of ways around the if/else construct, such as
 creating a subclass for the various servers with a uniform interface
 and hiding the differences inside the class.

This, but I'd prefer using one of the already available abstractions for PHP:

- PDO: http://www.php.net/PDO
- DB: http://pear.php.net/package/DB
- MDB2: http://pear.php.net/package/MDB2
- DBAL: http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/

... let's not re-re-reinvent the wheel ;)

I would also highly recommend NOT using the mysql extension anymore in PHP for 
new projects. Use mysqli (mysql Improved) or PDO_MySQL. Also, learn to love 
prepared statements.
-- 
Rik Wasmus

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql



RE: mixing and matching mysql mssql whileloop within an if case

2012-05-03 Thread Rick James
opinion
Cross-platform coding is folly.  There are too many differences (LIMIT, ROWNUM, 
SEQUENCE vs AUTO_INCREMENT, ...) that you either stumble over, or end up 
special casing, or you simply code to the least common denominator, thereby 
getting poor performance on all platforms.
/opinion

 -Original Message-
 From: Haluk Karamete [mailto:halukkaram...@gmail.com]
 Sent: Thursday, May 03, 2012 10:21 AM
 To: MySQL
 Subject: mixing and matching mysql  mssql whileloop within an if case
 
 Please take a look at the following code and tell me if there is a way
 around it.
 
 if ($current_server_is_mysql):
 while ($row = mysql_fetch_assoc($RS)) {
 else:
 while( $row = sqlsrv_fetch_array( $RS, SQLSRV_FETCH_ASSOC)){
 endif:
 Depending on the server I'm working with, I'd like to compile my
 records into the $RS recordset the proper/native way. If I can get pass
 this part, the rest should be all right cause both mysql and mssql $row
 can be tapped into the same way. For example, $row['fieldname'] will
 give me the field value whether the row was a mysql or mssql resource.
 So it all boils down to the above snippet failing.
 
 The error I get points to the else: part in the above snippet.
 
 Parse error: syntax error, unexpected T_ELSE in
 D:\Hosting\5291100\html\blueprint\pages\populate_migration_table.php
 on line 415
 I can understand why I am getting this error.
 
 But, I'm hoping you guys can offer a work-around it without me
 resorting to duplicate the entire while loop she-bang.
 
 --
 MySQL General Mailing List
 For list archives: http://lists.mysql.com/mysql
 To unsubscribe:http://lists.mysql.com/mysql


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql



Re: mixing and matching mysql mssql whileloop within an if case

2012-05-03 Thread Brown, Charles


Sent from my iPhone

On May 3, 2012, at 1:02 PM, Haluk Karamete halukkaram...@gmail.com wrote:

 Please take a look at the following code and tell me if there is a way
 around it.
 
 if ($current_server_is_mysql):
while ($row = mysql_fetch_assoc($RS)) {
 else:
while( $row = sqlsrv_fetch_array( $RS, SQLSRV_FETCH_ASSOC)){
 endif:
 Depending on the server I'm working with, I'd like to compile my
 records into the $RS recordset the proper/native way. If I can get
 pass this part, the rest should be all right cause both mysql and
 mssql $row can be tapped into the same way. For example,
 $row['fieldname'] will give me the field value whether the row was a
 mysql or mssql resource. So it all boils down to the above snippet
 failing.
 
 The error I get points to the else: part in the above snippet.
 
 Parse error: syntax error, unexpected T_ELSE in
 D:\Hosting\5291100\html\blueprint\pages\populate_migration_table.php
 on line 415
 I can understand why I am getting this error.
 
 But, I'm hoping you guys can offer a work-around it without me
 resorting to duplicate the entire while loop she-bang.
 
 -- 
 MySQL General Mailing List
 For list archives: http://lists.mysql.com/mysql
 To unsubscribe:http://lists.mysql.com/mysql
 

This message is intended only for the use of the Addressee and
may contain information that is PRIVILEGED and CONFIDENTIAL.

If you are not the intended recipient, you are hereby notified
that any dissemination of this communication is strictly prohibited.

If you have received this communication in error, please erase
all copies of the message and its attachments and notify us
immediately.

Thank you.


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql



Re: mixing and matching mysql mssql whileloop within an if case

2012-05-03 Thread Baron Schwartz
Haluk,

I could suggest a number of ways around the if/else construct, such as
creating a subclass for the various servers with a uniform interface
and hiding the differences inside the class. The actual error that you
showed is much simpler, however: you are mixing curly-brace style with
what I like to call visual basic style of PHP. You have an opening
curly-brace without a closing one (and an empty while-loop to boot).
You can use either-or style, but you can't mix them and leave unclosed
braces as you've done below :-)

On Thu, May 3, 2012 at 1:20 PM, Haluk Karamete halukkaram...@gmail.com wrote:
 Please take a look at the following code and tell me if there is a way
 around it.

 if ($current_server_is_mysql):
    while ($row = mysql_fetch_assoc($RS)) {
 else:
    while( $row = sqlsrv_fetch_array( $RS, SQLSRV_FETCH_ASSOC)){
 endif:
 Depending on the server I'm working with, I'd like to compile my
 records into the $RS recordset the proper/native way. If I can get
 pass this part, the rest should be all right cause both mysql and
 mssql $row can be tapped into the same way. For example,
 $row['fieldname'] will give me the field value whether the row was a
 mysql or mssql resource. So it all boils down to the above snippet
 failing.

 The error I get points to the else: part in the above snippet.

 Parse error: syntax error, unexpected T_ELSE in
 D:\Hosting\5291100\html\blueprint\pages\populate_migration_table.php
 on line 415
 I can understand why I am getting this error.

 But, I'm hoping you guys can offer a work-around it without me
 resorting to duplicate the entire while loop she-bang.

 --
 MySQL General Mailing List
 For list archives: http://lists.mysql.com/mysql
 To unsubscribe:    http://lists.mysql.com/mysql




-- 
Baron Schwartz
Win free MySQL conference tickets! http://goo.gl/mvZ4W

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql



Re: mixing and matching mysql mssql whileloop within an if case

2012-05-03 Thread Alex Schaft

  
  
I suppose an easier way is to have a getrow function, Something like

while ($row = getrow($RS) {
  .
  .
  .
  }
  
  function getrow($RS)
  
  {
  if ($current_server_is_mysql)
  {
   return mysql_fetch_assoc($RS);
 }
 else
 { 
  return sqlsrv_fetch_array( $RS, SQLSRV_FETCH_ASSOC);
 }
} 



On 2012/05/03 19:20, Haluk Karamete wrote:

  Please take a look at the following code and tell me if there is a way
around it.

if ($current_server_is_mysql):
while ($row = mysql_fetch_assoc($RS)) {
else:
while( $row = sqlsrv_fetch_array( $RS, SQLSRV_FETCH_ASSOC)){
endif:
Depending on the server I'm working with, I'd like to compile my
records into the $RS recordset the proper/native way. If I can get
pass this part, the rest should be all right cause both mysql and
mssql $row can be tapped into the same way. For example,
$row['fieldname'] will give me the field value whether the row was a
mysql or mssql resource. So it all boils down to the above snippet
failing.

The error I get points to the else: part in the above snippet.

Parse error: syntax error, unexpected T_ELSE in
D:\Hosting\5291100\html\blueprint\pages\populate_migration_table.php
on line 415
I can understand why I am getting this error.

But, I'm hoping you guys can offer a work-around it without me
resorting to duplicate the entire while loop she-bang.





--