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
Tap
Apr 12, 2003

Note to self: Do not shove foreign objects in mouth.

Lankiveil posted:

What is the current cool framework to use for PHP? At the moment I'm playing with CodeIgniter, but I'm happy to jump ship if there's something better out there.

If you like CodeIgnitor, check out Kohana. It's a PHP5 based framework originally built from CI, but completely rewritten to take advantage of PHP5's 'features'.

It is a really robust framework and I use it all the time in my projects.

https://www.kohanaphp.com

Adbot
ADBOT LOVES YOU

Lankiveil
Feb 23, 2001

Forums Minimalist

Anveo posted:

If you are going to look into it, you will probably want to start with version 1.2.

I've just had a quick look through the docs, and it actually looks fairly good. I'll have a bit of a play with this, thanks for the tip!

MrMoo
Sep 14, 2000

duz posted:

Commonly request scripts These have been checked for security
r1ch has an image uploading script

Does anyone bother altering HTTP status codes for errors? Taking R1CH's upload script for example:

php:
<?
header('HTTP/1.1 503 Service Unavailable');
die ("...");
...
header('HTTP/1.1 400 Bad Request');
$error = "Upload failed, please check the filename and try again.";
...
header('HTTP/1.1 413 Request Entity Too Large');
$error = "File size exceeded, maximum allowed file is {$config['max_size']}...
...
header('HTTP/1.1 500 Internal Server Error');
$error = "Internal error, unable to open uploaded file.";
?>
The 415 error is supposed to be in regard to client not server support, otherwise this one too:
php:
<?
header('HTTP/1.1 415 Unsupported Media Type');
$error = "Unknown file format, only JPEG, PNG and GIF files are allowed.";
?>
If the script didn't try to workaround previous uploaded files with the same name:
php:
<?
header('HTTP/1.1 409 Conflict');
$error = 'File already uploaded';
?>
If you can ban or delete entries you could use this:
php:
<?
header('HTTP/1.1 410 Gone');
$error = 'File has been removed';
?>
Or using the additional 200 codes when things go well:
php:
<?
header('HTTP/1.1 201 Created');
?>
<p>Your file was uploaded successfully.</p>
...
?>
For 202 it could be used with say a Waffle Images URL load, i.e. submit a form with an URL to load an image from, the server returns "202 Accepted" with an hanging-Ajax (Comet) display for progress reporting.

Is this only really useful if a program is going to interact with a webservice so they don't have to scrape?

In the meantime, enjoy a set of icons representing HTTP status codes on Flickr:

http://www.flickr.com/photos/apelad/sets/72157594388426362/

Static_Fiend
Jun 4, 2003

Who amongst us will have reached the end?
I've been having a hell of a time getting this to work properly and it still isn't quite doing what I've been wanting it to. I've been lately working with MySQLI and for the life of me I cannot get it to sort by what I want using variables.

php:
<?
$result = mysqli_prepare($dbh, "SELECT * FROM vidinfo ORDER BY ? LIMIT ?, 15");
mysqli_stmt_bind_param($result, "si", $sort, $limit);
mysqli_stmt_execute($result);
mysqli_stmt_bind_result($result, $id, $path, $vwidth, $vheight, $title, $author, $game, $fore, $back, $dnd, $uploader);
?>
When I do the fetch it doesn't sort properly at all, it seems to be ignoring ORDER BY entirely ($sort is never blank) and just sorting as it pleases.

Here's the fetch:
php:
<?
while (mysqli_stmt_fetch($result))
?>
Code executed in there just uses the variables from the bind_result. Is there anything I'm missing?

Edit: Some solutions I've come up with are to just make a ton of if's (looks ugly, would rather not resort to that) or maybe try:

php:
<?
$result = mysqli_prepare($dbh, "SELECT * FROM vidinfo ORDER BY ".$sort." LIMIT ?, 15");
?>
However security wise I'm not sure if this is a good idea or not.

Static_Fiend fucked around with this message at 04:14 on Nov 28, 2008

Lankiveil
Feb 23, 2001

Forums Minimalist

MrMoo posted:

Does anyone bother altering HTTP status codes for errors? Taking R1CH's upload script for example:

Yes, I use some obscure status codes (402 and 405, for instance) for things like malformed requests or unsupported requests. Perhaps not so useful for screenscrapers (who are the only ones who usually do these things), but useful for log tracking to see what bots are getting up to.

Mackerel, the Thief
Sep 24, 2003

Static_Fiend posted:

stuff




Edit: Nevermind. You cannot use bind_param for returning results. You can only use it for INSERT, UPDATE, and DELETE requests. What you're looking for is bind_result: http://us3.php.net/manual/en/mysqli-stmt.bind-result.php

Mackerel, the Thief fucked around with this message at 07:56 on Nov 28, 2008

MrMoo
Sep 14, 2000

Lankiveil posted:

Yes, I use some obscure status codes (402 and 405, for instance) for things like malformed requests or unsupported requests.

I just tried a 502 and PHP trimmed off the entity content, so if it's the same with many of the other codes it's pretty much impossible to use them for direct browser facing resources.

(edit) also 504 munged, and to quite a problem 413 is munged too. 500 and other 4xx codes seem to go through.

MrMoo fucked around with this message at 08:07 on Nov 28, 2008

Static_Fiend
Jun 4, 2003

Who amongst us will have reached the end?

Mackerel, the Thief posted:

Edit: Nevermind. You cannot use bind_param for returning results. You can only use it for INSERT, UPDATE, and DELETE requests. What you're looking for is bind_result: http://us3.php.net/manual/en/mysqli-stmt.bind-result.php

Edit: Nevermind, documentation for mysqli_prepare told me what's up:

quote:

However, they are not allowed for identifiers (such as table or column names), in the select list that names the columns to be returned by a SELECT statement, or to specify both operands of a binary operator such as the = equal sign.

So basically what I'm trying to do won't fly with this, ah well, guess I'm gonna have to do it another way.

Static_Fiend fucked around with this message at 10:12 on Nov 28, 2008

Unboxing Day
Nov 4, 2003

I'm having trouble with PHP and SOAP. The company whose server we are trying to access has sent us a sample soapclient script that they wrote using PHP4 and NuSoap that they claim works on their end. Our shop is PHP5, so I decide to convert the thing to use PHP5's SoapClient.

This is where I stand. I can connect to the SOAP Server fine. However, it keeps telling me that it is unable to parse the XML I'm sending it. To see if my server is misconfigured, I copy the script locally to my own machine and try it again. No dice. Out of curiosity, I wireshark the packets being sent to it, and I find out that indeed, the XML body is nowhere to be found.

At this point, I figure that my inexperience with SOAP in general has caused me to cock up something somewhere along the line. So I decide to download NuSOAP for PHP5, modify the script they gave me to account for the class naming fuckery, and give it a shot. Strangely enough, although the script works fine, I get the exact same XML parsing error, and sure enough upon wiresharking the outgoing packets the XML body is nowhere to be found; this time in a script that they claim works on their end.

I'm now at a loss. I have zero prior experience with SOAP, so I don't even know how to begin to figure out what's wrong, but something tells me that it's not my code that's the problem, instead there is some configuration setting I have to toggle, since both scripts are being wonky in the exact same way. What is going on here?

spiritual bypass
Feb 19, 2008

Grimey Drawer
The posting URL needs to point to a WSDL document; where I work, our customers give us URL's that look like this

http://soap.example.com/post.asmx

but what you want is

http://soap.example.com/post.asmx?WSDL

That might not be what's going on with you, but it's gotten me plenty of times.

Unboxing Day
Nov 4, 2003

royallthefourth posted:

The posting URL needs to point to a WSDL document; where I work, our customers give us URL's that look like this

http://soap.example.com/post.asmx

but what you want is

http://soap.example.com/post.asmx?WSDL

That might not be what's going on with you, but it's gotten me plenty of times.

Yep, that looks like the URL that I post to, but thanks.

Also, keep in mind that they claim that the script they gave me worked on their end, but when I tried it, I ran into the same problem as doing it using PHP5's SoapClient.

gibbed
Apr 10, 2006

Are you creating the SoapClient from a remote WSDL file or something local? Try downloading the WSDL and pointing the SoapClient at the local WSDL file instead?

Unboxing Day
Nov 4, 2003

gibbed posted:

Are you creating the SoapClient from a remote WSDL file or something local? Try downloading the WSDL and pointing the SoapClient at the local WSDL file instead?

Remote. Tried to download it and use it locally with no luck. Pretty much everything here did work though so at least I can rule out the feature being totally broken for whatever reason - at least going local -> local.

Unboxing Day fucked around with this message at 18:48 on Dec 1, 2008

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.
Does the SOAP API you are referencing require attachments? I was working with a SOAP API with attachments and found that for some reason in php5 its totally borked due to libxml or some such dependency. I ended up fixing it by hacking around with the pear soap library and I finally got it to work that way.

