Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-20-2013, 08:31 AM   PM User | #1
danh2
New to the CF scene

 
Join Date: Feb 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
danh2 is an unknown quantity at this point
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.
danh2 is offline   Reply With Quote
Old 02-20-2013, 03:33 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:24 AM.


Advertisement
Log in to turn off these ads.