Re: mysql question #2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Feb 10, 2008 1:12 PM, nihilism machine <nihilismmachine@xxxxxxxxx> wrote:

> Ok, I read the php.net info. so with this function though:
>
>        public function select_one($sql) {
>                $this->last_query = $sql;
>                $r = mysql_query($sql);
>                if (!$r) {
>                        $this->last_error = mysql_error();
>                        return false;
>                }
>                if (mysql_num_rows($r) != 1) {
>                        return false;
>                }
>                $ret = mysql_result($r, 0);
>                mysql_free_result($r);
>                if ($this->auto_slashes) {
>                        return stripslashes($ret);
>                } else {
>                        return $ret;
>                }
>        }


as the function stands you wont be able to.  you can alter it
though:

       public function select_one($sql, $columnName) {
               $this->last_query = $sql;
               $r = mysql_query($sql);
               $ret = false;                  ///  default return value is
false
               if (!$r) {
                       $this->last_error = mysql_error();
                       return false;
               }
               if (mysql_num_rows($r) != 1) {
                       return false;
               }
               $result = mysql_fetch_assoc($r);
               if(isset($result[$columnName])) {
                  $ret = $result[$columnName]);
               }
               mysql_free_result($r);
               if ($this->auto_slashes) {
                       return stripslashes($ret);
               } else {
                       return $ret;
               }
       }

note: i just hacked that together in my mail client :)

-nathan

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux