PHP - Runing Out Of Memory In Pdo Insert [merged With Previous Thread]
finally got some time to code
anyway i cant figure out why this doesnt work, i think its an error in my logic...
<?php $db = new PDO('mysql:host=localhost; dbname=test;', 'root', ''); $db2 = new PDO('mysql:host=localhost; dbname=test2;', 'root', ''); foreach($db->query('SELECT * FROM database1 LIMIT 1') as $row) { $thing1 = $row['COL 1']; $thing2 = $row['COL 2']; $thing3 = $row['COL 4']; $thing4 = $row['COL 6']; $thing5 = $row['COL 7']; $content = "\"big text with $things\""; addslashes($content); $db2->exec("INSERT INTO database2(col1,col2,col3) VALUES ('$thing1','text','$content')"); } ?>my foreach command should read all lines from database one and write one by one on database two? thx in advance Similar Tutorialshow do i insert this into a database? i need the php code please. Code: [Select] <select class="select" name="sex" id="sex"> <option value="0">Select Gender</option> <option value="1">Female</option> <option value="2">Male</option></select>I need it to insert what ever one they select Thanks Hey guys and gals, Here's my problem. I just finished programming an online game and I have some php script that generates xml files. Well, to do this, I type in the address of the file on the server and pass it to variables in the addressbar. It then queries a database and does everything fine and dandy. Problem is, I need it to do that automatically. I cannot be sitting at my computer 24-7 typing stuff in the address bar. Is there a way I can run the php script and pass those variables automatically? I have PHP and MYSQL Web Development Fourth Edition by Luke Welling and Laura Thompson I am on Chapter 9 Creating Your Web Database on Page 230 my -h host -u bookorama -D boos -p < bookorama.sql I have been tring to make this code work for 3 weeks and no luck. Can anybody Help Me on this line. They are not clear enough on this line but the book is an awesome book, learning alot. Advice please. I am setting up a new machine here and I can't remember which to download. What information do you need to be aware of to know whether to install 'non thread safe' or 'thread safe'. I did some googling but didn't find anything that was clear. And is 5.3 good to go or should I stick with 5.2. Thanks in advance for your input! I've already made fully working create topic, etc; what would I need to make to reply to a thread? I've gotten this so far... <?php $result = mysql_query("SELECT id FROM b ORDER BY id DESC"); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf("<a href='reply.php?id=%s'>Reply</a><hr><br /><br />", $row[0]); } mysql_free_result($result); ?> reply.php?id=%s (%s equaling the thread id) when I click it, it does bring me to the appropriate page, but I don't know where to go from there. Any help? any other info you might need just ask i got the below code from google, need to adapt it to use, it works, but i just need it to over write on the file instead of appending to the file , please help, i am not a coder nor understand much of this, if someone could change it for me please: function logText($text) { $ts = date("D d-m-y h:i A",time()); $toLog = "[" . $ts . "] " . $text; $fh = fopen("logFile.txt", 'a'); fwrite($fh, $toLog."\n"); fclose($fh); }Edited December 13, 2020 by requinix Hi all i am working on forum and i am close to testing stage and right now i am fighting serious bugs with $_GET ... http://hostings.flush.ws/?section=forumview&id=1 [you can manipulate the values and create unknown threads in unknown forums ] http://hostings.flush.ws/?section=forumthreadsubmit&id=1 [you can manipulate the values and create unknown threads ] also can mix both and get like backdoor trojan without admin knowledge if ($id = ((isset($_GET['id'])) && (ctype_digit($_GET['id'])) ? (int)$_GET['id'] : '')) { true; } else { echo $redirect.false; } Sow if somebody could show example how to counter attack value changing You can login in web with user help pass help12 address http://hostings.flush.ws/?section=news Hello everyone, it's my first post here. I was recommend this community for it's professionalism and "friendlyness". During my stay here, please excuse my english. I know it can be unpleasant for you to read a thread with terrible grammar, I hate it in my native language, I'll do my best. Okay, so I'm having two major issues for my website to operate like I'd like it to, I've done everything I knew about, and I can't think about anything else Google didn't help me much either this time. First one is that I seem to have a cookies/sessions problem. Well, I use Liberty Reserve to allow my members to top up their account. So I send my form to their SCI and when I either cancel or complete a transaction, I return to my website but I'm not logged in anymore! So the auto-add to balance system can't work. Alright, when I saw this I was only using sessions, so I added cookies so I could rely on them too. And there again, same thing. Doubled, tripled checked all the LR settings and everything, I know they are right. But what's really, really, weird to me and what's really doing my head in is that I'm not actually logged out, because if I use another tab/window I'm still logged in. In other words, it's only the window coming back from Liberty Reserve that won't log in. The cookies are still here and so is the session so... Another terrible thing is that it used to work when I was on my previous host (just moved to a dedicated server, which may be causing the problems, it's the first time I administrate a dedi). This is blocking my entire website from working. And my second problem is with the function mail() -there again 'caused' by new server-. I don't get any error message, or anything. The e-mails with cPanel/WHM work great. Though, I have done several tests and it never reaches my Gmail, Hotmail or Yahoo account. It did work with a Yopmail inbox though. So, I was focusing on 'why isn't it sending it' but since I just noticed it worked with Yopmail, I'm sure it is sending it and have no ideas why wouldn't it work with other e-mail service providers. I hope you understood what I meant and that, hopefully, you guys can help me out with those totally handicapping issues. Thank you, Regards. -Ben. Solution: Turns out the headers will not send unless all of the other code is behind an else userinfo.php?user=MikeH, possible addition to the sticked post? So strictly speaking I dont have a header error because my script does not produce errors. However my script should be redirecting me to "notes.php?error=ad" but instead it just sends me back to the page I was previously at. My script is made to process a download via "tokens" and then redirect the user. That all works fine but what I am trying to do now is check if the user has already about the download and if they have redirect them to the error page letting them know. So in short the URL goes like this: notes.php?viewn=2 -> purchase.php?user=MikeH&nid=2 (unseen page all processing) -> notes.php?error=ad however what it is doing is: notes.php?viewn=2 -> purchase.php?user=MikeH&nid=2 (unseen page all processing) -> notes.php?viewn=2 Here is the notes code: <?php }else if (isset($_GET['viewn'])){ $cid = $_GET['viewn']; $query = "SELECT * FROM approvednotes WHERE cid =".$cid; $res = mysql_query($query) or die (mysql_error()); $i=0; $r=1; ?> <h2>Programs:</h2> <table summary="Summary Here" cellpadding="0" cellspacing="0"> <tr> <td><b>File Name</b></td> <td><b>Author</b></td> <td><b>Cost</b></td> <td><b>Buy</b></td> </tr> <?php echo "<tbody>"; echo "<tr class= \"dark\">"; while ($row = mysql_fetch_array($res)){ if($i == 1){ echo "</tr>"; $r++; if($r% 1 == 0){ echo "<tr class = \"light\">"; $i=0; $r = 0; }else{ echo "<tr class = \"dark\">"; $i=0; } } echo "<td> ". $row['name']."</td><td>".$row['username']."</td><td>".$row['value']." <img src=\"images/money.png \" height=\"30px\" /></td><td><a href=\"purchase.php?user=".$session->username."&nid=".$row['id']."\"><img src=\"images/buy.png\" height=\"30px\"/></a></td>"; $i++; } echo "</table>"; }?> Here is the purchase code: <?php include("include/session.php"); if($session->checkLogin()){ $user= $_GET['user']; if ($user == $session->username){ $note = $_GET['nid']; $query3 = "SELECT * FROM users_downloaded WHERE nid=$note AND username='$user'"; $res3 = mysql_query($query3) or die (mysql_error()); $pass = mysql_num_rows($res3); if ($pass != 0){ header("Location: notess.php?error=ad"); } $nquery = "SELECT * FROM approvednotes WHERE id= ".$note; $nres = mysql_query($nquery) or die (mysql_error()); //Get info about the file while ($nrow = mysql_fetch_assoc($nres)){ $price = $nrow['value'] ; $location = $nrow['location']; } //see if user even has enough credits for this function creditcheck($username){ $usern= $_GET['user']; $query = "SELECT * FROM users WHERE username = '".$usern."'"; $res = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($res)){ $credits = $row['credits']; } return $credits; } $credits = creditcheck($user); if($credits >= $price){ //user has enough credits to purchase note. $newamount = $credits - $price; $person = $session->username; $query = "UPDATE users SET credits =".$newamount." WHERE username='$person'"; $res = mysql_query($query) or die (mysql_error()); $query2 = "INSERT INTO users_downloaded (nid, username) VALUES ('$note','$person')"; $res2 = mysql_query($query2) or die (mysql_error()); header("Location: download.php?f=".$location); exit; }else{ //error not enough money!! header("Location: notes.php?error=ne"); } } }else{ header ("Location: notes.php?error=nl"); } ?> Mmm i'm not sure if i'm approaching this correctly. Anyways, I wanted to create a multi-level thread, Where the child thread would be after the parent thread. Something like this: Hello World - Hello World - Hi! - What's up? - Hi Bob! Goodbye World - ....This guy got issues - Dude! You should watch Despicable Me! "It's so fuzzy i'm going to dieee!" Anyways, so my table looks something along the line of this: | post id | parent_id | title | body | date | 1 | NULL | Hello | Hi, i'm K | date 2 | NULL | Thread One | Body One | date 3 | 1 | Hello World | Body One | date 4 | 2 | Thread post 4 | Body One | date 5 | 1 | Thread post 5 | Body One | date 6 | 1 | Thread post 6 | Body One | date 7 | 3 | Hi What's up | Body One | date And here's the PHP code, although it's not very neat I want to clean it up and make it neater. I can only go two level deep so far. Any suggestion or recommendations? Using while & for: // Select * Threads $q = "SELECT * FROM test_db ORDER BY post_id ASC"; $r = @mysql_query($q); while ($pid_row = @mysql_fetch_object($r)) { // Array $pid_arr[] = $pid_row->post_id; // Assign Indexes to Post ID $ppid_arr[] = $pid_row->parent_id; // Assign Indexes to ParentID $md_arr = array($pid_arr, $ppid_arr); // Create multi-dimensional array matrix $parent_id = $pid_row->parent_id; } for ($i = 0; $i < count($pid_arr); $i++) { for ($a = 0; $a < count($ppid_arr); $a++) { $pid = $pid_arr[$i]; // pid = post id $ppid = $ppid_arr[$i]; // ppid = parent id //echo "<div>~~ PID $pid ~~ PPID $ppid ~~</div>"; if ($ppid === NULL) { $ppid_is_null = " & parent_id is NULL"; } else { $ppid_is_null = NULL; } // Select Top level Thread $z = "SELECT * FROM test_db WHERE post_id = '$pid'"; $y = @mysql_query($z); while ($t_row = @mysql_fetch_object($y)) { $title = $t_row->title; // title of child thread $level = $t_row->level; // level of child thread...is this useful? } // Display top level thread lvl 1 if ($ppid === NULL) { // If the parent_id is NULL, display top level thread echo '<div>PID: ' . $pid . ' || PPID: ' . $ppid . " || Title: " . $title . "</div><br>\n"; $post = $pid; // PostID = 1 $parent = $ppid; // Parent ID ex: [1] // Get child id, where parent id = [1] // trying to get the child thread here...but it's not working $child_q = "SELECT * FROM test_db WHERE parent_id = '$post'"; $child_r = @mysql_query($child_q); while($c_row = @mysql_fetch_object($child_r)) { $c_arr[] = $c_row->post_id; $c_ppid_arr[] = $c_row->parent_id; } for ($n = 0; $n < count($c_arr); $n++) { if ($c_ppid_arr[$n] === $post) { echo "<div>$c_arr[$n]</div>"; } } break; //echo "<div>PID: $pid</div>"; } break; } } Using While: <?php require_once('db_connection'); echo '<hr><hr><br>'; // I just realized that selecting * where parent id is null might limit the amount of rows retrieved. // Query to select threads $n = NULL; $q = "SELECT * FROM test_db WHERE (test_db.parent_id is NULL) Order By date ASC"; $r = @mysql_query($q); while ($threads = @mysql_fetch_object($r)){ $pid = $threads->post_id; $sid = $threads->subject_id; $parent_id = $threads->parent_id; $title = $threads->title; $body = $threads->body; echo '<div>PostID: ' . $pid . ' || Parent: ' . $parent_id . ' || SubjectID: ' . $sid . ' || Title: ' . $title . ' || Body: ' . $body . '</div>'; $q2 = "SELECT * FROM test_db WHERE parent_id = '$pid' Order by date DESC"; $r2 = @mysql_query($q2); while ($level2 = @mysql_fetch_object($r2)) { $level2_pid = $level2->post_id; $level = 1.5 *($level2->level); // lvl 2: 3em echo '<div style="text-indent:' . $level . 'em">' . 'PostID: ' . $level2->post_id . ' || ParentID: ' . $level2->parent_id . '</div>'; $q3 = "SELECT * FROM test_db WHERE parent_id = '$level2_pid'"; $r3 = @mysql_query($r3); while ($level3 = @mysql_fetch_object($r3)) { $level3 = 1.5 + $level; echo '<div style="text-indent:' . $level3 . 'em">' . 'PostID: ' . $level3->post_id . ' || ParentID: ' . $level3->parent_id . '</div>'; } } } ?> I'm not a comp. sci major or anything, so I'm learning this as I go. Any help would be greatly appreciated. It seems like the while & for is more practical, but i'm not quiet sure. What am I doing wrong? - K I just joined this forum today ^_^ Hope to be good friends with you guys and gals I am in the midst of developing a web application and despite having a decent amount of experience in web development, I never really stopped and gave a ton of thought to memory when it comes to my php scripts. However, with this project I am using zend framework and it is a decent memory hog. So I have some questions... I am monitoring my memory use for a typical call to my site and it appears as though its somewhere around 20MB. This seems like a ton and I am actively looking for ways to decrease it. One thing I noticed is that when I call zend's date class for the first time, my memory usage shoots up 3MB. However it is pretty much untouched for other instances of this class. So if I do Code: [Select] echo(memory_get_usage()); echo('<br />'); $this->last_login=Zend_Date::now(); echo(memory_get_usage()); echo('<br />'); $this->last_active=Zend_Date::now(); echo(memory_get_usage()); echo('<br />'); The result is Quote 9136448 12812408 12814496 So the jump is with that first call. My question is, if two users are accessing the site at the same time, will they both experience that 3MB memory use? Or will the server have that class in memory so it only uses 3MB once? Basically, if a call to the site uses 20MB of memory, will it be 20MB * the number of users. Or will the server have a lot of the information loaded into memory to subsequent calls so multiple users would use up far less memory then the initial? I would assume the latter is the case based on the fact that reusing zend_date doesn't incur a 3MB hit every time. But without being admin of my server and hvaing tons of folks to test at once, its hard to tell. Just how big can i make this ? Im sure it depends on the server hardware and if thats the case then how does one fidn out how big I can make this. I want to max it out. -SB Hey guys i have been making a website where friends can post on each others profiles like facebookish anyways im not sure if this is th ebest way to do it but i have this below its part of the code that pulls all the friends of the member from the database:: $query_friend = mysql_query("SELECT my_id,friend_id FROM site_friends WHERE my_id='$my_id'"); while($row = mysql_fetch_assoc($query_friend)){ $friend_id = $row['friend_id']; } then i pass it into a function blah blah not got that for yet anyway what happens if this person ends up having 100s of friends will this be harsh on the servers memory? or should i not worry to much ? hope someone can help thanks!! Hello Guys, I wanted to know what is memory leakage? Where we have to takecare of ? How to avoid this thing? I have osTicket installed on a Centos 5 Os with php5.3.3
I upgraded the osTicket from v1.9.1 to 1.9.4
I now get the following mail when I create a ticket by mailing in the support ticket
This is the mail system at host mail.mydomain.com.
I'm sorry to have to inform you that your message could not be delivered to one or more recipients. It's attached below.
For further assistance, please send mail to <postmaster>
If you do so, please include this problem report. You can delete your own text from the attached returned message.
The mail system
<support@mydomain.com>: Command died with status 255: "/usr/bin/php -q
/var/www/html/support/api/pipe.php". Command output: PHP Fatal error:
Allowed memory size of 268435456 bytes exhausted (tried to allocate 76
bytes) in /var/www/html/support/include/class.osticket.php on line 261 PHP
Warning: Unknown: Error occured while closing statement in Unknown on line
0
The osticket guys have pointed out to me that this is a php error, but I never made any changes to the php config
When I increase the memory in php.ini to 512Mb or even 1024Mb the error persists.
Anyone have any ideas of whether the memory is set/can be set somewhere else or overriding what is in php.ini ?
Hi: How do I set up an input textbox so that it remembers the text a user entered? Code: [Select] <form name="form1" method="post" action="<?=$_SERVER['PHP_SELF']?>" > <input name="myguess" type="text" value=""> <input type="hidden" name="allTheGuesses" value = ""> <input type="submit" value="GUESS"> </form> I can't seem to figure it out I have a 2-D array that holds a table of information that is stored in a $_SESSION array variable. If all the information in the table is correct, then it should be added to a database. If not correct, it will be sent to a page to be modified. There are a total of three pages: AddInformation.php ProcessInformation.php EditInformation.php Table array is created from a form on AddInformation.php. ProcessInformation.php checks for the validity of the information. And EditInformation.php allows you to update the errored information. A $_SESSION array that is Array[5][9] stops at ProcessInformation.php and doesn't bothering using the header('Location: EditInformation.php') that it is supposed to use. The only difference between the start memory usage and the end memory usage is of 5kb. As far as I know there is enough memory on the operating machine. Is there a way to fix this? Edit: I do not have direct access to the server or its terminal. I have this method that puts files into a zip file from an array list, it looks like this: public function zip($files = array(), $maxMB = 2, $flag = ZIP_NEW){ $this->memory_size = $maxMB * 1024 * 1024; $zip_id = $this->zip_id; $this->zip[] = new ZipArchive(); $this->zip_id++; if($flag == ZIP_NEW){ $open = $this->zip[$zip_id]->open("php://temp/maxmemory:$this->memory_size", ZipArchive::CREATE); $files = (array)$files; if(!empty($files)){ foreach($files as $file){ if(is_file($file)){ $this->zip[$zip_id]->addFile($file); } } } $this->zip[$zip_id]->close(); } $this->function_name = __FUNCTION__; return $this; } I then download them like this: public function download($download_data, $download_name, $type = DOWNLOAD_FILE){ header("Pragma: public;"); header("Expires: 0;"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0;"); header("Content-Type: application/force-download;"); header("Content-Type: application/octet-stream;"); header("Content-Type: application/download;"); header("Content-Transfer-Encoding: binary;"); header("Content-Disposition: attachment; filename=$download_name;"); if($type == DOWNLOAD_FILE){ header("Content-Length: ".filesize($download_data).";"); if($download_data == PHP_MEMORY){ $handle = fopen(PHP_MEMORY."/maxmemory:$this->memory_size", 'r+'); echo stream_get_contents($handle); }else{ readfile($download_data); } }elseif($type == DOWNLOAD_STRING){ header("Content-Length: ".mb_strlen($download_data).";"); echo $download_data; } $this->function_name = __FUNCTION__; return $this; } When I run this code: $files = array("file1.php","file2.php"); $live->zip($files)->download(PHP_MEMORY, "download.zip"); It downloads the file, the only problem is, is that when I open the file I get an error saying the file can not be opened. I know when I actually save it to a file instead of in memory it works. So, I am not sure if it isn't working in the download portion or the create file portion, as I have never worked with php://temp before. Any thoughts on why this doesn't work when using php://temp? What happens if you do not unset an array before the script is done executing? I am running through thousands of CSV files, parsing data for hundreds of thousands of customers. It works fine for the first 5/6 hours then starts bogging down bad. I run about 5-10 CSVs per execution...I'm wondering if unsetting the arrays in the script would help this or not...I thought they would be unallocated after the script ends. Am I wrong? Hi, I'm getting following error on my website Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 36000000 bytes) in /var/www/vhosts/celebratingart.com/1DEV_CELEBRATINGART/judges/phpimageeditor/classes/phpimageeditor.php on line 652 I tried to increase memory limit to 256M but invain. Please Help |