Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Retrieve value from database (got the data with extra spaces)

    Hello i am having some issues,

    when i try to pull some values from my db i get them with extra spaces like "DATA "

    the code i am using for it is
    Code:
    		function doQuery($query)
    		{
    			$parameters = func_get_args();
    			array_shift($parameters);
    
    			$this->queryResult = $this->_doQuery($query, $parameters);
    			if ($this->queryResult == -1)
    				$this->getError();
    			else
    				parent::Success();
    
    
    			return $this->queryResult;
    		}
    		
    		function _doQuery($query, $parameters)
    		{
    			if (!parent::isConnected())
    			{
    				if (!$this->doConnect())
    					return -1;
    			}
    			
    			if ($this->result)
    				@odbc_free_result($this->result);
    			
    			parent::Query();
    			if (sizeof($parameters) > 0)
    			{
    				$this->result = @odbc_prepare($this->conn, $query);
    				if (!$this->result)
    					return -1;
    					
    				$result = @odbc_execute($this->result, $parameters);
    				if (!$result)
    					return -1;
    			}
    			else
    			{
    				$this->result = @odbc_exec($this->conn, $query);
    				if (!$this->result)
    					return -1;
    			}
    			return @odbc_num_rows($this->result);
    		}
    
    
    		function doRead($fetch = DB_FETCH_ARRAY)
    		{
    			if ($fetch == DB_FETCH_ROW)
    			{
    				return @odbc_fetch_row($this->result);
    			}
    			else
    			{
    				return @odbc_fetch_array($this->result);
    			}
    		}
    
    $db->doQuery('SELECT strAccountID, strCharID, strClientIP, nServerNo FROM CURRENTUSER WHERE strAccountID = ? AND strClientIP = ?', $_POST[CPD_ID], $this->getRemoteIP());
    				
    				$row = $db->doRead();
    				if (strcmp($_POST[CPD_ID], $row['strAccountID']) !== 0)
    
    now the issue is with getting "$row['strAccountID']"
    
    the value that is it giving it "database            "
    and then it is not matching.
    
    any idie what it is like that?
    
    thanks.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    I don't use ODBC, but I can't see the library itself doing this.
    Are you using a varchar type field for your database, or is it a char type field? That strAccountID for example appears to have 20 chars in total, which would be consistent with a char(20) datatype. MySQL for example would right pad the string to the size required to fit in the char field. Instead we'd use varchar to allow up to but not pad the size of the field in question. Not sure what db you are using though, so I can't really help on that.
    PHP wise you can simply rtrim() the data to remove the excess padding.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •