[PHP-DB] UPDATE IF
I have a table in a mysql db that has 3 columns that I want to insert (update) data if the rowcolumn is empty (IS NULL). However I want to start at the first column, if this column is not null, then move to insert the data into column 2, if that is empty, then insert data into column 3. I have been looking over the manual and boards but am not finding a solution. Can anyone point me in the right direction. -- Gary __ Information from ESET Smart Security, version of virus signature database 5952 (20110314) __ The message was checked by ESET Smart Security. http://www.eset.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] UPDATE IF
On 14 March 2011 15:42, Gary gp...@paulgdesigns.com wrote: I have a table in a mysql db that has 3 columns that I want to insert (update) data if the rowcolumn is empty (IS NULL). However I want to start at the first column, if this column is not null, then move to insert the data into column 2, if that is empty, then insert data into column 3. I have been looking over the manual and boards but am not finding a solution. Can anyone point me in the right direction. -- Gary __ Information from ESET Smart Security, version of virus signature database 5952 (20110314) __ The message was checked by ESET Smart Security. http://www.eset.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php You would have to code it. I'm not a mysql guru (MSSQL is what I use), but ... UPDATE Table SET Column3 = CASE WHEN Column3 IS NULL AND Column2 IS NOT NULL AND Column1 IS NOT NULL THEN Value ELSE Column3 END, Column2 = CASE WHEN Column2 IS NULL AND Column1 IS NOT NULL THEN Value ELSE Column2 END, Column1 = CASE WHEN Column1 IS NULL THEN Value ELSE Column1 END WHERE IDColumn = ID something like that? -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] MySQL Unbuffered Query Behavior Change
I was previously on PHP 5.1.6 and was using the following code: $dbr = mysql_unbuffered_query($query, $this-con); while($row = mysql_fetch_array($dbr, $assoc ? MYSQL_ASSOC : MYSQL_NUM)) $this-result[] = $row; $this-rows = mysql_num_rows($dbr); It worked properly. The documentation at http://www.php.net/manual/en/function.mysql-num-rows.php indicates that mysql_num_rows won't return the correct result on unbuffered queries until all of the rows had been fetched, but since I was looping through and fetching all rows with mysql_fetch_array, it worked properly and wasn't a problem. I've upgraded to PHP 5.3.5 and now mysql_num_rows always returns 0. I am fetching all rows before calling mysql_num_rows, just like the documentation says to do, so mysql_num_rows should return the correct result. Why is it not? Is the documentation wrong now (should it have been updated to say that mysql_num_rows now NEVER works with unbuffered queries instead of saying you have to fetch all rows first)? Is there a bug in PHP? Or am I doing something wrong and it just coincidentally worked before? Thanks, Nick