Jump to content

arianhojat

Members
  • Posts

    235
  • Joined

  • Last visited

    Never

Everything posted by arianhojat

  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
  16. I am moving many hundreds of files over. and i was wondering should i scp everything over and then chmod all the files to the user:group= apache:apache with something like 'commandLine> chmod * 644'. I think when scp-ing them over, they get the user and group of me so when moved into apache web folder, apache doesnt have the rights/permissions to even show the files. Should i just 644 everything? Any specific kinda things gotta watch out for? Dont think there are any read-only files that I would want to keep read only. Would the whole code written with Window's encoding becoming an issue (with line-ends)? Thanks, Arian
  17. Before when php was on a IIS box at work, I just authenticated a person by looking at $_SERVER['AUTH_USER'] (which is magically provided by this Windows box to php even though its not the server doing authentication on our network), then getting their info from that like domain/username (cut out the username with substring), then looking in our mysql windowslogon JOIN userinfo table to find that username and some extra info associated them to store in session so pages on the intranet can access some useful data about the user. But we want to move to a Linux box for our web server... Someone recommended to me Active Directory for authentication... i see that you should setup a user in A.D. for php web scripts to connect and get info. so pretend i did that. but how you can query the database to ask what the current user is? seem like you can only get information by supplying parameters in with php LDAP functions but i dont know if u can ask what current signed in user is. i saw some other options to possibly use NTLM authentication on linux with an apache module called mod_auth_ntlm_winbind. i dunno what is better way to do authenication (without user ever needing to sign into anything)? Any suggestions? if suggest LDAP/Active Directory, can help with simple example how to get signed in user username?
  18. so mysql_fetch_assoc is like a cursor then going through the data straight from the database resource. But then shouldnt this be called unbuffered? instead of buffered result as it seems people agree on that it is?
  19. Sorry to bang out any more answers from ya PhREEEk... So just to clarify for my own curiousity... The resource identifier is pointing to the first record like stated above, but also all data is passed in memory to the variable also on that one mysql_query line (for the while loop to loop over). Because when i asked if the loop [w/ mysql_fetch_assoc] if its bringing data over from mySQL, you said yes, which i intrepreted as it is asking the resource for data from mySQL versus asking for data that is already brought over from mySQL in memory. PhREEEk, So as the while loop is looping, data is being brought over from MYSQL (from a temp table as someone stated) or everything has already been brought over (from a temp table) in the mysql_query line (the latter is what i assume, aka buffered)? Thanks again for clarification, PhREEEk Just curious what happens behind the scenes as it is interesting
  20. just wondering on page 87 of the book Object Oriented PHP, it says the result set returned by mysql_query, all rows, are buffered in memory. "..Your result set is buffered. it was created using the function mysql_query. Because a buffered result set stores all roews in memory, the record pointer can be repositioned [by mysql_data_seek]" So is it just a resource pointer to 1st record? if so, why does the above seem to contradict that.
  21. Daniel0, if ($connection == 'hello'), then its passed by reference, right since value was changed by function? (i think your example had opposite) Anyway tested it out... <? function test($var) { $var = 'hello'; } $connection = mysql_connect($host, $user, $pass) or die("Unable to connect!"); //also tested with object: $connection = new mysqli($host, $user, $pass); echo $connection ."<br/>"; test($connection); echo $connection ."<br/>"; and get Resource#1 each time, so the connection isnt passed by reference unless explicit in function definition.
  22. cool, didnt see resources are Passed by Reference in php manual i have downloaded. thanks Daniel0 and roopurt18.
  23. PhREEEk, So as the while loop is looping, data is being brought over from MYSQL?
  24. So is a mysql resource connection viewed as an object then? it was created via mysql_connect(); i know mysqlI(mproved) in php manual says it returns an object. but regular mysql_connect which is what they use returns a 'MySQL resource link identifier'. Can this be viewed as an object then?
  25. I assume number 2 just wanted clarification. $sql = "SELECT * FROM sometable"; $result = mysql_query($sql); // At this point is all data sent to client ready to be looped through in $result? while ($row = mysql_fetch_assoc($result)) //or is data gotten from mysql now { echo $row["userid"]; echo $row["fullname"]; echo $row["userstatus"]; } is there anyway where you dont get all data sent to you at once, so you can go along as needed (kinda like goings though xml with SAX versus DOM )?
×
×
  • 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.