LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-11-2011, 09:52 AM   #1
jonniebigodes
Member
 
Registered: Feb 2006
Posts: 42

Rep: Reputation: 15
help with php function


hi.

i'm going nuts with a function that returns some values from a table, the code works, no mysql or php errors, but the array is not populated.
it's always returning a null value.
every attempt charles webproxy shows me that the result is null.
here is my code:
Code:
/**
	 * Returns the item corresponding to the value specified for the primary key.
	 *
	 * Add authorization or any logical checks for secure access to your data 
	 *
	 * @param string $itemID
	 * @return stdClass[]
	 */
	public function getCursoInfoByID($itemID) {
	
		
		$stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename where IDCurso=?");	
		$this->throwExceptionOnError();
		
		 
		 mysqli_stmt_bind_param($stmt, 's', $itemID);
		 $this->throwExceptionOnError();
		
		mysqli_stmt_execute($stmt);
		 $this->throwExceptionOnError();
		
		 $rows = array();
		
		 mysqli_stmt_bind_result($stmt, $row->IDCurso, $row->IDModulo, $row->NomeModulo, $row->ModuloAnterior, $row->ModuloSeguinte, $row->IDUnidade, $row->NomeUnidade, $row>UnidadeAnterior, $row->UnidadeSeguinte, $row->IDTopico, $row->NomeTopico, $row->TopicoAnterior, $row->TopicoSeguinte, $row->IDEcra, $row->NomeEcra, $row->EcraAnterior, $row->EcraSeguinte,$row->NumCreditos,$row->PathEcra);
		 array_push($rows,$row);

	     while (mysqli_stmt_fetch($stmt)) {
	   $newstdclass= new stdClass();
			mysqli_stmt_bind_result($stmt, $row->IDCurso, $row->IDModulo, $row->NomeModulo, $row->ModuloAnterior, $row->ModuloSeguinte, $row->IDUnidade, $row->NomeUnidade, $row->UnidadeAnterior, $row->UnidadeSeguinte, $row->IDTopico, $row->NomeTopico, $row->TopicoAnterior, $row->TopicoSeguinte, $row->IDEcra, $row->NomeEcra, $row->EcraAnterior, $row->EcraSeguinte,$row->NumCreditos,$row->PathEcra);
		  $newstdclass= $row;
		  array_push($rows,$newstdclass);
	     }
		
		 mysqli_stmt_free_result($stmt);
	     mysqli_close($this->connection);
	
	     return $rows;
		}
am i doing something wrong?
i can't seem to get my head around this....


forgot to add something, this works on my local machine, but not on a remote server, i've checked permissions, changed the connection string to the server, but doesn't return a thing
help would be apreciated

thanks in advance

Last edited by jonniebigodes; 01-16-2011 at 07:42 PM.
 
Old 01-12-2011, 09:51 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
May I ask you a favour? I'm working on a laptop w/ 1280x800, and
find it tortureous to try and read this post; can you replace your
PHP tags w/ plain old CODE tags? Never mind the colours - three way
scrolling to try and read something in its entirety doesn't work for me.



Cheers,
Tink
 
Old 01-16-2011, 07:42 PM   #3
jonniebigodes
Member
 
Registered: Feb 2006
Posts: 42

Original Poster
Rep: Reputation: 15
ok, sorry about that.
it's done, i've changed the tags
 
Old 01-16-2011, 11:42 PM   #4
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
You're using a single copy of $row, without ever properly initializing it.

Your class does the necessary mysqli_real_connect() before this gets used, I presume?
Could you try the following instead?

PHP Code:
public function getCursoInfoByID($itemID) {
    
$stmt mysqli_prepare($this->connection"SELECT * FROM $this->tablename where IDCurso=?");
    
mysqli_stmt_bind_param($stmt's'$itemID);
    
mysqli_stmt_execute($stmt);

    
$row = new stdClass();
    
mysqli_stmt_bind_result($stmt$row->IDCurso$row->IDModulo$row->NomeModulo$row->ModuloAnterior,
                            
$row->ModuloSeguinte$row->IDUnidade$row->NomeUnidade$row>UnidadeAnterior,
                            
$row->UnidadeSeguinte$row->IDTopico$row->NomeTopico$row->TopicoAnterior,
                            
$row->TopicoSeguinte$row->IDEcra$row->NomeEcra$row->EcraAnterior,
                            
$row->EcraSeguinte,$row->NumCreditos,$row->PathEcra);

    
$rows = array();
    
mysqli_stmt_store_result($stmt);

    while (
mysqli_stmt_fetch($stmt))
        
$rows[] = duplicate($row);

    
mysqli_stmt_free_result($stmt);
    
mysqli_stmt_close($stmt);

    return 
$rows;

I don't have a suitable database configured right now, so I cannot test this myself.
Nominal Animal

Last edited by Nominal Animal; 03-21-2011 at 06:34 AM.
 
Old 01-20-2011, 05:07 AM   #5
jonniebigodes
Member
 
Registered: Feb 2006
Posts: 42

Original Poster
Rep: Reputation: 15
i'm going to give it a go and see if it works
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP/MySQL | insert on duplicate key run php function?? xsyntax Programming 2 09-10-2010 03:14 AM
PHP: How to can a PHP function without refreshing the page? frenchn00b Programming 6 04-23-2009 04:57 PM
calling a function from within another function in php jayakrishnan Programming 2 06-19-2007 08:36 AM
PHP / VideoLAN / Fedora Core Question - how can I get the PHP "exec" function to work gtrawoger Linux - Software 3 12-21-2005 06:51 AM
Passing one php function result as a parameter to another php function davee Programming 13 09-12-2004 12:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration