Jump to content



Photo

PHP - SQL Efficiency Questions

sql

  • Please log in to reply
18 replies to this topic

#16 +Seahorsepip

Seahorsepip

    http://seapip.com

  • Tech Issues Solved: 26
  • Joined: 23-January 11
  • Location: Netherlands
  • OS: Windows 8.1 Pro
  • Phone: Nexus 5

Posted 21 July 2014 - 00:48

Oh okay I get it now. I am used to ASP.NET where I would need to make new parameters on every line.

So if I was using a Series ID, I would use i instead of an s? What would happen if I use an i but I pass in a string?

Also, Seahorsepip, you had the following code:

while($row = mysqli_fetch_array($result)) {
	$v = $row[v.*]; //Set current v.* as variable v
	$r = $row[r.*]; //Set current r.* as variable r
	$videos[$v][] = $r; //Add r to array of v
}
More specifically:
$videos[$v][] = $r; //Add r to array of v
If a video has multiple resources, does that append to the array, or overwrite the first several resources with that is in the current iteration?
That code appends a resource to the end of the array, it does not overwrite resources. Using [] without a value means that you want to add a value to the end of the array inside videos[$v].
You can also make it even more advanced. Currently the array exists of a list of video ids with a array inside them consisting of sources.

You can also make a array of video ids and inside that a array of video details, so one name, one link, an array with descriptions.

So the array would look like this:
$videos = array();

//Begin while loop
$id = 123;
$name = "video name";
$link = "video link";
$description = array("description one","description two","description three");
$video = array(name=>$name,link=>$link,description=>$description);
$videos[$id] = $video;
//End while loop

print_r($videos);//show array that has been created for testing, if the text looks like a single line add <pre> html tags around this php block



#17 +Seahorsepip

Seahorsepip

    http://seapip.com

  • Tech Issues Solved: 26
  • Joined: 23-January 11
  • Location: Netherlands
  • OS: Windows 8.1 Pro
  • Phone: Nexus 5

Posted 21 July 2014 - 00:55

And if you use a i and pass in a string you should get a error, that's the whole point of prepared mysqli queries, you can try yourself and see what happens ^^

#18 OP xWhiplash

xWhiplash

    Neowinian Senior

  • Joined: 07-March 08

Posted 21 July 2014 - 01:45

Okay, thanks for the help!



#19 tim_s

tim_s

    Default

  • Tech Issues Solved: 1
  • Joined: 07-January 13
  • OS: OSX (Macbook Pro i7), Windows 7 (Gaming), Gentoo
  • Phone: iPhone 5s

Posted 31 August 2014 - 15:57

Hi,

When dealing with stock PHP / MySQL you will be dealing with unoptimized configurations, in regards to memory management and IO.

You will have a performance difference between PDO and MySQLi where in most instances MySQLi will out perform PDO, however, you will lose a lot of features. Two that might specifically be of interest.

1. Prepared statements (can be done in MySQLi but is native for PDO), which adds a lot of benefits.

2. PDO is not tied to a specific "vendor", which I use the term loosely.