CTphpnwb's Profile User Rating: *****

Reputation: 2896 Guru
Group:
Mentors
Active Posts:
10,038 (4.6 per day)
Joined:
08-August 08
Profile Views:
58,504
Last Active:
User is offline Yesterday, 06:01 PM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Mac
Favorite Browser:
Safari
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Toyota
Dream Kudos:
350
Expert In:
PHP

Latest Visitors

Icon   CTphpnwb has not set their status

Posts I've Made

  1. In Topic: Regarding Prepared Statements

    Posted 30 Jul 2014

    If you want 1 row returned then you need to write your query to ensure that. You could take the first value LIMIT 1 or the nth value LIMIT N,1 or you could be more specific about your parameters.
  2. In Topic: Regarding Prepared Statements

    Posted 30 Jul 2014

    Let's say there are 200 rows in your table that have enabled=1. Your query will retrieve all 200 of them, each time setting $this->sitename, $this->copyright, and $this->facebook and doing nothing with them, so the only row that will actually get used will be the last one. It's values will persist past the while loop, but all previous rows will have been overwritten.
  3. In Topic: Regarding Prepared Statements

    Posted 30 Jul 2014

    View PostDoxramosPS, on 30 July 2014 - 03:57 PM, said:

    When using a query that has no user input is it worth the time to convert it to a prepared statement or just leave it the way it is? IE
    public function GetSiteInfo() {
    		Dox::Connect();
    		$this->query="SELECT * FROM siteinfo";
    		$this->result=mysqli_query($this->mysqli,$this->query);
    		while($row=mysqli_fetch_object($this->result))
    			{
    				$this->sitename=$row->name;
    				$this->copyright=$row->copyright;
    				$this->facebook=$row->facebook;
    				}
    			}
    
    

    Note that this code will retrieve many rows but use only the last row while skipping all others. You probably want to do something like:
    public function GetSiteInfo() {
    	Dox::Connect();
    	$this->query="SELECT * FROM siteinfo";
    	$this->result=mysqli_query($this->mysqli,$this->query);
    	while($row=mysqli_fetch_object($this->result))
    	{
    		$this->output($row);
    	}
    }
    

    Where the output method will do something with the row. For example, it might display the information.

    Oh, and that still doesn't prepare the query.
  4. In Topic: datetime is not what I think it is, is it?

    Posted 30 Jul 2014

    Good catch. The variables in the query should be replaced by question marks, and if userid is an auto incrementing primary key there's no need to refer to it at all on an insert.
  5. In Topic: factorial of large numbers

    Posted 29 Jul 2014

    Factorials of large numbers can overflow int. Try unsigned long long.

My Information

Member Title:
D.I.C Lover
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Interests:
Looking for php programming work.
Years Programming:
34
Programming Languages:
Experience is important, yet at the same time it's over-rated.

Contact Information

E-mail:
Click here to e-mail me
Website URL:
Website URL  http://

Comments

Page 1 of 1
  1. Photo

    CTphpnwb Icon

    31 Mar 2010 - 18:50
    Please post programming questions in the appropriate forums.
Page 1 of 1