Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Little Brittle posted:

I can't figure out how to get wrappers working, so I'll just use CURL. Thanks for the tip.

I have another question, how do you get the value of an attribute via XPATH? I have an xml file that looks like this, and I'm trying to grab the ref[href] value (hello.php). Nothing I've tried doesn't seem to be working, and I can't find any good tutorials on it.
code:
<ASX Version="3">
<ENTRY>
<REF HREF="hello.php"/>
<MBLINK HREF="http://www.example.com" />
</ENTRY>
</ASX>

I don't think you can do that with XPath alone. Try pulling the node via XPath, then reading the attribute from the results. Example:

php:
<?
$nodes = $xpath->query('//REF');
foreach ($nodes as $n) {
    echo $n->getAttribute('HREF');
}
?>

Adbot
ADBOT LOVES YOU

tef
May 30, 2004

-> some l-system crap ->
the xpath is /ref/@href.

Edit: No it isn't - oops.

tef fucked around with this message at 08:26 on Jul 5, 2008

waffle iron
Jan 16, 2004

Little Brittle posted:

I can't figure out how to get wrappers working, so I'll just use CURL. Thanks for the tip.

I have another question, how do you get the value of an attribute via XPATH? I have an xml file that looks like this, and I'm trying to grab the ref[href] value (hello.php). Nothing I've tried doesn't seem to be working, and I can't find any good tutorials on it.
code:
<ASX Version="3">
<ENTRY>
<REF HREF="hello.php"/>
<MBLINK HREF="http://www.example.com" />
</ENTRY>
</ASX>
The lazy way is //REF/@HREF and that will give you a nodeset of all HREF attributes of REF tags.

You need the // to search all nodes for the REF tag otherwise the query is /ASX/ENTRY/REF/@HREF

In most engines the tag/attribute name matching can be case sensitive, so check first.

waffle iron fucked around with this message at 04:34 on Jul 5, 2008

Little Brittle
Nov 1, 2004

Come visit me dawg
Finally got it, thanks for the help everyone.

Another question that has been boggling my mind: How can I grab a page's content via curl that requires the URL to be urldecoded? A site I'm working with requires spaces in the URI, and 301 redirects if it has any '%20' characters. That redirect causes curl to error and not grab the page. My host doesn't allow CURLOPT_FOLLOWLOCATION, and I've read that enabling it can be a security concern. Here's an example:

The URL should look like this:
code:
http://example.com/photos/my cool album/100.html
This is the URL curl tries to grab after it has been passed into CURLOPT_URL, and subsequently receives an error:
code:
http://example.com/photos/my%20cool%20album/100.html
Is there any way to pass curl an urldecoded URL?

Zorilla
Mar 23, 2005

GOING APE SPIT

Little Brittle posted:

Is there any way to pass curl an urldecoded URL?

urldecode()

Is this what you're looking for or does PHP's curl function crap out when you use URIs with spaces? Either way, URIs with spaces breaks standards. You should be requesting the document with an encoded URI, then have the target site decode it at that end.

Zorilla fucked around with this message at 10:40 on Jul 5, 2008

Little Brittle
Nov 1, 2004

Come visit me dawg
The problem is, the site redirects urlencoded requests and curl can't follow the redirect. If I pass an urldecoded string to curl, it automatically tries to grab the urlencoded page. Unless there is some little-known parameter that makes curl ignore urldecoded URLs, I don't see a solution to grab a page with spaces in the URI when the host site requires it.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Little Brittle posted:

The problem is, the site redirects urlencoded requests and curl can't follow the redirect. If I pass an urldecoded string to curl, it automatically tries to grab the urlencoded page. Unless there is some little-known parameter that makes curl ignore urldecoded URLs, I don't see a solution to grab a page with spaces in the URI when the host site requires it.

That doesn't make much sense. Like Zorilla said, it violates the standards. What happens when you put the URL with spaces in a browser's address bar? How about when you replace the spaces with + instead of %20?

Edit: By the way, you can tell cURL to follow redirects by setting the CURLOPT_FOLLOWLOCATION option to true.

DaTroof fucked around with this message at 20:09 on Jul 5, 2008

Little Brittle
Nov 1, 2004

Come visit me dawg

DaTroof posted:

That doesn't make much sense. Like Zorilla said, it violates the standards. What happens when you put the URL with spaces in a browser's address bar? How about when you replace the spaces with + instead of %20?

Edit: By the way, you can tell cURL to follow redirects by setting the CURLOPT_FOLLOWLOCATION option to true.

I know it violates standards, but that's how they roll. When you put the URL with spaces in the address bar, the spaces are not converted. If you put the address in with %20, the page is redirected and they are converted to spaces. I know you can follow redirects with curl, but my host disallows CURLOPT_FOLLOWLOCATION for security reasons. I think you have to disable open_basedir in order to enable it, and I've read that opens up a whole host of problems.

Zorilla
Mar 23, 2005

GOING APE SPIT
Is that URL going to an actual path, such as photos/my cool album/100.html, or is it rewriting to something like index.php?get1=photos&get2=my cool album&get3=100

If it's the latter, it makes sense that it's redirecting on you since it can't find any entries literally named "my%20cool%20album" in the database and is probably doing something like taking you back to the front page because of it. If this is what it's doing, you could probably substitute spaces with + since that's what web browsers and PHP expect (and does automatically for things like multiple search keywords in forms).

Zorilla fucked around with this message at 22:20 on Jul 5, 2008

cannibustacap
Jul 7, 2003

Brrrruuuuuiinnssss
I have Visual Studio 2008 through my school and I am wondering if you'd recommend them as a PHP debugger? I don't think that PHP comes standard in VS2008 so which add on would you recommend to allow PHP functionality?

Little Brittle
Nov 1, 2004

Come visit me dawg

Zorilla posted:

Is that URL going to an actual path, such as photos/my cool album/100.html, or is it rewriting to something like index.php?get1=photos&get2=my cool album&get3=100

It's the actual path where the content is located. Properly encoded URLs are redirected to the standard-violating path.

Anveo
Mar 23, 2002

cannibustacap posted:

I have Visual Studio 2008 through my school and I am wondering if you'd recommend them as a PHP debugger? I don't think that PHP comes standard in VS2008 so which add on would you recommend to allow PHP functionality?

I believe there is a commercial PHP debugger for VS, but you are probably better off just using a good text editor. If you need a real debugger that you can step through code with, try Zend Studio, Eclipse, Komodo, or (preferably :))Vim.

cannibustacap
Jul 7, 2003

Brrrruuuuuiinnssss

Anveo posted:

I believe there is a commercial PHP debugger for VS, but you are probably better off just using a good text editor. If you need a real debugger that you can step through code with, try Zend Studio, Eclipse, Komodo, or (preferably :))Vim.

I was looking around and I think I may just use the netbeans + xdebug option http://www.netbeans.org/kb/61/php/installing-and-configuring-required-software.html

What do you think?

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Little Brittle posted:

It's the actual path where the content is located. Properly encoded URLs are redirected to the standard-violating path.

That's what doesn't make sense to me. The browser should encode the URL before it gets sent. If the browser requests a URL with illegal characters, the server should respond with a bad request error. If it requests a URL with encoding, the server should unencode it before it tries to resolve it to a local file path, so you shouldn't need the redirect in the first place.

Zorilla
Mar 23, 2005

GOING APE SPIT
Yeah, this is starting to sound like a fundamental server problem to me. Even with absolutely no dynamic code, %20 should be interpreted as a space by the web server for any case in which directories have spaces in them, not redirecting. I have to wonder how you're even able to access the page through an ordinary web browser (as opposed to curl) since they encode illegal characters on the fly once you hit "Go" on the URL bar.

If you're comfortable with it, would you like to paste your .htaccess file to see if it sheds any light on this problem?

Zorilla fucked around with this message at 00:27 on Jul 6, 2008

Little Brittle
Nov 1, 2004

Come visit me dawg
This is a remote server I'm grabbing info from, so I don't have the htaccess file available. I managed to grab the page with file_get_contents() as opposed to curl, so that will work for now. I have no idea what their server config is, but I've never seen anything like that before either.

Rabbi Dan
Oct 26, 2005

ASK ME ABOUT MY CREEPY FACEBOOK APP FOR STALKING GIRLS I DON'T KNOW
A while ago when I started doing PHP/MySQL I downloaded this great software bundle called phpdev (http://www.firepages.com.au/yak2.htm/down1).

It basically gives you everything you need to locally develop PHP/MySQL web apps: a local apache server w/PHP modules installed, MySQL, and phpmyadmin all set up and ready to go.

It hasn't been updated recently and I'd like to use the MySQL/phpmyadmin setup as a database for another server-side scripting framework but I want to use the latest version of MySQL and phpmyadmin.

Downloading the latest version of phpmyadmin is easy - I just get the php files and put them in the appropriate directory, but I don't know what to do about mysql. Has anyone here ever used phpdev and can anyone perhaps let me know how I could download/setup the latest version of MySQL to work with this bundle?

I'd appreciate it. Thanks.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Rabbi Dan posted:

It hasn't been updated recently and I'd like to use the MySQL/phpmyadmin setup as a database for another server-side scripting framework but I want to use the latest version of MySQL and phpmyadmin.


Check out XAMPP, it is updated quite frequently.

40ozOE
Aug 26, 2004

Bedridden I know more than you.
I'm using Dreamweaver CS3 to create some PHP pages, and 100% of the PHP code on my site is generated automatically through Dreamweaver. After using it a while, I can spot errors and fix them, but I haven't really created anything myself. So:

Can I call for a specific data entry in a specific spot? Let's say in Spot #1 I want Entry x. In Spot #2 I want Entry x-1. In Spot #3, I want Entry x-2.

I know that sounds like a "repeating region", but I want to change the information displayed based on the spot. (I've got a newsstory database. Spot #1 is displayed with photo/headline/byline/summary, for example. Spot #2 is just photo/headline, etc.) Dreamweaver's "repeating region" displays all the information the same way.

Are there any resources/tutorials for this? I'd Google it, but it took me 20 minutes just to figure out how to convey my idea without any real hands-on PHP experience, and I'm still not sure how clear it is.

Evil Angry Cat
Nov 20, 2004

You know I'm as willing to stick up for PHP as just about anyone when the going gets tough but I've just come across something that is such complete idiocy that I can't even begin to fathom why whoever wrote it is even allowed to continue existing.

I think we all accepted a long time ago that PHPs core functions were a bit loopy and zany, like a very inconsistent clown. For instance today I became annoyed once more in PHPs assumption that I never want to preserve keys in my arrays. Excuse me sir, you want to preserve keys in array_reverse()? Well you better flag it because obviously it sense to not preserve them by default!

Then today after crafting quite a handsome depthSort() function that will sort an array of arrays based on a consistent internal key and testing it using associative and non-associative keys such as:

php:
<?
$thisarr = array ('Ben' => array ('Happy' => 12, 'Sad' => 20), 'Rob' => array ('Happy' => 10, 'Sad' => 22), 'Mike' => array ('Happy' => 5, 'Sad' => 100));

$thisarr = depthSort($thisarr, "Happy");
print_r($thisarr);
?>
I was very happy with my creation, until three hours later I came to use it on an array which looks like this:


Array ( [6] => Array ( [Total] => 4 [Correct] => 2 ) [11] => Array ( [Total] => 4 [Correct] => 2 ) [10] => Array ( [Total] => 4 [Correct] => 2 ) [7] => Array ( [Total] => 4 [Correct] => 2 ) [3] => Array ( [Total] => 3 [Correct] => 2 ) [8] => Array ( [Total] => 4 [Correct] => 1 ) [1] => Array ( [Total] => 4 [Correct] => 0 ) [9] => Array ( [Total] => 3 [Correct] => 2 ) [2] => Array ( [Total] => 4 [Correct] => 3 ) [5] => Array ( [Total] => 3 [Correct] => 1 ) [4] => Array ( [Total] => 3 [Correct] => 2 ) )


After having it not work for a while and trying to figure out what the problem is, I head over to php.net to take a look at some of the internal functions that depthSort() uses to see if I can find the problem. Low and behold:

array_multisort() can be used to sort several arrays at once, or a multi-dimensional array by one or more dimensions.

Associative (string) keys will be maintained, but numeric keys will be re-indexed.


I just can't fathom why anyone thought this would be a good idea? Why is it that they've decided that numeric keys are completely useless and no would ever use them associatively? I mean there has to be a reason doesn't there? Please can someone explain to me why someone lacked such basic sense as to automatically re-index an array thats being sorted by an integer based key? Gah sometimes PHP.

functional
Feb 12, 2008

Evil Angry Cat posted:

I just can't fathom why anyone thought this would be a good idea? Why is it that they've decided that numeric keys are completely useless and no would ever use them associatively? I mean there has to be a reason doesn't there? Please can someone explain to me why someone lacked such basic sense as to automatically re-index an array thats being sorted by an integer based key? Gah sometimes PHP.

I think I see what you're getting at.

Unfortunately things don't work out for you in this instance, but overall it makes more sense to do what they're doing.

The reason is that all PHP arrays are associative, but 'unkeyed' arrays typically rely on keyed values to determine order. It wouldn't make sense for me to create $a=Array('Z','Y','X') and have $a[0] return the same value before and after the sort.

I wasn't aware before that there are PHP functions which will step through a list in the order it's stored, even if some of the keys are integers that are out of order. This is good to know.

php:
<?
$a=Array(1=>'A', 0=>'B');//Same as $a=Array('1'=>'A', '0'=>'B');
echo $a[0];//B
foreach($a as $i)echo $i;//AB
for($i=0;$i<count($a);$i++)echo $a[$i];//BA
?>

functional fucked around with this message at 16:10 on Jul 9, 2008

Evil Angry Cat
Nov 20, 2004

functional posted:

The reason is that all PHP arrays are associative, but 'unkeyed' arrays typically rely on keyed values to determine order. It wouldn't make sense for me to create $a=Array('Z','Y','X') and have $a[0] return the same value before and after the sort.

Good point well made. If only they'd give me the option though like they do with all of their other barmy array functions I'd be happy.

functional
Feb 12, 2008

Evil Angry Cat posted:

If only they'd give me the option though like they do with all of their other barmy array functions I'd be happy.

Yep, you're right. There ought to be an option for what you want to do. I would submit a feature request. It shouldn't be a difficult change to implement. (Presuming asort() is insufficient for your application.)

functional fucked around with this message at 21:20 on Jul 9, 2008

Stephen
Feb 6, 2004

Stoned
In PHP using the MVC method, I see a lot of people criticize for using foreach() inside a view. I understand why this might be bad, as it's always best to keep the PHP and HTML as seperated as possible, but I don't understand why this situation is so unacceptable. If I want to build a table of information on my page based on database results, I'll have to build the table's rows HTML inside the controller, and then echo that in the view, or pass the data and loop inside the view.

In either of these instances, I'm mixing code, but as far as I can tell it's unavoidable. Is there a better way that I'm not seeing?

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Stephen posted:

In PHP using the MVC method, I see a lot of people criticize for using foreach() inside a view.
...
In either of these instances, I'm mixing code, but as far as I can tell it's unavoidable. Is there a better way that I'm not seeing?

No, you have to. I can't imagine anybody criticizing that.

If you're a smarty pants you use a {foreach from=$myArray item=foo}

bleh
Jun 13, 2003

I have a web form and want the action page to be self.php with an anchor "anc"

code:
<form action="self.php#anc" method="post" name="webform">
Some visitors (HTTP Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
are getting 404 errors because the url is resolving to self.php%23com. The character code for # is "%23". Is there any way to make this work both ways? Is there a redirect I can do in my .htacesss to make this work?

hey mom its 420
May 12, 2007

Yeah, foreach is basically the control flow construct for templates. It needs minimal logic and produces the desired behaviour. If you wanted to put foreach loops out of your templates, you'd probably have to generate all the HTML that requires looping in the controllers and then pass that off to the views ... :wtc:

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Bonus posted:

Yeah, foreach is basically the control flow construct for templates. It needs minimal logic and produces the desired behaviour. If you wanted to put foreach loops out of your templates, you'd probably have to generate all the HTML that requires looping in the controllers and then pass that off to the views ... :wtc:

the first and worst sin of home-grown template engines is usually that they suck at iteration, which usually means they suck loving period.

either you're using a foreach() in your templates, or you have some equivalent to a foreach() method in your template engine, or your template engine loving sucks. even trivial web sites usually need some way to loop through a collection, for chrissake

<deleted user>
PHP's foreach is a mess. You need to be really careful with it because of how it performs implicit copies and may screw around with references in unexpected ways. Because PHP has no lexical scope, foreach also does not clean up after itself properly as it does in other languages.

The effects differ depending what version of PHP you are using. I think a for loop is much safer and predictable.

MrEnigma
Aug 30, 2004

Moo!

genericadmin posted:

PHP's foreach is a mess. You need to be really careful with it because of how it performs implicit copies and may screw around with references in unexpected ways. Because PHP has no lexical scope, foreach also does not clean up after itself properly as it does in other languages.

The effects differ depending what version of PHP you are using. I think a for loop is much safer and predictable.

The biggest issue is that referencing switched from PHP4 to PHP5, at least with regard to objects.

In PHP5 objects are always referenced when using '=', arrays are referenced using '=&'
In PHP5 a '=&' on an object makes a 'hard-link',
Example:
$a = new ABC();
$b =& $a;
unset($b);

Edit: I think this might actually be a clone (shallow copy) but it's deprecated in PHP5 regardless.

That will actually unset $a because it's a 'hard-link', just using a normal reference or copy would leave just $b unset.

With regards to a foreach, you can specify to do foreach($array as &$value) which allows you to not copy the array but do it b y reference instead. (the & in front of the $value).

Also be aware that foreach will move the array pointer also (but calling foreach resets it back to the start).

MrEnigma fucked around with this message at 06:37 on Jul 10, 2008

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
Will an if statement try the rest of the conditions after the first one fails?

Wazzerphuk
Feb 9, 2001

Hating Chelsea before it was cool
Winner of the PWM POTM for September
Winner of the PWM POTM for January
Co-Winner of the PWM POTM for March

fletcher posted:

Will an if statement try the rest of the conditions after the first one fails?

No, it'll only go as far as it needs (from left-to-right).

That is:

php:
<?
if (a() || b()) # b() won't be called if a() returns true
{ ...

if (a() && b()) # b() won't be called if a() returns false
{ ...
?>

chocojosh
Jun 9, 2007

D00D.
I apologize if this has already been asked.

I'm working on a small e-commerce site for a friend. I'm building a very simple admin interface to add items to the database (MySQL). She wants to be able to upload a description, title, and image.

1) She's a graphic designer so she suggested manually resizing the images herself and uploading two images (full-sized and thumbnail) at once. Would there be a way to let her only give the larger image and have a script automatically resize it to the appropriate sized thumbnail without quality loss?
2) Since I've never worked with images/BLOBs before, is there anything I need to be aware of? Is it possible to do mysql injection or other bad things with image data. I saw an online tutorial that used addslashes() on the image data; I used mysql_real_escape_string on my previous site so I'd like a goon opinion or two.

Murodese
Mar 6, 2007

Think you've got what it takes?
We're looking for fine Men & Women to help Protect the Australian Way of Life.

Become part of the Legend. Defence Jobs.

chocojosh posted:

I apologize if this has already been asked.

I'm working on a small e-commerce site for a friend. I'm building a very simple admin interface to add items to the database (MySQL). She wants to be able to upload a description, title, and image.

1) She's a graphic designer so she suggested manually resizing the images herself and uploading two images (full-sized and thumbnail) at once. Would there be a way to let her only give the larger image and have a script automatically resize it to the appropriate sized thumbnail without quality loss?
2) Since I've never worked with images/BLOBs before, is there anything I need to be aware of? Is it possible to do mysql injection or other bad things with image data. I saw an online tutorial that used addslashes() on the image data; I used mysql_real_escape_string on my previous site so I'd like a goon opinion or two.

1) http://au.php.net/gd

2) Don't store images in the db. Instead, write an upload script that stores the file on the server (an upload folder or something), rename the stored file to a uniqid().extension so you don't have to worry about same-name photos, and store it in the database as something like

imageID | physical_name | alt_text?orsomething

(assuming the image is only used for a single product)

chocojosh
Jun 9, 2007

D00D.
I was actually hoping to store the images in the database although I've read that it's a more common approach to store them in the file system.

Any reasons why I shouldn't store them in the DB?

hey mom its 420
May 12, 2007

Yeah.
  • You can't change databases once you have them inside because the BLOB format might be incompatible.
  • You can't get the images via other protocols (FTP or something RESTful or whatever) without resorting to writing scripts that query the DB and then relay the images.
  • There are performance implications. Getting them out of the database every time and then echoing them through a serverside language is slow and since the database is the most likely bottleneck of a website you should hit it as little as possible.
Pretty much the only upside to storing them in the DB is that there's no chance of having broken links. But I've used the approach of storing them in the filesystem many times and I've never had any broken links. Just remember to check if it's been uploaded to the filesystem before committing the database record and if it hasn't then just roll it back.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

So I'm trying to implement Dijkstra's algorithm for a side project I'm working on but I'm having difficulty grasping how the whole thing works...

I've setup a map where each location a player can be go to is identified as a sector. Each sector knows whether it connects to any of the sectors to the north, east, south, or west of it.

