ruano84 Posted November 2, 2006 Share Posted November 2, 2006 Hi,I am having throuble with a temporary table. I can create it, fill it and even select it, but every time i access it, the data is corrupted. This is the code to create it:(The query is supposed to be ?sec=xx&art=yy&cant=zz)[code]<?php$ref=apache_request_headers();setcookie("origen",$ref['Referer']);setcookie("query",$_SERVER['QUERY_STRING']);session_start();if(!isset($_SESSION["nombre"])){ session_write_close(); header("location:ingresar.php"); //To the registration page}else{ $dbh=mysql_pconnect ("localhost", "interglo_admin") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db("interglo_Users"); $id=session_id(); parse_str($_COOKIE["query"]); mysql_query("CREATE TEMPORARY TABLE IF NOT EXISTS cart$id (cat char(255),id int, cantidad int)"); mysql_query("INSERT INTO cart$id (cat,id,cantidad) VALUES ('$sec','$art','$cant')"); header("location:".$_COOKIE["origen"]);}?>[/code]And this is the code for access it:[code]<?phpsession_start();if($err==0){ $_SESSION["nombre"]=$row[0]." ".$row[1]; $_SESSION["cedula"]=$row[2]; $_SESSION["fijo"]=$row[3]."-".$row[4]; $_SESSION["cel"]=$row[5]."-".$row[6]; $_SESSION["direccion"]=$row[7]; $_SESSION["email"]=$row[8]; if(isset($_COOKIE["query"])) header("location:add.php?".$_COOKIE["query"]);} if($_SERVER['QUERY_STRING']=="sec=v_cart"){ $dbh=mysql_pconnect ("localhost", "interglo_admin") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("interglo_Users"); echo mysql_error(); $res=mysql_query("SELECT * FROM cart$id"); //The shopping cart echo mysql_error(); $aff=mysql_affected_rows(); echo $id." ".$aff."<br>"; echo mysql_error(); if($aff==0){ ?> Aún no has agregado artículos a tu carro de compras.<br> <?php }else{ $dbh1=mysql_connect("localhost","interglo_admin"); mysql_select_db("interglo_productos"); //The products for($i=0;$i<$aff;$i++){ $fetch=mysql_fetch_row($res); echo $i." ".$fetch[0]." ".$fetch[1]."<br>"; $res1=mysql_query("SELECT * FROM ".$fetch[0]." WHERE id=".$fetch[1]); echo mysql_error(); $fetch1=mysql_fetch_row($res1); echo $fetch1[1]." ".$fetch[2]." ".$fetch[3]."<br>"; } }$id=session_id();[/code]I hope somebody can help meAlexis RR Quote Link to comment Share on other sites More sharing options...
fenway Posted November 2, 2006 Share Posted November 2, 2006 How can it be corrupted if you can't create/select from it? How are you accessing it? Quote Link to comment Share on other sites More sharing options...
gluck Posted November 2, 2006 Share Posted November 2, 2006 persistent connections with temporary tables will cause problems. The connection between apache's process and mysql is persistent. Now when you connect through the other page you may or may not use the same apache process. Quote Link to comment Share on other sites More sharing options...
ruano84 Posted November 2, 2006 Author Share Posted November 2, 2006 sorry i write it wrong (cant instead of can), but i modified it already. Quote Link to comment Share on other sites More sharing options...
fenway Posted November 2, 2006 Share Posted November 2, 2006 Then I don't understand what you mean by "corrupted"... how? Quote Link to comment Share on other sites More sharing options...
gluck Posted November 2, 2006 Share Posted November 2, 2006 After creating modifying etc. can you select it at the same page?If you can on the same page but can't on the other then the script is not accessing the same temporary tables. Temporary tables last just a session and should be destroyed the moment you close the connection. Quote Link to comment Share on other sites More sharing options...
ruano84 Posted November 3, 2006 Author Share Posted November 3, 2006 Hi, thanks for answer.In the script i create the table and insert the data, when i select, everything is fine, like a normal table. When i select the same table with the pconnect function (it's supposed to give me a reference of the last one), sometimes output that the table doesn't exists, sometimes it selects but retrieve just the first x rows and sometimes the data is ok.Thanks again,Alexis RR Quote Link to comment Share on other sites More sharing options...
gluck Posted November 4, 2006 Share Posted November 4, 2006 p connection messes up stuff at times :) Quote Link to comment Share on other sites More sharing options...
fenway Posted November 4, 2006 Share Posted November 4, 2006 Make sure that everything is well behave without persistent connections, so that we can establishing that it's not a MySQL issue. Quote Link to comment Share on other sites More sharing options...
gluck Posted November 4, 2006 Share Posted November 4, 2006 It is a pconn issue. Temp tables will not be available to two different sessions otherwise. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.