Also, you might want to try fiddler instead of wireshark. Its heaven for this kind of stuff, a lot easier than wireshark.

NoSpoon
Jul 2, 2004
I've got a relatively simple (I hope) regular expression question...

I have some templates which are written like..

quote:

Hi People. <a href="http://site/invoice.php?i=[[INV_NUM]]">Click here to view invoice [[INV_NUM]]</a> on our site.
Obviously [[INV_NUM]] gets populated with a legit invoice number before sending it out.

I'd like to replace all these (there's a bunch of them) with <span class="previewtag">[[INV_NUM]]</span> so that it gets highlighted in a pretty colour so people know we'll deal with it later.

My problem comes with not replacing the tag if it's inside an HTML tag. Basically I guess I need something that matches [[INV_NUM]] that isn't <.*[[INV_NUM]].*>. Or something like that.

Thanks!

Zorilla
Mar 23, 2005

GOING APE SPIT
It seems like it would be much more straightforward and flexible in the future just to put <span class="previewtag">[[INV_NUM]]</span> in the template itself. Even if you're not doing a proper MVC application, you really should keep your code and HTML output as separate as possible.

Is there any reason you're not doing this now?

NoSpoon
Jul 2, 2004

Zorilla posted:

It seems like it would be much more straightforward and flexible in the future just to put <span class="previewtag">[[INV_NUM]]</span> in the template itself. Even if you're not doing a proper MVC application, you really should keep your code and HTML output as separate as possible.

Is there any reason you're not doing this now?
It makes a bundle harder to make templates. Ultimately, people will be able to make templates with a WYSIWYG editor (TinyMCE or similar). They can then go through and add in [[INV_NUM]] or [[MEM_NAME]] or one of a dozen other things.

They will then be able to preview these, and it'll highlight the bits that will ultimately change.

Finally, it'll email out to a bundle of people, with each one having their name or invoice number substituted in.

Zorilla
Mar 23, 2005

GOING APE SPIT
Makes sense. I suck at regular expressions, so you could probably do this for now:

php:
<?php
$template str_replace(
    "[[INV_NUM]]",
    "<span class=\"previewtag\">".$inv_num."</span>",
    $template
);
// fix all the false positives
$template str_replace(
    "<a href=\"http://site/invoice.php?i=<span class=\"previewtag\">".$inv_num."</span>",
    "<a href=\"http://site/invoice.php?i=".$inv_num."\">",
    $template
);
?>

It's probably inefficient as hell, but it will probably work until you can get a regular expression figured out later on.

Again, I'm bad as regular expressions and this is probably totally wrong, but maybe this will put you on the right path to finding the right one:

php:
<?php
// replace all instances of [[INV_NUM]] except those between < and >
$template preg_replace(
    "(?<!<)(?!>)(\[\[INV_NUM\]\])",
    "$1",
    $template
?>

Zorilla fucked around with this message at 14:36 on Dec 2, 2008

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



NoSpoon posted:

I've got a relatively simple (I hope) regular expression question...

I have some templates which are written like..

How about
php:
<?
//note the space before the first bracket
$tpl = str_replace(' [[INV_NUM]]',' <span class="previewtag">[[INV_NUM]]</span>',$tpl);
?>
or you could insert the real invoice number. No need to use regular expressions for this.

NoSpoon
Jul 2, 2004

Munkeymon posted:

How about
php:
<?
//note the space before the first bracket
$tpl = str_replace(' [[INV_NUM]]',' <span class="previewtag">[[INV_NUM]]</span>',$tpl);
?>
or you could insert the real invoice number. No need to use regular expressions for this.
Ultimately the mail will be sent out to dozens (well, a few more than that) of people, with their respective invoice numbers, names, email addresses, etc being substituted in.

The <span class> bit is only for a preview - so people can create a template, and see what it actually looks like, with the bits that will ultimately change highlighted (I do realise there's a WYSIWYG editor, but however - we want the [[STUFF]] highlighted).

Putting a space before it would probably work, but if someone bolds the invoice number on the templates - "Please pay invoice <strong>[[INV_NUM]]</strong> now" then it'd break.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



NoSpoon posted:

Ultimately the mail will be sent out to dozens (well, a few more than that) of people, with their respective invoice numbers, names, email addresses, etc being substituted in.

The <span class> bit is only for a preview - so people can create a template, and see what it actually looks like, with the bits that will ultimately change highlighted (I do realise there's a WYSIWYG editor, but however - we want the [[STUFF]] highlighted).

Putting a space before it would probably work, but if someone bolds the invoice number on the templates - "Please pay invoice <strong>[[INV_NUM]]</strong> now" then it'd break.

Oh, I thought from your description that you were maintaining full control of the templates until some indefinite time in the future where you had time to add features.

You could have 2 tags: [[INV_NUM]] and [[INV_URL]] so your users wouldn't have to know how to form a URL to the invoices and, if the pattern changes, could be blissfully unaware of it with no disruption in service:
code:
Hey, look!  <a href='[[INV_URL]]'>Invoice #[[INV_NUM]] is up!</a> Click on that poo poo, jerks.
It's easier to use and easier to parse.

bleh
Jun 13, 2003

This may be more html but I have a database that contains a field with upside down text using Unicode characters "IE: uʍop ǝpısdn sı sıɥʇ" how would I get the upside characters to display correctly using echo $upsidedowntext; . I know the variable is stored in the database correctly but when I display the variable I get "u?op ?p?sdn s? s???" am i missing some encoding I have to specify or something?

MrMoo
Sep 14, 2000

bleh posted:

I get "u?op ?p?sdn s? s???" am i missing some encoding I have to specify or something?
You're using MSIE by any chance? Make sure you mark the document as UTF-8 encoding, MSIE defaults to whatever ISO locale your desktop is.

fuck the ROW
Aug 29, 2008

by zen death robot
I'm not sure if this might be a more web dev question but - I'm trying to overlay a 50x50 png with another 50x50 png, the top png to have some transparency. Is there a way to do this with PHP, or maybe CSS (which I'd be generating with PHP anyway)?

Zorilla
Mar 23, 2005

GOING APE SPIT

gently caress the ROW posted:

I'm not sure if this might be a more web dev question but - I'm trying to overlay a 50x50 png with another 50x50 png, the top png to have some transparency. Is there a way to do this with PHP, or maybe CSS (which I'd be generating with PHP anyway)?
A simple copy ought to do it.
php:
<?php
$image1["data"] = imagecreatefrompng(BASE_IMAGE);
$image2["data"] = imagecreatefrompng(OVERLAY_IMAGE);

list($image1["x"], $image1["y"]) = getimagesize($image1["data"]);
list($image2["x"], $image2["y"]) = getimagesize($image2["data"]);

imagecopyresampled(
    $image1["data"],
    $image2["data"],
    0,0,
    0,0,
    $image1["x"],$image1["y"],
    $image2["x"],$image2["y"]
);
?>

I would just make sure the overlay image itself is partially transparent instead of setting it in PHP so there's only this amount of work involved.

You could totally do this with CSS intead though, and I prefer this since managing images is much easier when you don't have to apply gloss/whatever to each one:

code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<head>
<title>Title</title>
<style type="text/css">
div.image {
	overflow: hidden;
	position: relative;
	border: 1px solid #aaa;
}
span.gloss {
	position: absolute;
	display: block;
	left: 0;
	top: 0;
	width: 50px;
	height: 50px;
	background: transparent url(images/gloss.png) no-repeat scroll left top;
}
</style>
<!--[if lte IE 6]>
<style type="text/css">
/*
PNG transparency for IE6 and below. Search Google for iepngfix.htc and put it in
the same directory as this page. Be sure to include all elements that need it into
the following rule. For now, it's just span.gloss that needs it:
/* 
span.gloss {
	behavior: url(iepngfix.htc);
}
</style>
<![endif]-->
</head>
<body>
<div class="image">
	<img src="images/img-timeline.png" alt="" />
	<span class="gloss" />
</div>
</body>
</html>

Zorilla fucked around with this message at 22:18 on Dec 4, 2008

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Zorilla posted:


You could totally do this with CSS intead though, and I prefer this since managing images is much easier when you don't have to apply gloss/whatever to each one:

code:

Just remember that IE6 can't handle alpha channels in PNGs normally so you'll have to use that activex filter or reduce the top image to 8bit color.

Zorilla
Mar 23, 2005

GOING APE SPIT

duz posted:

Just remember that IE6 can't handle alpha channels in PNGs normally so you'll have to use that activex filter or reduce the top image to 8bit color.

Yeah, that slipped my mind for some reason while writing that at 5:30 in the morning. It's now fixed.

Zorilla fucked around with this message at 21:49 on Dec 4, 2008

ilikechapstick
Jun 17, 2007

very, very notorious.
I've just started to delve into using PHP5's simpleXML class and have a couple of questions. I am so used to using MySQL and just regular queries I am a little bit lost when it comes to 'querying' XML files themselves.

The basic structure of my XML file is something like this

php:
<?
<cgt>
<employee>
<username>blah</username>
<...lots of other tags>
</employee>
</cgt>
?>
Basically, I am building a directory that is based off an XML backend. The query I need to do would look something like this in SQL:

code:
SELECT * FROM employee WHERE username="blah"
Which would then allow me to use all of the nodes inside of that in this way, like I've been doing for the rest of my site. Here's a little example that just goes through and lists all the employees and some of their info.

php:
<?
    foreach($xml->employee as $employee) {
        $name = $employee->firstname;
        echo '<tr>';
        echo '<td><a href="view.php?id='.$employee->username.'">' . $employee->firstname . " " . $employee->lastname . '</a></td>';
        echo '<td class="email">' . $employee->email . '</td>';
        echo '<td>' . $employee->phone . '</td>';
        echo '</tr>';
    
?>
Ideally I would get all of the information and then just scatter $employee->NODENAME wherever I need the info.

But I am lost as to how to perform this 'query' with simpleXML. Do I have to use xpath or something?

ilikechapstick fucked around with this message at 21:43 on Dec 4, 2008

Zorilla
Mar 23, 2005

GOING APE SPIT

ilikechapstick posted:

Ideally I would get all of the information and then just scatter $employee->NODENAME wherever I need the info.

But I am lost as to how to perform this 'query' with simpleXML. Do I have to use xpath or something?
I'm reading this and it looks like you do.

php:
<?php
$xml simplexml_load_file("somefile.xml");
    or exit("File not found");
?>
<table>
    <tr>
        <th>Name</th>
        <th>Email</th>
        <th>Phone Number</th>
    </tr>
<?php
foreach ($xml->xpath("/cgt/employee[name='".$user_id."']") as $employee) {
?>
    <tr>
        <td><a href="view.php?id=<?php echo $employee->username?>"><?php echo $employee->firstname?> <?php echo $employee->lastname?></a></td>
        <td class="email"><?php echo $employee->email?></td>
        <td><?php echo $employee->phone?></td>
    </tr>
<?php
}
?>
</table>

I've never used SimpleXML before, so I have no idea if this example works exactly right.

Zorilla fucked around with this message at 03:04 on Dec 5, 2008

ilikechapstick
Jun 17, 2007

very, very notorious.
Ok, I think I actually found out something.

php:
<?
$xml->xpath("//*[username='".$userID."']");

$fullname = $xml->employee->firstname . $xml->employee->lastname;
?>
That actually selects the correct XML node based on ID. But when I try to assign values to variables based on it, it only pulls the first entry in the XML list, no matter what $userID is (userID is a $_GET variable from a previous page)

That code should insert the <firstname> and <lastname>'s of the person with the username of $userID, right? For some reason it's stopping at the first entry?

However, if I do a
php:
<?
print_r($xml->xpath("//*[username='".$userID."']"));
?>
It actually outputs the correct array for the userID, which seems odd.

EDIT: I'm dumb, never assigned the array to a variable!
php:
<?
$employee = $xml->xpath("//*[username='".$userID."']");

        $fullname = $employee[0]->firstname . $employee[0]->lastname;
        $email = $employee[0]->email;
        $phone = $employee[0]->phone;
        $fax = $employee[0]->fax;
?>

ilikechapstick fucked around with this message at 22:27 on Dec 4, 2008

Zorilla
Mar 23, 2005

GOING APE SPIT
edit: I can't read

edit2: though your corrections were kind of what I was alluding to

Zorilla fucked around with this message at 22:28 on Dec 4, 2008

ilikechapstick
Jun 17, 2007

very, very notorious.
Yeah, thanks for the inspiration.

Another question though. In my XML file, some professors have a tag like:
code:
<course name="xxx" link="http://www.xxx.com">Course Name Here</course>
While others do not teach any courses, so they don't have any of those items.

I successfully looped through and linked everything with this code
php:
<?
                        foreach ($employee[0]->course as $course) {
                            echo "<li><a href='" . $course->attributes()->link . "'>" . $course . "</a></li>";
                        }
?>
But how would I check if that tag doesn't exist? I want to put some default text in if they don't teach any classes.

jasonbar
Apr 30, 2005
Apr 29, 2005

ilikechapstick posted:

But how would I check if that tag doesn't exist? I want to put some default text in if they don't teach any classes.

Something like
php:
<?php
if (empty($employee[0]->course))
    echo "Your default text here.";
else
    foreach ($employee[0]->course as $course)
        echo "<li><a href='" $course->attributes()->link "'>" $course "</a></li>";
?>

fuck the ROW
Aug 29, 2008

by zen death robot

Zorilla posted:

A simple copy ought to do it.
php:
<?php
$image1["data"] = imagecreatefrompng(BASE_IMAGE);
$image2["data"] = imagecreatefrompng(OVERLAY_IMAGE);

list($image1["x"], $image1["y"]) = getimagesize($image1["data"]);
list($image2["x"], $image2["y"]) = getimagesize($image2["data"]);

imagecopyresampled(
    $image1["data"],
    $image2["data"],
    0,0,
    0,0,
    $image1["x"],$image1["y"],
    $image2["x"],$image2["y"]
);
?>

I would just make sure the overlay image itself is partially transparent instead of setting it in PHP so there's only this amount of work involved.

You could totally do this with CSS intead though, and I prefer this since managing images is much easier when you don't have to apply gloss/whatever to each one:

This is exactly what I was looking for - I had found examples of the CSS but this way fits what I'm doing a lot better, thanks a billion.

ilikechapstick
Jun 17, 2007

very, very notorious.
Now I have a new problem. I am trying to update a users password, and the XML file looks something like this:

code:
<users>
	<employee username="msarapin" password="msarapin" type="faculty" mode="user" />
</users>
Now here's what I have to update the password. Note the variable $password is a $_POST'ed variable from the form on the previous page.

php:
<?
// load the xml file
$xml = simplexml_load_file('xml/users.xml', 'SimpleXMLElement', LIBXML_NOCDATA);

// select the username 
$user = $xml->xpath("//*[@username='".$_SESSION["username"]."']");

//update the XML file, yeah right!
$user[0]->attributes()->password = '"'.$password.'"';
echo $xml->asXML();
?>
This XML stuff sure is frustrating...

ilikechapstick
Jun 17, 2007

very, very notorious.
Ok, I am going to stop posting these things. I figured it out.

php:
<?
$user[0]['password'] = $password;
file_put_contents('xml/users.xml', $xml->asXML());
?>
Maybe these are actually helpful to someone...

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof
I'm using a framework that handles database queries with prepared statements. Lately I've been struggling with huge dynamic queries that need to swap joins and other clauses based on various conditions. It's a major headache to do it by manipulating strings. I've looked at ORM frameworks like Propel, but they seem like more trouble than they're worth for this project. All I really need is a library that helps me generate dynamic SQL without forcing me to append strings and fight over misplaced clauses and commas.

My current solution is a class that works something like this:

php:
<?
$select = new Select();
$select->table('customer');
$select->field('customer.name', 'customer.email');
$select->order('customer.name');
$select->where('customer.country = ?', 'US');
if ($user == $not_an_administrator) {
    // Add a join and a where clause to filter for customers that belong to
    // this user
    $select->innerJoin('representative', 'representative.id = customer.repid');
    $select->where('representative.id = ?', $userid);
}
?>
I'm sure I've seen this type of thing before, but I can't find a decent version of it. Google searches turn up stuff that's lamer than the version I slapped together in an hour. Does anyone know of a mature library for this type thing? I'd rather not spend a bunch of time developing my own, but I don't want a framework that requires a bunch of boilerplate, either.

karms
Jan 22, 2006

by Nyc_Tattoo
Yam Slacker
You just need to know the right search terms.

DaTroof
Nov 16, 2000

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

I'm looking for something to help me build dynamic SQL queries against arbitrary table definitions. An ORM framework isn't out of the question, but the actual object-relational mapping isn't the important feature to me. I've browsed the documentation for Doctrine and Propel, but

quote:

I don't want a framework that requires a bunch of boilerplate

Adbot
ADBOT LOVES YOU

Whilst farting I
Apr 25, 2006

What's the easiest way to get just the current formatted system timestamp?

Instead of something like

2006-09-19 16:56:56

just

16:56:56

Here's what I have

code:
<?php
  
  $temptime = time();
  
  $time = strtotime($temptime);
  
  echo "$time";
?>
And it outputs 1228593110 so I'm a bit lost. I've spent at least a half an hour reading up on strtotime, time, and gettimeofday and I'm still utterly confused.

Whilst farting I fucked around with this message at 20:59 on Dec 6, 2008

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