In MySQL, the table for sectors looks like this:

table: sectors
sector_id | north | east | south | west

If the current sector connects with another (eg. north) then it would have the sector_id in that field. Otherwise the value of 0 would be in the field.

Would the connecting sectors be the vertices?

To illustrate it, the map array might look something like this:

code:
array( '1' => array( 'north' => 0, 'east' => 2, 'south' => 6, 'west' => 0) );
array( '2' => array( 'north' => 0, 'east' => 3, 'south' => 7, 'west' => 1) );
array( '3' => array( 'north' => 0, 'east' => 0, 'south' => 8, 'west' => 2) );
array( '6' => array( 'north' => 1, 'east' => 0, 'south' => 0, 'west' => 0) );
array( '7' => array( 'north' => 2, 'east' => 8, 'south' => 0, 'west' => 0) );
array( '8' => array( 'north' => 3, 'east' => 0, 'south' => 0, 'west' => 7) );

1 - 2 - 3
|   |   |
6   7 - 8
edit: drew that wrong

Acer Pilot fucked around with this message at 00:34 on Jul 11, 2008

Stephen
Feb 6, 2004

Stoned
code:
// Accepts an id, if 0 or nothing is passed, a random dog is displayed.
if($idCanine == 0) {
	$stmt = $this->dbPrepare('CALL SP_S_CANINE_RANDOM()');
} else {
	$stmt = $this->dbPrepare('CALL SP_S_CANINE(:idCanine)');
	$stmt->bindParam(':idCanine', $idCanine);
}
$stmt->execute();

