Jump to content

arianhojat

Members
  • Posts

    235
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

arianhojat's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. Think it has to do with i have some select queries above it... if i try to spit out error with: $stmt = $pdo->query( 'SELECT simple_operation(5) as x' ); if (!$stmt) { echo "\nPDO::errorInfo():\n". $pdo->errorCode().'...'; print_r($pdo->errorInfo()); } it says: "DO::errorInfo(): HY000...Array ( [0] => HY000 [1] => 2014 [2] => Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. )" Setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY as recommended didnt work either or using fetchAll's for all queries Hmmmm, will take a look.... http://www.phpbuilder.com/board/showthread.php?t=10360219 http://bugs.php.net/bug.php?id=44081
  2. Hey all, Im having no problems with stored procedures in PDO, but stored functions are giving me hell... I have this mysql stored func to test that just returns simple value: DELIMITER $$ DROP FUNCTION IF EXISTS `simple_operation` $$ CREATE DEFINER=`root`@`localhost` FUNCTION `simple_operation`(price int) RETURNS int(11) RETURN price*1000 $$ DELIMITER ; and here is my code to actually get the value... The 2 ways that Im trying to query + get the value work fine standalone in the mysql query browser, so how the heck i do this in php? <?php $user = "yoink"; $pass = "yoink"; $pdo = new PDO('mysql:host=localhost;dbname=test', $user, $pass); //none of these work, but the queries work fine standalone in the mysql query browser foreach($pdo->query( 'SELECT simple_operation(5) as x' ) as $row) { print_r($o); } $stmt = $pdo->prepare("SELECT simple_operation(?) as x"); $val=5; $stmt->bindParam(1, $val); $stmt->execute(); while ($row = $stmt->fetch()) { echo print_r($row); } $pdo->prepare("SET @x=simple_operation(5)"); foreach($pdo->query( 'SELECT @x' ) as $row) { print_r($o); } for comparision, the stored procs are easy to call: print '<h3>PDO: calling sp with 'out' variables</h3>'; $pdo->query( 'CALL get_user(1, @first, @last)' ); foreach($pdo->query( 'SELECT @first, @last' ) as $row) { debug($row); } print '<h3>PDO: calling sp returning a recordset</h3>'; foreach($pdo->query( 'CALL get_users()' ) as $row) { debug($row); }
  3. Wow that makes alot of sense, thanks wildteen88, you are some sort of Golden God! I praise your holy statue from now on.
  4. Didnt work. You just added brackets around the 'else' statement, right? Which arent needed for 1 line else statement anyway. Thanks for trying but i think its something bigger that im not seeing/understanding how pass by reference works in php. You can see at the end of the code the subarrays required fields arent modified, even though when it handles the subarrays it looks like it does change them. Anyone got ideas?
  5. I am making a recursive function to modify an array, and its not modifying the arrays under the main array. So like when the function approaches a subarray, it recursively calls the function passed by reference.... i see then it changes that subarray via 'CHANGED array...' called right after it hits the required field in that subarray. But when that subarray gets done, and it then prints 'CHANGED array...' for the array again, it doesnt change the sub value. the initial parent #required value is the only one changed permanently for some reason; Not sure why cause even recursively it should respect the '&' pass-by-reference sign in the function parameters right? code is attached if u want to run and let me know what the hecks i doing wrong... <?php function unset_required_fields(&$array){ foreach( $array as $key=>$value) { echo '#KEY being looked at: ['.$key.']<br/>'; echo '$array be4:<pre>'.htmlspecialchars(print_r($array, true)).'</pre><br/>'; if( is_array($value) ) { echo 'RECURSE, look at array under ['. $key .']...'.'<br/>'; unset_required_fields($value); } else if( $key == 'required') { echo 'CHANGED array, value for this "required" key should now be 0!!!'.'<br/>'; $array[$key] = 0; //'#required' } else echo 'Nothing cool happens since not an array or required field'.'<br/>'; echo '$array AFTER:<pre>'.htmlspecialchars(print_r($array, true)).'</pre><br/>'; } } $thearray = array( 'title' => "Here are some radio button questions", 'required' => 1, 'weight' => 2, 'child 1' => array( 'title' => "Radio button 1 question: blah blah?", 'required' => 1, 'weight' => -1 ), 'someotherparameters0' => 0, 'child 2' => array( 'title' => "Radio button 2 question: blah blah?", 'required' => 1, 'weight' => -1 ), 'someotherparameters1' => 0, 'someotherparameters2' => "bleh" ); unset_required_fields($thearray); ?> [attachment deleted by admin]
  6. Flash is cool if you can do that. never tried this, but looks cool and configurable if u know a lil flash and stuff: http://backspace.com/mapapp/ but i think since there is no meaty info, Leaving this info in image is prob fine. might want to google css image maps (http://www.alistapart.com/articles/imagemap/), but i think not needed in this case.
  7. I figured out I can maybe just use a javascript version of htmlspecialchars() and that seemed to sanitize things well without funky things happening... Any reason why this is this a bad solution? function htmlspecialchars(string, quote_style) { // http://kevin.vanzonneveld.net // + original by: Mirek Slugen // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // * example 1: htmlspecialchars("<a href='test'>Test</a>", 'ENT_QUOTES'); // * returns 1: '<a href='test'>Test</a&gt' string = string.toString(); // Always encode regex = /&/g; string = string.replace(regex, '&'); regex = /</g; string = string.replace(regex, '<'); regex = />/g; string = string.replace(regex, '>'); // Encode depending on quote_style if (quote_style == 'ENT_QUOTES') { regex = /"/g; string = string.replace(regex, '"'); regex = /'/g; string = string.replace(regex, '''); } else if (quote_style != 'ENT_NOQUOTES') { // All other cases (ENT_COMPAT, default, but not ENT_NOQUOTES) regex = /"/g; string = string.replace(regex, '"'); } return string; }
  8. whenever i need to output a variable in html, i make sure to use php htmlspecialchars() like so: echo '<select id="entityText" name="entityText">'; while( $row= mysql_fetch_assoc($result) ){ $TextfromDatabase = $row['entityText']; echo '<option value="'.htmlspecialchars($TextfromDatabase).'">'. htmlspecialchars($TextfromDatabase) .'</option>'; } echo '</select>'; .... echo '<div id="addEntityDiv">'; foreach($_GET['customParams']['Entities'] as $entitytext)//btw this is called if there is an error on the form, so adds submitted info back to form... (Code isnt shown here but if no errors, form is redirected somewhere else.) { echo '<input type="hidden" name="customParams[Entities][]" value="'. htmlspecialchars($entitytext) .'"/>'; echo '<div>'. htmlspecialchars($entitytext) .'</div>'; } echo '</div>'; So to get those customParams[Entities][] values to even exist, a user clicks on a select option and presses an add button, and some javascript creates those form elements like so: var entitytext = jQuery('#entityText').val(); jQuery('<input type="hidden" name="customParams[Entities][]" value="'+ entitytext +'"/>').appendTo("#addEntityDiv"); jQuery( '<div>'+ entitytext +'</div>').appendTo('#addEntityDiv'); I think the part that gets me if there are funky characters in the initial select box: like pretend one of the select options in database is for some reason something funky like: <' AlternativeEnergy "> Then the option's value for it is <option value="<' AlternativeEnergy ">"> since it gets htmlspecialchar-ized. So when no matter what the javascript looks like below (tried them all), it messes up the values outputted to screen and the hidden input: jQuery( '<div>'+ entitytext +'</div>').appendTo('#addEntityDiv'); jQuery( '<div>'+ escape(entitytext) +'</div>').appendTo('#addEntityDiv'); jQuery( '<div>'+ unescape(entitytext) +'</div>').appendTo('#addEntityDiv'); It will output since its not escaping stuff correctly for example: "/> <' AlternativeEnergy "> and when posted (and error occurs), it also will mess up and output something wrong also since that foreach($_GET['customParams']['Entities']...) gets called. Any ideas how to use escaping efficiently in php/javascript combined? PS all the ', ", and > (qoutes and greater than/less than signs ) are literal in the output i give as an example. the phpfreaks forums did a good job of sanitizing my post
  9. Hey fenway, When i run that on respected table, i get: | Table | Op | Msg_type | Msg_text | +------------------------+-------+----------+-------------------------------------------------+ | thedatabase.thetablename | check | error | Can't open file: 'thetablename.ibd' (errno: 1) | any ideas? i am on Windows Box, and MYSQL 4.1.12a-nt
  10. Can you set the company id in the tbl_contact table to be Index key (not Primary, just set to Index)? I assume result_link is Primary or Index-ed field' are these MyISAM databases or InnoDB? maybe set to MyISAM too if dont need foreign keys, etc.
  11. This table has not been openable for months, I try doing a SELECT * FROM the_table and get an error that "Can't open file: 'the_table.ibd' (errno: 1)" not sure what to do. ill be fine with deleting it, and rebuilding it. trying to but delete it gives me a "MYSQL 1051 ERROR, unknown table 'the_table'", however it still shows up in my MYSQL Query Browser screen. Cant do a CREATE either, says table already exists haha. I googled around for months off and on, maybe has something to do with deleting certain files in the database .frm or .ibd values maybe? Finally need to use that table again, so hence why i delayed looking into it for so long.
  12. hey fenway, Thought HAVING was only for GROUP BY statements?
  13. hello all, I want to do a query using an alias of a subquery value like so : SELECT t1.evaluationID, t1.clientID , (SELECT t2.employeeID FROM table2 t2 WHERE t2.somefield=t1.somefield) as evaluator FROM table1 t1 WHERE evaluator=23 but i get an error that evaluator is an unknown column. is there anyway to do this without resulting to SELECT t1.evaluationID, t1.clientID , (SELECT t2.employeeID FROM table2 t2 WHERE t2.somefield=1) as evaluator FROM table1 t1 WHERE (SELECT t2.employeeID FROM table2 t2 WHERE t2.somefield=1)=23 which works... Currently using mysql 4.1.12a-nt Thanks for any help.
  14. Basically instead of having many columns in a table, when user saves data, i put user submitted data in a php serialized array in a mysql field for later reference. Now I have to do a complex query where i want to do pretend ... $field = serialized($row['data']); $approved = $field['userapproved']; ...'WHERE userapproved='. $approved; But id prefer to do it with a pure mysql query. Is this possible? Id rather not do it with php logic like i have been doing, seems like ill be doing alot of checks when trying to build something like pagination in a search query.
  15. Saw a recent article on the Bakery http://bakery.cakephp.org/articles/view/setting-up-eclipse-to-work-with-cake ... Wasnt sure if someone else set up the same with phpeclipse, easyEclipse, or Eclipse all in one install with PTO. Their article does PTO. I was having some issues, so was wondering what IDE setups you have for cake (steps would be appreciated). Even his article on how a project gets setup i didnt fully understand how to setup many projects locally. i have seen tutorials where each website is in its own directory in root (standard like on a host that handles multiple domains), and cake1.1 and cake1.2 folders are in their own directories under a cake folder pretend in root. and you can go into each websites app/webroot/index.php and configure Cake path to the version that website uses. But that was on a hosting setup. To work locally it think each website has a project folder, and i guess cake versions are outside of this folder, but added as a project to include path. he didnt elaborate too much on how he sets up website projects locally. he has 1 core cake folder, pointing to the current projects path? seems like i didnt interpret it correctly as then you would need to change the path each time working on new cake project. and i would assume u want the opposite, all things pointing from project path to cake core libs. "I follow the Cake convention of storing all my CakePHP projects in the Cake root directory (making a copy of /app, renaming it, and changing the constant APP_DIR in /app/webroot/index.php to the name of my directory). You should probably follow this convention as well." so u would have if listened to the instructions: /cake /app (points to current project i am working on in eclipse?) /proj1_com /proj2_com
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.