|
Thanks. Out of curiosity, that code snippet at the end,php:<? echo Xhtml::create('img') ->setAttribute('src', 'images/happycat.jpg') ->setAttribute('alt', 'A Happy Cat') ->addClass('align_right') ->addClass('drop_shadow') ->render(); ?>
|
# ? Jun 26, 2009 19:02 |
|
|
# ? May 15, 2024 11:35 |
|
Because I made my functions return $this each time I can chain them like that. Its also why I used a create() function to call the constructor (you cannot do new Xhtml()->func() it will not work) Interestingly... I executed that code before I posted it, and it works fine. Yet I had left off the static keyword in front of the create() function. Yet its callable statically. Every day I find some new oddity in PHP... Its a nice construct for things you are going to use and discard immediately.
|
# ? Jun 26, 2009 19:18 |
|
Golbez posted:This is more general programming theory, but what is the best way to handle data in an object? Have a generic record and functions to handle it, or make a separate function for each piece of data? Since you seem to be using PHP5, have you thought about using __get, __set and __call instead?
|
# ? Jun 27, 2009 20:17 |
|
EDIT: Nevermind. Just a server config issue.
Recycle Bin fucked around with this message at 06:17 on Jun 28, 2009 |
# ? Jun 28, 2009 04:28 |
|
I'm currently using ADODB to handle MySQL abstraction on my website but I recently updated to PHP5 and thought it might be a better idea to use something like mysqli or PDO. Which of the two should I use to handle all my MySQL transactions? If it matters, I use "update" a lot.
|
# ? Jul 1, 2009 03:01 |
|
PDO.
|
# ? Jul 1, 2009 03:34 |
|
mysqli. Edit: OK, so this is just a bitchy response to the above, why PDO?
|
# ? Jul 1, 2009 05:20 |
|
Golbez posted:why PDO? Less chunky than Pear:B_DataObject and reasonable parameter and exception handling? PDO::FETCH_CLASS is very convenient too.
|
# ? Jul 1, 2009 05:42 |
|
Edit: PDO is nice, I'm sure. I just don't like the verbosity. And 90% of the servers I work on are on RHEL<=5.
Tad Naff fucked around with this message at 05:57 on Jul 1, 2009 |
# ? Jul 1, 2009 05:44 |
|
MrMoo posted:Less chunky than Pear:B_DataObject and reasonable parameter and exception handling? PDO::FETCH_CLASS is very convenient too. But the question was PDO vs mysqli, not PDO vs Pear.
|
# ? Jul 1, 2009 06:07 |
|
Doesn't mysqli force you to bind variables?
|
# ? Jul 1, 2009 06:11 |
|
I'd hate to be a bitch two posts in a row, but there's really already a ton of discussion on the subject: http://www.google.com/search?q=mysqli+vs+pdo My personal preference is PDO because I feel it's API is much nicer to work with than mysqli.
|
# ? Jul 1, 2009 06:21 |
|
gibbed posted:Doesn't mysqli force you to bind variables? Doesn't force it, no. You have the choice to send a straight query string, or to bind variables. That said, I'm near giving up on it, due to this monstrosity I've spent the last few minutes creating: php:<? $query = 'UPDATE tblcases SET CaseType = ? ,UserID = ? ,UserEmail = ? ,UserCompany = ? ,UserName = ? ,UserPhone = ? ,DateOpened = ? ,DateClosed = ? ,Resolution = ? ,Question = ? WHERE CaseID = ?'; $mysqli = new InternalDBConnection; $stmt = $mysqli->prepare($query); $stmt->bind_param('iisissssssi' ,$this->getData('CaseTypeID') ,$this->getData('UserID') ,$this->getData('UserEmail') ,$this->getData('UserCompany') ,$this->getData('UserName') ,$this->getData('UserPhone') ,$this->getData('DateOpened') ,$this->getData('DateClosed') ,$this->getData('Resolution') ,$this->getData('Question') ,$this->getData('CaseID')); $stmt->execute(); ?> Zend_DB is looking kind of nice. I think I need a beer.
|
# ? Jul 1, 2009 06:40 |
|
Golbez posted:just to realize that bind_param probably doesn't work that way; for it to work, I'll have to load all of those getDatas into individual variables, then bind THOSE. Yet I still want to have a secure input; back to mres() for me, I guess. Oh, and a new one: Apparently mysqli_bind_param doesn't support NULLs! Well that's just loving great. So now I have to dynamically edit the query as well?
|
# ? Jul 1, 2009 07:19 |
|
Though in retrospect there's really no reason for me to use "getData" and "setData"; all those commands do is verify the array key exists in $Record. I could just have public variables like, y'know, $UserID, $CaseTypeID, etc. Would make the sanitize function a little more complicated (having to run specifically on each variable, rather than just pass an array to it), but it might make life simpler. And since most of what sanitize() does is escape it, I could skip that if I'm still parameterizing. Thoughts? Edit: Or I could skip using the functions to read its own data and pass the Record directly. Duh. Golbez fucked around with this message at 08:08 on Jul 1, 2009 |
# ? Jul 1, 2009 07:56 |
|
Hmmm. Binding parameters one by one is a little troublesome, but then again I only need to bind three or four at max... If using adodb seems to be "slow" would that be an issue with adodb or MySQL?
|
# ? Jul 1, 2009 09:36 |
|
Likely your queries/tables/datbase. Define "slow".
|
# ? Jul 1, 2009 09:49 |
|
It takes a few seconds every once and awhile but not always.
|
# ? Jul 1, 2009 13:14 |
|
Golbez posted:Though in retrospect there's really no reason for me to use "getData" and "setData"; all those commands do is verify the array key exists in $Record. I could just have public variables like, y'know, $UserID, $CaseTypeID, etc. Would make the sanitize function a little more complicated (having to run specifically on each variable, rather than just pass an array to it), but it might make life simpler. And since most of what sanitize() does is escape it, I could skip that if I'm still parameterizing. The idea of using prepared statements is that the API does the escaping for you, you shouldn't need to do any sanitizing as far as database security (but still want to check user input for validity). Personally I used PDO or Zend_DB (which you can have ride on top of PDO). Also, its really easy to extend PDO or Zend_DB into your own subclasses, which is extremely handy. With Zend_DB you don't have to use the entire gay framework, just the DB library, and you can do stuff like this, but still have the power to write your own SQL statements when needed. code:
|
# ? Jul 1, 2009 14:30 |
|
I *like* writing queries. Why do all these advanced things take that tiny joy away from me?
|
# ? Jul 1, 2009 18:36 |
|
drcru posted:I'm currently using ADODB to handle MySQL abstraction on my website but I recently updated to PHP5 and thought it might be a better idea to use something like mysqli or PDO. Stick with ADODB if you can. Its still a fine library.
|
# ? Jul 2, 2009 01:23 |
|
Golbez posted:I *like* writing queries. Why do all these advanced things take that tiny joy away from me? You still can with PDO if you want. You can do stuff like this, and it will still do all the data cleansing. $sql = "INSERT into mytable(field) VALUES(@field)"; Then you can do $stmt->bindValue("@field", $value); (probably not exact syntax, but something similar).
|
# ? Jul 2, 2009 14:32 |
|
I'm stumped on this, I'm not a big fan of loops in php because they seem to go horribly wrong, but I'm trying to do a simple preg_replace on tags that a matched through regex on an included file, now its not that it doesn't work, its that the final result sets all the name fields with just 1 variable. This is the actual function. php:<? $type = "[a-zA-Z]*"; $tag = "[a-zA-Z]*"; $pattern = "/({)(?:(".$type.")[_](".$tag."))(})/"; $text = file_get_contents("template.html"); preg_match_all($pattern,$text,$matches); $i=0; foreach($matches as $foo => $bar){ $replaced = preg_replace($pattern,"<select name='".$matches[3][$i]."'>".$matches[2][$i]."</select>",$text); $i++; } echo $replaced; ?> code:
Am I doing this the wrong way or something else?
|
# ? Jul 4, 2009 14:24 |
|
ATM Machine posted:I'm stumped on this, I'm not a big fan of loops in php because they seem to go horribly wrong, but I'm trying to do a simple preg_replace on tags that a matched through regex on an included file, now its not that it doesn't work, its that the final result sets all the name fields with just 1 variable. Basically each time through the loop you're replacing all occurrences of the matching pattern with the current drop/xTime pair, so at the end you're given all occurrences that originally matched the pattern replaced with the last one. You want to create a second search for the specific occurrence as you loop through each match. Also, when doing a $key => $value pair loop, $key is the index. So in this case, $foo and $i are the same thing. Try this code out: php:<?php $type = "[a-zA-Z]*"; $tag = "[a-zA-Z]*"; $pattern = "/({)(?:(".$type.")[_](".$tag."))(})/"; $text = file_get_contents("template.html"); preg_match_all($pattern,$text,$matches); foreach($matches[2] as $foo => $bar) { $sub_pattern = "/({)(?:(".$matches[2][$foo].")[_](".$matches[3][$foo]."))(})/"; preg_match_all($sub_pattern,$text,$sub_matches); $text = preg_replace($sub_pattern,"<select name='".$sub_matches[3][0]."'>".$matches[2][0]."</select>",$text); } echo $text; ?>
|
# ? Jul 4, 2009 15:08 |
|
ATM Machine posted:I'm stumped on this, I'm not a big fan of loops in php because they seem to go horribly wrong, but I'm trying to do a simple preg_replace on tags that a matched through regex on an included file, now its not that it doesn't work, its that the final result sets all the name fields with just 1 variable. Well, the immediate good news is you don't need a loop to do a working version of what you have: php:<? $replaced = preg_replace('/{([a-zA-Z]+)_([a-zA-Z]+)}/', '<select name="$2">$1</select>', $text); ?> But I don't see any attempt to create the <option> tags in your code, and you will need a loop to do that (probably). Lets assume you can get that content into $uwStart for {drop_uwStart}, don't you want something more like this? php:<? $matches = array(); $hits = preg_match_all('/{drop_([a-zA-Z]+)}/', $text, $matches); if($hits > 0) { foreach($matches[1] as $match) { if(isset($$match)) { $text = str_replace('{drop_'.$match.'}', '<select name="'.$match.'">'.$$match."</select>", $text); // when we match {drop_uwStart} $match is "uwStart" so $$match is $uwStart // you could also setup $associative_array['uwStart'] and use $associative_array[$match] instead of $$match } } } ?>
|
# ? Jul 5, 2009 00:21 |
|
Ferg posted:helping KuruMonkey posted:helping Both help, but yeah, I do want to put options in the select fields. The current way was to call the function that did the options seperately and that'd print off the list, but I hadn't thought about how to go about adding the options in, I knew calling the function probably wouldn't work but I'm out of my area of how I used to code, I'm just trying to break out of the <html><?php $foo ?></html> system I have so that I can reuse and manage similar code easier. So anything more on this is me learning. And yeah, I'm terrible with loops, I just figured that seeing as what I was aiming for was going to be, find tag -> set the variables -> a loop to fill with options -> next tag, but I think I've missed the mark with this. EDIT: I actually tried calling my function in Fergs suggestion and it prints the time correctly, but only the first part of the array, but at least its not doing nothing on me. The result is <select name='uwStart'><option value='0000'>0000</option></select> which is pretty much spot on, but because return ends the function straight away, it stops at the first result, and echo just lumps everything up the top of the page instead of where its called ATM Machine fucked around with this message at 03:57 on Jul 5, 2009 |
# ? Jul 5, 2009 03:25 |
|
Because of duz, I looked into using __get and __set, and kind of like them. However, I'm running into a problem:php:<? $stmt->bind_param('iisi',$this->Type,$this->UserID,$this->UserEmail,$this->UserCompany); ?> code:
On a similar note, is there any way to see the raw query text of a query mysqli has just executed? It would help with debugging.
|
# ? Jul 8, 2009 19:05 |
|
I'm trying to get his php mailer to work, but forever reason it just won't. Everything looks right to me. I grabbed it off another forum, did some slight changes, they had some errors, but no dice. Any help would be appreciated. <?php $Subject = "Test E-mail"; $toEmail = "********@gmail.com"; if($submit) { $resultMail = mail($toEmail, $Subject, $nMessage); if($resultMail) { print "Your e-mail has been sent."; } else { print "Your e-mail has not been sent."; } } ?> <html> <head> <title>Mail Tutorial</title> </head> <body bgcolor="#FFFFFF"> <form method="post" action="<?php echo($PHP_SELF) ?>"> Your E-mail: <input type="text" name="fromEmail" size="25"> <br> Your Name: <input type="text" name="fromName" size="25"> <br> Your Message: <br> <textarea cols="50" rows="5" name="nMessage">Your Message Here...</textarea> <br> <input type="submit" value="submit" name="submit"> </form> </body> </html>
|
# ? Jul 8, 2009 22:43 |
|
SpoonsForThought posted:I'm trying to get his php mailer to work... Just to get the easy guess out of the way, is your code on a Windows server (or your own (Windows) computer)? mail on a Linux server basically just hands off to a native command that does a lot of stuff for you, but Windows is different because you're actually delivering it to an SMTP server. If you're on Windows, make sure all line endings are \r\n and not just \n, and make sure php.ini is modified as appropriate.
|
# ? Jul 8, 2009 23:45 |
|
Supervillin posted:Just to get the easy guess out of the way, is your code on a Windows server (or your own (Windows) computer)? mail on a Linux server basically just hands off to a native command that does a lot of stuff for you, but Windows is different because you're actually delivering it to an SMTP server. I'm new to php so I'll answer these the best I can. I use a Mac, and I'm not sure of the server type as it is my university's web space that I'm uploading to. There is literally one line about the server and it says it supports PHP scripting. SpoonsForThought fucked around with this message at 01:05 on Jul 9, 2009 |
# ? Jul 8, 2009 23:54 |
|
SpoonsForThought posted:I'm new to php so I'll answer these the best I can. (and of course, don't leave that script there, remove it when you're done)
|
# ? Jul 9, 2009 00:50 |
|
gibbed posted:Upload a PHP script with the contents <?php phpinfo(); and access it. The output of phpinfo should give sufficient information about the server and php's configuration. Ok information: It is a Linux server, with PHP Version 5.2.4. What else should I be looking for? Here is my code, a thanks goes DarkLotus for helping me out. For whatever reason, it doesn't work on this server but he says it runs fine on his. Here is the code: code posted:
|
# ? Jul 9, 2009 01:18 |
|
SpoonsForThought posted:Here is my code, a thanks goes DarkLotus for helping me out. For whatever reason, it doesn't work on this server but he says it runs fine on his. Here is the code: What's the result? Do you get "Your email has not been sent" or just nothing? If nothing, add this as the first line after <?php: code:
|
# ? Jul 9, 2009 02:56 |
|
I get these before I even submit: Notice: Undefined index: fromEmail in /export/webhome/*****/web_pages/request/test.php on line 5 Notice: Undefined index: fromName in /export/webhome/*****/web_pages/request/test.php on line 6 Notice: Undefined index: nMessage in /export/webhome/*****/web_pages/request/test.php on line 7 Notice: Undefined index: submit in /export/webhome/******/web_pages/request/test.php on line 12 And then when I try to submit: The requested URL /*****/request/<br /><b>Notice</b>: Undefined variable: PHP_SELF in <b>/export/webhome/*****/web_pages/request/test.php</b> on line <b>37</b><br /> was not found on this server. The ***** being my username/etc.
|
# ? Jul 9, 2009 05:26 |
|
SpoonsForThought posted:The requested URL /*****/request/<br /><b>Notice</b>: Undefined variable: PHP_SELF in <b>/export/webhome/*****/web_pages/request/test.php</b> on line <b>37</b><br /> was not found on this server. SpoonsForThought posted:<form method="post" action="<?php echo($PHP_SELF) ?>"> $PHP_SELF should be $_SERVER['PHP_SELF'] Also, you can just try this script to see that mail() actually works without worrying about the rest of your script potentially breaking or mis-directing. If that doesn't work your university may have blocked access to sendmail. When hosting companies do this they usually provide access to an alternative, like PEAR mail. http://pear.php.net/package/Mail php:<? mail($your_email, "Test", "Test Message"); ?> jasonbar fucked around with this message at 08:21 on Jul 9, 2009 |
# ? Jul 9, 2009 08:12 |
|
Is there anyway to do the following with PDO? Original Array ( [0] => Array ( [map_id] => 1 [name] => Peanut Butter [width] => 25 [height] => 15 [start_sector] => 1 ) [1] => Array ( [map_id] => 2 [name] => Cold Lamb Sandwhich [width] => 11 [height] => 15 [start_sector] => 376 ) ) Array Index is map_id Array ( [1] => Array ( [name] => Peanut Butter [width] => 25 [height] => 15 [start_sector] => 1 ) [2] => Array ( [name] => Cold Lamb Sandwhich [width] => 11 [height] => 15 [start_sector] => 376 ) ) I'm using fetchAll(PDO::FETCH_ASSOC) right now.
|
# ? Jul 9, 2009 09:48 |
|
drcru posted:Is there anyway to do the following with PDO? I don't believe so. But it is pretty easy to create a function that will take your array from pdo and spit out your new fancy array. Like code:
|
# ? Jul 9, 2009 14:18 |
|
jasonbar posted:$PHP_SELF should be $_SERVER['PHP_SELF'] I did that. Nothing happens, no errors, but yet no e-mail comes. php:<? mail("****@gmail.com", "Test", "Test Message"); ?> Notice: Undefined index: fromEmail in /export/webhome/*****/web_pages/request/requestwinders.php on line 6 Notice: Undefined index: fromName in /export/webhome/*****/web_pages/request/requestwinders.php on line 7 Notice: Undefined index: fromCompany in /export/webhome/******/web_pages/request/requestwinders.php on line 8 Notice: Undefined index: fromPhone in /export/webhome/*******/web_pages/request/requestwinders.php on line 9 Notice: Undefined index: whichProduct in /export/webhome/******/web_pages/request/requestwinders.php on line 10 Notice: Undefined index: literature in /export/webhome/*******/web_pages/request/requestwinders.php on line 11 Notice: Undefined index: pricing in /export/webhome/*******/web_pages/request/requestwinders.php on line 12 Notice: Undefined index: contact in /export/webhome/******/web_pages/request/requestwinders.php on line 13 Notice: Undefined index: nMessage in /export/webhome/******/web_pages/request/requestwinders.php on line 14 And here is the php: php:<? error_reporting(E_ALL); $Subject = "ONLINE INFORMATION / SALES REQUEST"; $toEmail = "******@gmail.com"; $fromEmail = $_POST['fromEmail']; $fromName = $_POST['fromName']; $fromCompany = $_POST['fromCompany']; $fromPhone = $_POST['fromPhone']; $whichProduct = $_POST['whichProduct']; $literature = $_POST['literature']; $pricing = $_POST['pricing']; $contact = $_POST['contact']; $message = wordwrap($_POST['nMessage'], 70); $headers = "From: \"$fromName\" <$fromEmail> \r\n" . "Company: \"$fromCompany\" <$fromPhone> \r\n" . "Request: \"$whichProduct\" <$literature> <$pricing> <$contact> \r\n" . "Reply-To: \"$fromName\" <$fromEmail> \r\n" . 'X-Mailer: PHP/' . phpversion(); if(isset($_POST['submit'])) { $resultMail = mail($toEmail, $Subject, $message, $headers); if($resultMail) { print "Your e-mail has been sent."; } else { print "Your e-mail has not been sent."; } } ?>
|
# ? Jul 9, 2009 21:15 |
|
Begby posted:I don't believe so. But it is pretty easy to create a function that will take your array from pdo and spit out your new fancy array. Like Thanks, I did something like that instead. Is there a nicer way to do this? php:<? function rekey($array) { $out = array(); $max = count($array); for($i = 0; $i < $max; $i++) { $keys = array_values($array[$i]); if(is_numeric($keys[0])) { array_shift($array[$i]); $out[$keys[0]] = $array[$i]; } } return $out; } ?>
|
# ? Jul 10, 2009 00:33 |
|
|
# ? May 15, 2024 11:35 |
|
SpoonsForThought posted:NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE To get rid of the notices, just move all your variable declarations into the if (isset($_POST['submit'])) block. You only need those if the form is being processed anyway. It's still strange that you'd get NOTHING though, if there's no warning but mail() fails you should hit the "Your e-mail message has not been sent" block. Try this to see if it even starts processing the form: php:<? if(isset($_POST['submit'])) { // (right here is where you put the variable assignments, by the way) print 'Submit value: ' . $_POST['submit']; $resultMail = mail($toEmail, $Subject, $message, $headers); if($resultMail) { print "Your e-mail has been sent."; } else { print "Your e-mail has not been sent."; } } ?>
|
# ? Jul 10, 2009 07:50 |