function dbPrepare($sqlString) {
	return $this->dbo->prepare($sqlString);
}
I'm trying to get this to work, but every time it returns 0 results.

If I move either of the prepares right above the execute() line, it works perfectly. Can anyone tell me what the issue is, or am I just retarded?

SuckerPunched
Dec 20, 2006

Why in the world did you put the prepare statement into a wrapper? That seems ... wasteful? What happens when you just run the prepare without the wrapper?

Adbot
ADBOT LOVES YOU

Stephen
Feb 6, 2004

Stoned

SuckerPunched posted:

Why in the world did you put the prepare statement into a wrapper? That seems ... wasteful? What happens when you just run the prepare without the wrapper?

I'm really just experimenting mostly. This is the first time I've used PDO's.

code:
$idCanine = 0;
if($idCanine == 0) {
	$stmt = $this->dbo->prepare('CALL SP_S_CANINE_RANDOM()');
} else {
	$stmt = $this->dbo->prepare('CALL SP_S_CANINE(:idCanine)');
	$stmt->bindParam(':idCanine', $idCanine);
}
$stmt->execute();
This fails. Returns 0 results.

code:
$idCanine = 0;
$stmt = $this->dbo->prepare('CALL SP_S_CANINE_RANDOM()');
$stmt->execute();
This fails. Returns 0 results.

code:
$idCanine = 0;
if($idCanine == 0) {
	$stmt = $this->dbo->prepare('CALL SP_S_CANINE_RANDOM()');
} else {
	$stmt = $this->dbo->prepare('CALL SP_S_CANINE(:idCanine)');
	$stmt->bindParam(':idCanine', $idCanine);
}
		
$stmt = $this->dbo->prepare('CALL SP_S_CANINE_RANDOM()');
$stmt->execute();
Edit: This works properly, however. I just don't understand why.

Stephen fucked around with this message at 20:29 on Jul 11, 2008

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply