[PHP-DB] How use select for update
I m trying to make a program with PHP and Oracle I want to use an "Select for upate" But when i send the command, it doesn t lock my "table" If someone can help me -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: search query
On Wed, 15 Sep 2004 23:30, Peppe wrote: > Hi > I have a option box with values > > Less than 150.000 > tot 175.000 > tot 200.000 > tot 250.000 > tot 300.000 > tot 350.000 > tot 400.000 > More than 400.000 > > I need help when the user chose option value 3 till 200.000 than the query > should search between 175.000 and 200.000 how to achive this > Regards SELECT fields FROM table WHERE something BETWEEN 175.000 AND 200.000 More information at http://dev.mysql.com/doc/mysql/en/Comparison_Operators.html or see the docs for whatever other database you use. -- David Robley "What's the value of a dollar bill?" asked Tom noteworthily. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Accessing Matisse DB
Petrus Ali Saputra wrote: John Holmes wrote: Petrus Ali Saputra wrote: Petrus Ali Saputra wrote: Is there anyone here can tell me how to access Matisse DB? Thank you. Isn't there anyone can help me? ODBC? Yes, but it will lower the ability of Matisse. Sorry, you did not phrase that in the form of a question. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Accessing Matisse DB
John Holmes wrote: Petrus Ali Saputra wrote: Petrus Ali Saputra wrote: Is there anyone here can tell me how to access Matisse DB? Thank you. Isn't there anyone can help me? ODBC? Yes, but it will lower the ability of Matisse. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] RE: [SPAM] Re: [PHP-DB] Using sessions to gather visitor information
John and everyone else, thanks for all the help. Here is what I have for code. Again you help is greatly appreciated. "; echo $_SESSION['user_agent'] . ""; echo $_SESSION['host_name'] . ""; echo $_SESSION['visit_time'] . ""; } // look for db entry $IpSearch = mysql_query("SELECT ip, time FROM visitor where ip = {$_SESSION['ip_address']}"); $Results = mysql_fetch_row($IpSearch); if($Results) { // need to figure out how to check if time greater than 24 hours from now // if greater than 24 hours do: $UpdateVisit = mysql_query("UPDATE visitor SET time = '$_SESSION['visit_time']', visitcount = /* add +1 */ WHERE ip = $_SESSION['ip_address']"); } else { $InsertVisit = mysql_query("INSERT INTO visitor (ip, agent, host, time, visitcount) VALUES ($_SESSION['ip_address'], $_SESSION['user_agent'], $_SESSION['host_name'], $_SESSION['visit_time'], '1' "); ?> -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] replacing dynamic variable in preg_replace
Steve Morgan wrote: I am working on a script which takes a list of variables form a database. The problem i am currently having is some of the variables have other variables in the content , i.e. $temp="$title" (made up example), is something that might come out of the mysql. $query=mysql_query("SELECT `code`,`varname` FROM `k_sys`"); while(list($code,$var)=mysql_fetch_array($query)){ $code=str_replace("-user-",USER,$code); $code=preg_replace("/--(\w+)--/","$$1",$code); // PROBLEM $$var=$code; } is the current code, i'm setting off variables with a --, so if variables $title, is in the mysql, the above example would be --title-- instead. When i do the above i would just get like $title as an output. I think its due to how mysql is storing the information, but a stripslashes didnt work. If anyone can help it'd be much appreciated. preg_replace('/--(\w+)--/e','$$1',$code); -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Newby variable error
Hi, first step in debugging...learn to love the var_dump() function :) just add the following code to the do_calculate.php function ... "; // set up the pricing assignments ... This will display what is held in your $_POST variable. When you run the script at the start of your output will be the following array(2) { ["beans"]=> string(16) "Ethiopian Harrar" ["quantity"]=> string(1) "3" } Notice that beans and quantity are in double quotes. From now it should be east to fix ;) graeme. W Roothman wrote: Wizards, I am VERY new to PHP, paging through Meloni's 'PHP Essentials' I get the following error which I assume is very simple to solve, but for me. I have tried different approaches in identifying the 'price' variable with no luck: error: Notice: Undefined variable: price in c:\inetpub\wwwroot\php exercises\do_calculate.php on line 20 Notice: Undefined variable: price in c:\inetpub\wwwroot\php exercises\do_calculate.php on line 24 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] replacing dynamic variable in preg_replace
I am working on a script which takes a list of variables form a database. The problem i am currently having is some of the variables have other variables in the content , i.e. $temp="$title" (made up example), is something that might come out of the mysql. $query=mysql_query("SELECT `code`,`varname` FROM `k_sys`"); while(list($code,$var)=mysql_fetch_array($query)){ $code=str_replace("-user-",USER,$code); $code=preg_replace("/--(\w+)--/","$$1",$code); // PROBLEM $$var=$code; } is the current code, i'm setting off variables with a --, so if variables $title, is in the mysql, the above example would be --title-- instead. When i do the above i would just get like $title as an output. I think its due to how mysql is storing the information, but a stripslashes didnt work. If anyone can help it'd be much appreciated. Steve Mo'gan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Accessing Matisse DB
Petrus Ali Saputra wrote: Petrus Ali Saputra wrote: Is there anyone here can tell me how to access Matisse DB? Thank you. Isn't there anyone can help me? ODBC? -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Accessing Matisse DB
Petrus Ali Saputra wrote: Is there anyone here can tell me how to access Matisse DB? Thank you. Isn't there anyone can help me? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Newby variable error
Wizards, I am VERY new to PHP, paging through Meloni's 'PHP Essentials' I get the following error which I assume is very simple to solve, but for me. I have tried different approaches in identifying the 'price' variable with no luck: error: Notice: Undefined variable: price in c:\inetpub\wwwroot\php exercises\do_calculate.php on line 20 Notice: Undefined variable: price in c:\inetpub\wwwroot\php exercises\do_calculate.php on line 24 You ordered 1 bags of Ethopian Harrar. Bags of Ethopian Harrar are R0.00 each. Your subtotal is R0.00. Sales tax is 14% in this location. R0.00 has been added to your order. You owe R0.00 for your coffee. code: show_calculate_b.php Bean Counter Form Select a bean type: Ethiopian Harrar - $14.25 Kona - $16.25 Sumatra - $13.00 How many bags would you like? 1 2 3 4 5 do_calculate_b.php Bean Counter Results You ordered $_POST[quantity] bags of $_POST[beans]."; echo "Bags of $_POST[beans] are \$$fmt_price each."; echo "Your subtotal is \$$fmt_sub_total."; echo "Sales tax is $sales_tax_pct% in this location."; echo "\$$fmt_sales_tax_amount has been added to your order."; echo "You owe \$$fmt_grand_total for your coffee."; ?> Regards and many thanks, Will
[PHP-DB] Limiting records per page
I have written a script that will display the contents of a MYSQL database that starting to fill up. I would like to be able to only show about 20 records per page and then at the bottom of the page there will be buttons to move to the nest page which gets the next 20 records. I understand the LIMIT command, but I am questioning how all of this is going to work. I am unsure of how to change the SQL query on same page like that. Can anyone give me some suggestions. Thanks, Aaron -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] PHP 5 Error Handling
guys thanks for the responses, i am sure i may be able to parse the results of $e->getTrace() to get the results i want ;) On Wed, 15 Sep 2004 09:25:05 -0500, Gary Every <[EMAIL PROTECTED]> wrote: > Good question. I've tried the __LINE__ and __FILE__ in my > error-handling, but it does the same thing you're experiencing, getting > the line in the function/method as opposed to the actual error line. The > only way I've gone around it is whenever there may be an exception, such > as a sql statement, etc I assign $line_no = __LINE__ and if an exception > gets thrown, the $line_no is captured, and I can use the info to print > to the logs or the screen or ... > > G. > > Gary Every > Sr. UNIX Administrator > Ingram Entertainment Inc. > 2 Ingram Blvd, La Vergne, TN 37089 > "Pay It Forward!" > > > > > -Original Message- > From: Joseph Crawford [mailto:[EMAIL PROTECTED] > Sent: Tuesday, September 14, 2004 5:55 AM > To: [PHP-DB] Mailing List > Subject: [PHP-DB] PHP 5 Error Handling > > Guys, > > i have been working with custom exception classes that extend the > general exception. Here is some code i have > >public function command($cmd) { >if($cmd) { >$res = fputs($this->connection, $cmd); >$this->response = fgets($this->connection, 128); >switch($this->getCode()) { >case 500: >throw new CommandException($cmd); >break; >} >} >} > >public function selectGroup($group) { >$this->group = $group; >if(substr($this->response,0,3) == "200") { > >THIS IS THE LINE THAT THROWS THE ERROR >$this->command("NoSuchCommand\n"); > >$this->response = fgets($this->connection, 1024); >} >$info = split(" ", $this->response); > >$this->first = $info[2]; >$this->last = $info[3]; >} > > now when the error is thrown and i do $e->getLine(); it shows the line > of the file where the throw statement is. Is there a way to make it > show the actual line number of the line that is the error? the > $this->command("NoSuchCommand\n"); line. > > -- > Joseph Crawford Jr. > Codebowl Solutions > [EMAIL PROTECTED] > 802-558-5247 > > For a GMail account > contact me OFF-LIST > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Joseph Crawford Jr. Codebowl Solutions [EMAIL PROTECTED] 802-558-5247 For a GMail account contact me OFF-LIST -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Totally lost on why If statement doesn't work to call query
whoa! It looks like a space. no? results of echo var_dump($z): string(4) "C " I'll try a trim statement. thanks! John Holmes <[EMAIL PROTECTED]> wrote: From: "Karen Resplendo" > $data5=odbc_do($connectionSDS,"SELECT SystemType FROM > orweb.dbo.InventoryTiny WHERE PWS='$pwsno'"); > $z=odbc_result($data5,"SystemType"); > $thissystem="C"; > echo $z; //returns "C" > echo " "; > echo $thissystem; //returns "C" > echo " "; > If($z==$thissystem) Try var_dump($z) to see if there are any extra characters returned in $z. ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php - Do you Yahoo!? Yahoo! Mail - 50x more storage than other providers!
Re: [PHP-DB] Sybase Peristent Connections Gotchas
Bob, I agree there are inherit limitations and better ways to pool db connections. Any decent middleware package would probably handle these problems very easily. I just thought that some people may have found simplier ways to realize the benefits of pconnect and reduce some of the side effects. It may be in my situation, it just isn't worth the troubles. I just thought I'd ask... Thanks, Brian Robert Twitty wrote: Hi Brian Why don't you just avoid using sybace_pconnect() with transactions? I use ODBTP to connect to SQL Server and Sybase databases, and this is not an issue. The reason is because ODBTP involves the use of a mediating service that pools all connections, and automatically rollbacks transactions upon client disconnection. The odbtp extension does not support persistent connections, since they are pooled by the ODBTP server. And, if an odbtp script aborts, the odbtp client connection will be terminated, which will cause the odbtp server to rollback the transaction. However, the underlyning database connection will still be pooled by the server for use by another client. Persistent connections may not be the best way to implement database connection reusage. Not only are they subject to undesirable open transactions, they will never timeout, and a single web client can cause a database connection to remain open for each web server child process. Connection pooling may be a better alternative, however, it requires a middle-man server to manage the pool. Unfortuantely, ODBTP requires the server to be placed on a Win32 host that can access the database with its local ODBC facilities. For some developers, this is not always feasible. If it's feasible for you, then your problem will be solved by using the odbtp extension. Otherwise, you can't use persistent connections. -- bob On Wed, 15 Sep 2004, Brian Foddy wrote: On transactions, no this is my biggest concern. Say a php script performs a "begin tran" then aborts early due to an error (user error for instance), but the script error handling fails to rollback the transaction before it exits. Just 1 poorly coded script. Now the begin tran is still open, the next page served by that apache process inherits an open transaction. Even if it is coded and perform perfectly with its own begin / commit trans (remember you can nest trans), the transaction is ultimately never commited; but there is almost no indication to the script. This keeps going and going making this uncomitted trans bigger and bigger, locking more and more records. Finally one of 2 things will happen. 1. The locks get so big that users may get blocked or the max locks exceed the sybase config. 2. The apache process may actually exit if its defined for a max usage or is trimmed by the web server due to max running daemons. In case 1, application support would probably restart the web server to release the locks. In case 2 apache itself does it. Either way, the transaction and all the subsequent nested ones will be rolled back, as if they never occurred. It could be a big database headache. The best way I can forsee to prevent this is to always perform a "rollback tran" after a call to sybase_pconnect to make sure there isn't an unclosed trans. As for the other points you make, I was expecting to perform a sybase_pconnect each execution anyway so that is automatic. I'm not sure how I can reset the handle in Sybase? If its possible I'd like to know how. The more I think about this, it seems that this whole thing is more work than its worth. But if someone sees some effective ways to handle some of these issues I'd like to hear them. Brian Jeff Moss wrote: The biggest problem I've had with persistent connections is the problems that arise when the connection goes down. You have to monitor the connection status anyways (and reconnect on a failure), so it was usually easier to just connect every time. I don't know if this is specific to sybase. You also avoid headache dealing with multiple connections per process. Over a local ethernet this was usually such a short delay that it didn't matter. Typically I don't care much for speed, you avoid a lot of headache avoiding the persistent connections, but the tradeoff is speed of course. It seems to make a lot more sense to me to just reset the handle to drop all temp tables and that. As for the transactions, I think as long as you "do" the transaction all at once there would be no problem right? If it was a problem in the middle of a socket write, chances are the socket closed also, right? -Jeff Brian Foddy wrote: I've been using PHP4/5 and Sybase for several years, using standard sybase_connect. Today I tried playing around with pconnect to get aquainted. I expected one simple condition of a "use database" from one web page affecting another, and easilly handled that with a connection wrapper that re-uses the proper database with each reconnection. A couple other more troublesome issues also quickly came up. 1. Any #t
Re: [PHP-DB] Sybase Peristent Connections Gotchas
Hi Brian Why don't you just avoid using sybace_pconnect() with transactions? I use ODBTP to connect to SQL Server and Sybase databases, and this is not an issue. The reason is because ODBTP involves the use of a mediating service that pools all connections, and automatically rollbacks transactions upon client disconnection. The odbtp extension does not support persistent connections, since they are pooled by the ODBTP server. And, if an odbtp script aborts, the odbtp client connection will be terminated, which will cause the odbtp server to rollback the transaction. However, the underlyning database connection will still be pooled by the server for use by another client. Persistent connections may not be the best way to implement database connection reusage. Not only are they subject to undesirable open transactions, they will never timeout, and a single web client can cause a database connection to remain open for each web server child process. Connection pooling may be a better alternative, however, it requires a middle-man server to manage the pool. Unfortuantely, ODBTP requires the server to be placed on a Win32 host that can access the database with its local ODBC facilities. For some developers, this is not always feasible. If it's feasible for you, then your problem will be solved by using the odbtp extension. Otherwise, you can't use persistent connections. -- bob On Wed, 15 Sep 2004, Brian Foddy wrote: > On transactions, no this is my biggest concern. Say a php script > performs a > "begin tran" then aborts early due to an error (user error for > instance), but > the script error handling fails to rollback the transaction before it exits. > Just 1 poorly coded script. > > Now the begin tran is still open, the next page served by that apache > process inherits an open transaction. Even if it is coded and perform > perfectly with its own begin / commit trans (remember you can nest trans), > the transaction is ultimately never commited; but there is almost no > indication to the script. This keeps going and going making this > uncomitted trans bigger and bigger, locking more and more records. > Finally one of 2 things will happen. > 1. The locks get so big that users may get blocked or the max locks exceed > the sybase config. > 2. The apache process may actually exit if its defined for a max usage or > is trimmed by the web server due to max running daemons. > > In case 1, application support would probably restart the web server to > release > the locks. In case 2 apache itself does it. > Either way, the transaction and all the subsequent nested ones will be > rolled back, as if they never occurred. It could be a big database > headache. > > The best way I can forsee to prevent this is to always perform a > "rollback tran" after a call to sybase_pconnect to make sure there isn't > an unclosed trans. > > As for the other points you make, I was expecting to perform a > sybase_pconnect each execution anyway so that is automatic. > I'm not sure how I can reset the handle in Sybase? If its possible I'd like > to know how. > > The more I think about this, it seems that this whole thing is more work > than its worth. But if someone sees some effective ways to handle some > of these issues I'd like to hear them. > > Brian > > Jeff Moss wrote: > > > The biggest problem I've had with persistent connections is the > > problems that arise when the connection goes down. You have to monitor > > the connection status anyways (and reconnect on a failure), so it was > > usually easier to just connect every time. I don't know if this is > > specific to sybase. You also avoid headache dealing with multiple > > connections per process. Over a local ethernet this was usually such a > > short delay that it didn't matter. Typically I don't care much for > > speed, you avoid a lot of headache avoiding the persistent > > connections, but the tradeoff is speed of course. > > > > It seems to make a lot more sense to me to just reset the handle to > > drop all temp tables and that. > > > > As for the transactions, I think as long as you "do" the transaction > > all at once there would be no problem right? If it was a problem in > > the middle of a socket write, chances are the socket closed also, right? > > > > -Jeff > > > > Brian Foddy wrote: > > > >> I've been using PHP4/5 and Sybase for several years, using standard > >> sybase_connect. Today I tried playing around with pconnect to get > >> aquainted. > >> > >> I expected one simple condition of a "use database" from one web page > >> affecting another, and easilly handled that with a connection wrapper > >> that > >> re-uses the proper database with each reconnection. > >> > >> A couple other more troublesome issues also quickly came up. > >> 1. Any #temp database tables are not destroyed between calls. I can > >> probably > >> work around this with some minor coding changes to manually drop temp > >> tables. > >> > >> 2. Any call to environmental "s
Re: [PHP-DB] Totally lost on why If statement doesn't work to call query
From: "Karen Resplendo" <[EMAIL PROTECTED]> $data5=odbc_do($connectionSDS,"SELECT SystemType FROM orweb.dbo.InventoryTiny WHERE PWS='$pwsno'"); $z=odbc_result($data5,"SystemType"); $thissystem="C"; echo $z; //returns "C" echo ""; echo $thissystem; //returns "C" echo ""; If($z==$thissystem) Try var_dump($z) to see if there are any extra characters returned in $z. ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Using sessions to gather visitor information
the time difference is most likely becuase your server is in a different time zone, or is at least set to a different time zone. When you run your time calculations, you can add something like this: $now = (time() - 18000); that would give you the time on the server minus 5 hours. Now I don't know the difference between time() and localtime() so I don't know how that will affect the output. -- -->> Jasper Howard :: Database Administration ApexEleven Web Design 1.530.559.0107 http://www.ApexEleven.com/ <<-- "Vincent Jordan" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I am trying to track the users that visit one page on a site. I am having a > couple of problems. The time seems to be 5 hours off. I do not have any > tables as of yet what I would like to do is only count an ip address as one > in a 24 hour period, if more than one visit then update visit count.I have > played around with the time using date() and localtime(). Here is what I > have sofar. > > > > ini_set('display_errors',1); > > error_reporting(E_ALL & ~E_NOTICE); > > session_start(); > > $_SESSION['ip_address'] = $IP; > > $_SESSION['user_agent'] = $Browser; > > $_SESSION['host_name'] = $Host; > > $_SESSION['visit_time'] = $now; > > > > $now = localtime(); > > $now = $now[2] . ":" . $now[1] . ":" . $now[0]; > > $IP = getenv(REMOTE_ADDR); > > $Browser = $_SERVER['HTTP_USER_AGENT']; > > $Host = getHostByName($IP); > > > > I have not setup tables yet but I think I will use this: > > vid init(5) not null auto_incriment > > ip varchar(25) null > > agent varchar(100) null > > host varchar(100) null > > time varchar(10) nul > > visitcount int(100) null > > > > when a visitor loads the page I can run this > > > > mysql_query(SELECT ip, time FROM tablename where ip=$_SESSION['ip_address'] > and time=$_SESSION['visit_time']) > > > > I would like to query if $_SESSION['ip_address'] has visited in less then 24 > hours then kill session and close mysql connection. If last visit was more > than 24 hours update time and add +1 to visitcount. If new visit add to > table. > > > > Once all done how can I properly clean up the session. I have tried the > following bur get an error > > unset($_SESSION); > > session_destroy(); > > I tried this with a link to another page and got this error: > > Warning: session_destroy(): Trying to destroy uninitialized session in > /home/content/html/killtest.php on line 5 > > I assume I forgot something. > > > > Any help would be appreciated. > > > > > > > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Totally lost on why If statement doesn't work to call query
This works: If("C"=="C") { //query and display here } This works: If("C"=="D") { //query and display here (won't happen) } In other words the query inside the If clause runs or not, depending on the logic. But, when I initialize $z=odbc_result($data5,"SystemType"); and $thissystem="C" then this doesn't work: If($z==$thissystem) { //query and display here } I've echoed all the values to the page to make sure they are there. What the heck is going on? (please) Here is the whole block of code that runs or doesn't. I've spent hours trying to figure out why it doesn't work even when the code itself without the If statement works: $data5=odbc_do($connectionSDS,"SELECT SystemType FROM orweb.dbo.InventoryTiny WHERE PWS='$pwsno'"); $z=odbc_result($data5,"SystemType"); $thissystem="C"; echo $z; //returns "C" echo ""; echo $thissystem; //returns "C" echo ""; If($z==$thissystem) { $data6=odbc_do($connectionSDWIS,"EXEC orweb.jdavis.sp_CCR '$pwsno'"); echo "\n"; echo "Consumer Confidence Reports"; echo $trcenter; echo "For YearDate ReceivedDate Certified"; echo ""; do { echo $trcenter; $fields=odbc_num_fields($data6); for($i=1 ; $i<=$fields ; $i++) echo "".odbc_result($data6,$i).""; echo "\n"; } while(odbc_fetch_row($data6)); echo ""; } echo "(Only Community water systems require a Consumer Confidence Report)"; - Do you Yahoo!? vote.yahoo.com - Register online to vote today!
Re: [PHP-DB] Using sessions to gather visitor information
Hi. On Sep 15, 2004, at 6:55 AM, Vincent Jordan wrote: I am trying to track the users that visit one page on a site. I am having a couple of problems. The time seems to be 5 hours off. I do not have any tables as of yet what I would like to do is only count an ip address as one in a 24 hour period, if more than one visit then update visit count.I have played around with the time using date() and localtime(). Here is what I have sofar. ini_set('display_errors',1); error_reporting(E_ALL & ~E_NOTICE); session_start(); $_SESSION['ip_address'] = $IP; $_SESSION['user_agent'] = $Browser; $_SESSION['host_name'] = $Host; $_SESSION['visit_time'] = $now; $now = localtime(); $now = $now[2] . ":" . $now[1] . ":" . $now[0]; $IP = getenv(REMOTE_ADDR); $Browser = $_SERVER['HTTP_USER_AGENT']; $Host = getHostByName($IP); I have not setup tables yet but I think I will use this: vid init(5) not null auto_incriment ip varchar(25) null agent varchar(100) null host varchar(100) null time varchar(10) nul visitcount int(100) null when a visitor loads the page I can run this mysql_query(SELECT ip, time FROM tablename where ip=$_SESSION['ip_address'] and time=$_SESSION['visit_time']) I would like to query if $_SESSION['ip_address'] has visited in less then 24 hours then kill session and close mysql connection. If last visit was more than 24 hours update time and add +1 to visitcount. If new visit add to table. Once all done how can I properly clean up the session. I have tried the following bur get an error unset($_SESSION); session_destroy(); I tried this with a link to another page and got this error: Warning: session_destroy(): Trying to destroy uninitialized session in /home/content/html/killtest.php on line 5 I assume I forgot something. Any help would be appreciated. You might make sure that on the page where it says session_destroy(); that you have actually carried the session over. Meaning, if it's on a different page than you originally started the session, make sure you include session_start(); at the beginning of that next page. Also, something you might want to try is first testing to see if the session is set. if (session_id()) session_destroy(); That part doesn't really help your specific situation (as far as destroying the session), but I think it's good practice and will not give an error message if your session has not been started yet and you try to destroy it. Hope this helps you some. ~Philip -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Using sessions to gather visitor information
From: "Vincent Jordan" <[EMAIL PROTECTED]> I am trying to track the users that visit one page on a site. I am having a couple of problems. The time seems to be 5 hours off. I do not have any tables as of yet what I would like to do is only count an ip address as one in a 24 hour period, if more than one visit then update visit count.I have played around with the time using date() and localtime(). Here is what I have sofar. ini_set('display_errors',1); error_reporting(E_ALL & ~E_NOTICE); session_start(); $_SESSION['ip_address'] = $IP; $_SESSION['user_agent'] = $Browser; $_SESSION['host_name'] = $Host; $_SESSION['visit_time'] = $now; $now = localtime(); $now = $now[2] . ":" . $now[1] . ":" . $now[0]; $IP = getenv(REMOTE_ADDR); $Browser = $_SERVER['HTTP_USER_AGENT']; $Host = getHostByName($IP); How about showing some actual code and giving details on what doesn't work? This code doesn't make sense, as you're calculating $now, $IP, etc after you've assigned them to the session... Basic debugging steps: start printing out variables and ensuring they have a value and it's what you think it should be. Print out your queries before you execute them to look for obvious errors. Turn register_globals OFF. I have not setup tables yet but I think I will use this: [snip] time varchar(10) nul This should be a DATETIME or TIMESTAMP field. [snip] Once all done how can I properly clean up the session. I have tried the following bur get an error unset($_SESSION); session_destroy(); I tried this with a link to another page and got this error: Warning: session_destroy(): Trying to destroy uninitialized session in /home/content/html/killtest.php on line 5 $_SESSION = array(); will clear the session. If you unset() it, I don't think it's written at the end of the script, so your data remains. session_destroy() then probably fails because $_SESSION is gone or you never called session_start() on the page. ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Sybase Peristent Connections Gotchas
On transactions, no this is my biggest concern. Say a php script performs a "begin tran" then aborts early due to an error (user error for instance), but the script error handling fails to rollback the transaction before it exits. Just 1 poorly coded script. Now the begin tran is still open, the next page served by that apache process inherits an open transaction. Even if it is coded and perform perfectly with its own begin / commit trans (remember you can nest trans), the transaction is ultimately never commited; but there is almost no indication to the script. This keeps going and going making this uncomitted trans bigger and bigger, locking more and more records. Finally one of 2 things will happen. 1. The locks get so big that users may get blocked or the max locks exceed the sybase config. 2. The apache process may actually exit if its defined for a max usage or is trimmed by the web server due to max running daemons. In case 1, application support would probably restart the web server to release the locks. In case 2 apache itself does it. Either way, the transaction and all the subsequent nested ones will be rolled back, as if they never occurred. It could be a big database headache. The best way I can forsee to prevent this is to always perform a "rollback tran" after a call to sybase_pconnect to make sure there isn't an unclosed trans. As for the other points you make, I was expecting to perform a sybase_pconnect each execution anyway so that is automatic. I'm not sure how I can reset the handle in Sybase? If its possible I'd like to know how. The more I think about this, it seems that this whole thing is more work than its worth. But if someone sees some effective ways to handle some of these issues I'd like to hear them. Brian Jeff Moss wrote: The biggest problem I've had with persistent connections is the problems that arise when the connection goes down. You have to monitor the connection status anyways (and reconnect on a failure), so it was usually easier to just connect every time. I don't know if this is specific to sybase. You also avoid headache dealing with multiple connections per process. Over a local ethernet this was usually such a short delay that it didn't matter. Typically I don't care much for speed, you avoid a lot of headache avoiding the persistent connections, but the tradeoff is speed of course. It seems to make a lot more sense to me to just reset the handle to drop all temp tables and that. As for the transactions, I think as long as you "do" the transaction all at once there would be no problem right? If it was a problem in the middle of a socket write, chances are the socket closed also, right? -Jeff Brian Foddy wrote: I've been using PHP4/5 and Sybase for several years, using standard sybase_connect. Today I tried playing around with pconnect to get aquainted. I expected one simple condition of a "use database" from one web page affecting another, and easilly handled that with a connection wrapper that re-uses the proper database with each reconnection. A couple other more troublesome issues also quickly came up. 1. Any #temp database tables are not destroyed between calls. I can probably work around this with some minor coding changes to manually drop temp tables. 2. Any call to environmental "set" commands like "set isolation" remain in effect after the web page is complete. Again with some work I could probably recode some pages to not change these values, or reset them when complete. 3. The potentially most bothersome would be a page failing to call commit tran/rollback tran, especially during some error condition. Its easy to think any uncommited tran is rolled back when the page exists. But persistent connections won't do this. This could be a disaster by leaving open a transaction causing all subsequent calls to never be commited... I might be able to create some wrapper that always resets the transaction state before starting?? I'm curious how others have attempted to solve these problems, and others I haven't thought of yet. Clearly many can be avoided by having clean code, but just 1 exception... Brian -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] PHP 5 Error Handling
Good question. I've tried the __LINE__ and __FILE__ in my error-handling, but it does the same thing you're experiencing, getting the line in the function/method as opposed to the actual error line. The only way I've gone around it is whenever there may be an exception, such as a sql statement, etc I assign $line_no = __LINE__ and if an exception gets thrown, the $line_no is captured, and I can use the info to print to the logs or the screen or ... G. Gary Every Sr. UNIX Administrator Ingram Entertainment Inc. 2 Ingram Blvd, La Vergne, TN 37089 "Pay It Forward!" -Original Message- From: Joseph Crawford [mailto:[EMAIL PROTECTED] Sent: Tuesday, September 14, 2004 5:55 AM To: [PHP-DB] Mailing List Subject: [PHP-DB] PHP 5 Error Handling Guys, i have been working with custom exception classes that extend the general exception. Here is some code i have public function command($cmd) { if($cmd) { $res = fputs($this->connection, $cmd); $this->response = fgets($this->connection, 128); switch($this->getCode()) { case 500: throw new CommandException($cmd); break; } } } public function selectGroup($group) { $this->group = $group; if(substr($this->response,0,3) == "200") { THIS IS THE LINE THAT THROWS THE ERROR $this->command("NoSuchCommand\n"); $this->response = fgets($this->connection, 1024); } $info = split(" ", $this->response); $this->first = $info[2]; $this->last = $info[3]; } now when the error is thrown and i do $e->getLine(); it shows the line of the file where the throw statement is. Is there a way to make it show the actual line number of the line that is the error? the $this->command("NoSuchCommand\n"); line. -- Joseph Crawford Jr. Codebowl Solutions [EMAIL PROTECTED] 802-558-5247 For a GMail account contact me OFF-LIST -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] search query
Hi I have a option box with values Less than 150.000 tot 175.000 tot 200.000 tot 250.000 tot 300.000 tot 350.000 tot 400.000 More than 400.000 I need help when the user chose option value 3 till 200.000 than the query should search between 175.000 and 200.000 how to achive this Regards -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Using sessions to gather visitor information
I am trying to track the users that visit one page on a site. I am having a couple of problems. The time seems to be 5 hours off. I do not have any tables as of yet what I would like to do is only count an ip address as one in a 24 hour period, if more than one visit then update visit count.I have played around with the time using date() and localtime(). Here is what I have sofar. ini_set('display_errors',1); error_reporting(E_ALL & ~E_NOTICE); session_start(); $_SESSION['ip_address'] = $IP; $_SESSION['user_agent'] = $Browser; $_SESSION['host_name'] = $Host; $_SESSION['visit_time'] = $now; $now = localtime(); $now = $now[2] . ":" . $now[1] . ":" . $now[0]; $IP = getenv(REMOTE_ADDR); $Browser = $_SERVER['HTTP_USER_AGENT']; $Host = getHostByName($IP); I have not setup tables yet but I think I will use this: vid init(5) not null auto_incriment ip varchar(25) null agent varchar(100) null host varchar(100) null time varchar(10) nul visitcount int(100) null when a visitor loads the page I can run this mysql_query(SELECT ip, time FROM tablename where ip=$_SESSION['ip_address'] and time=$_SESSION['visit_time']) I would like to query if $_SESSION['ip_address'] has visited in less then 24 hours then kill session and close mysql connection. If last visit was more than 24 hours update time and add +1 to visitcount. If new visit add to table. Once all done how can I properly clean up the session. I have tried the following bur get an error unset($_SESSION); session_destroy(); I tried this with a link to another page and got this error: Warning: session_destroy(): Trying to destroy uninitialized session in /home/content/html/killtest.php on line 5 I assume I forgot something. Any help would be appreciated.