php-general Digest 11 Feb 2007 11:22:00 -0000 Issue 4620
Topics (messages 248718 through 248732):
Please critique my database class.
248718 by: barophobia
248729 by: barophobia
Re: PHP or Bridge (card game)
248719 by: Matt Carlson
248721 by: Paul Novitski
php based digg like package?
248720 by: blackwater dev
Re: base64-encoding in cookies?
248722 by: Robert Cummings
248723 by: Fletcher Mattox
un include?
248724 by: jekillen
248725 by: Casey Chu
248726 by: Larry Garfield
Re: Any Internal search engine in PHP?
248727 by: Paul Scott
248732 by: David Robley
Re: Recommend a PHP Framework
248728 by: Jim Lucas
Pasar varialbe sin GET
248730 by: Anuack Luna
Web Based Game Theory
248731 by: Sancar Saran
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
Hi!
I was thinking about asking for recommendations for a lightweight database
class. But I realized I hadn't thought much about what my requirements are
so I decided instead to ask the list to critique my own class. I don't need
anything as robust as ADOdb and I always use MySQL.
This class was written with PHP4 in mind but now that I'm using PHP5 feel
free to make more advanced suggestions.
I'd like to know if there is anything I'm doing in this class that is a
nono, or can be done better.
Maybe my approach to the class is flawed and I should start over. Or maybe
the class is fine as it is.
Maybe I can have a better naming scheme.
I'm just looking for general feedback. Anything you have to say will be
considered with an open mind.
Thanks!
Chris.
// BEGIN
class Database
{
var $db_server;
var $db_database;
var $db_user;
var $db_password;
var $root_path;
var $return_type = MYSQL_ASSOC;
// used to store db connection
var $db;
// stores mysql_fetch_array() after a query
var $Result = array();
function Database()
{
// define variables
$this->db_server = $GLOBALS['DB_SERVER'];
$this->db_database = $GLOBALS['DB_NAME'];
$this->db_user = $GLOBALS['DB_USER'];
$this->db_password = $GLOBALS['DB_PASSWORD'];
$this->root_path = $GLOBALS['HTTP_ROOT'];
$this->open_connection();
$this->connect_db();
}
function open_connection()
{
$this->db = mysql_connect($this->db_server, $this->db_user,
$this->db_password)
or die("failed to make db connection");
}
function close_connection()
{
mysql_close($this->db);
}
function stop($sql)
{
$tmp_mysql_errno = mysql_errno();
$tmp_mysql_error = mysql_error();
// print the error
echo <<<QQQ
<p class="error">
$tmp_mysql_errno, $tmp_mysql_error</p>
QQQ;
if(!$GLOBALS['SITE_IS_LIVE'])
{
echo <<<QQQ
<pre>$sql</pre>
QQQ;
}
}
function connect_db()
{
mysql_select_db($this->db_database)
or die($this->stop("stop stop stop"));
}
function execute($sql)
{
$this->Result = mysql_query($sql) or die($this->stop($sql));
if(strtolower(substr(ltrim($sql), 0, 6)) == "select")
{
if(mysql_affected_rows() > 0)
{
return $this->_get_results();
}
else
{
return false;
}
}
}
function _get_results()
{
// we have to reset the Result_Arr because otherwise it will have
old
// values left over if you use this method twice in the same object.
$Result_Arr = array();
// initialize counter
while($line = mysql_fetch_array($this->Result, $this->return_type))
{
$Result_Arr[] = $line;
}
mysql_free_result($this->Result);
return $Result_Arr;
}
}
// END
--- End Message ---
--- Begin Message ---
First time this went through I got a message saying I had to confirm my
address. I did that but I never saw it show up on the list so I'm trying
again.
---------- Forwarded message ----------
From: barophobia <[EMAIL PROTECTED]>
Date: Feb 10, 2007 2:12 PM
Subject: Please critique my database class.
To: php-general <[email protected]>
Hi!
I was thinking about asking for recommendations for a lightweight database
class. But I realized I hadn't thought much about what my requirements are
so I decided instead to ask the list to critique my own class. I don't need
anything as robust as ADOdb and I always use MySQL.
This class was written with PHP4 in mind but now that I'm using PHP5 feel
free to make more advanced suggestions.
I'd like to know if there is anything I'm doing in this class that is a
nono, or can be done better.
Maybe my approach to the class is flawed and I should start over. Or maybe
the class is fine as it is.
Maybe I can have a better naming scheme.
I'm just looking for general feedback. Anything you have to say will be
considered with an open mind.
Thanks!
Chris.
// BEGIN
class Database
{
var $db_server;
var $db_database;
var $db_user;
var $db_password;
var $root_path;
var $return_type = MYSQL_ASSOC;
// used to store db connection
var $db;
// stores mysql_fetch_array() after a query
var $Result = array();
function Database()
{
// define variables
$this->db_server = $GLOBALS['DB_SERVER'];
$this->db_database = $GLOBALS['DB_NAME'];
$this->db_user = $GLOBALS['DB_USER'];
$this->db_password = $GLOBALS['DB_PASSWORD'];
$this->root_path = $GLOBALS['HTTP_ROOT'];
$this->open_connection();
$this->connect_db();
}
function open_connection()
{
$this->db = mysql_connect($this->db_server, $this->db_user,
$this->db_password)
or die("failed to make db connection");
}
function close_connection()
{
mysql_close($this->db);
}
function stop($sql)
{
$tmp_mysql_errno = mysql_errno();
$tmp_mysql_error = mysql_error();
// print the error
echo <<<QQQ
<p class="error">
$tmp_mysql_errno, $tmp_mysql_error</p>
QQQ;
if(!$GLOBALS['SITE_IS_LIVE'])
{
echo <<<QQQ
<pre>$sql</pre>
QQQ;
}
}
function connect_db()
{
mysql_select_db($this->db_database)
or die($this->stop("stop stop stop"));
}
function execute($sql)
{
$this->Result = mysql_query($sql) or die($this->stop($sql));
if(strtolower(substr(ltrim($sql), 0, 6)) == "select")
{
if(mysql_affected_rows() > 0)
{
return $this->_get_results();
}
else
{
return false;
}
}
}
function _get_results()
{
// we have to reset the Result_Arr because otherwise it will have
old
// values left over if you use this method twice in the same object.
$Result_Arr = array();
// initialize counter
while($line = mysql_fetch_array($this->Result, $this->return_type))
{
$Result_Arr[] = $line;
}
mysql_free_result($this->Result);
return $Result_Arr;
}
}
// END
--- End Message ---
--- Begin Message ---
Having learned Bridge when I was younger, I feel PHP is alot easier to learn as
it is "constant" in a way.
Depending on cards you are holding, cards your partner is holding, and your
oponents bidding, depends how you should bid. Quite a bit of variablity in
there.
----- Original Message ----
From: Kenn Murrah <[EMAIL PROTECTED]>
To: pub <[EMAIL PROTECTED]>
Cc: PHP General List <[email protected]>
Sent: Saturday, February 10, 2007 3:57:03 PM
Subject: Re: [PHP] PHP or Bridge (card game)
pub wrote:
> which do you think is harder to learn, PHP or bridge?
>
Well, PHP *can* be a lot more complicated, but at least it's more or
less predictable, and I've RARELY had a bridge partner that played the
game predictably and consistently ....
kennM
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
At 2/10/2007 01:19 PM, pub wrote:
Do any of you also know how to play bridge?
If yes, which do you think is harder to learn, PHP or bridge?
I don't think learning is so generalizable.
In my experience, motivation has a lot to do with how easy things are
to learn. If you're excited or passionate about a subject, you'll
eat it up; if it bores you or aggravates you, you'll tend to resist,
even if unconsciously.
I love languages, including programming languages; card games haven't
interested me in years, and bridge always seemed particularly
boring. I wouldn't expect anyone else to share my particular
motivations nor my learning pattern.
PHP has more 'cards' and many more rules than bridge, so I expect
it's far more complex. That in itself doesn't make it more difficult
to learn, but I suppose it might if one's passion for the two
pursuits were, somehow, equal.
So... what does this have to do with PHP?
Regards,
Paul
--- End Message ---
--- Begin Message ---
A month or so ago I can across a php based open source community news
package. I can't seem to find it now...does anyone know of one?
Thanks!
--- End Message ---
--- Begin Message ---
On Sat, 2007-02-10 at 17:01 -0600, Fletcher Mattox wrote:
> Robert Cummings writes:
>
> > But isn't the sender and receiver usually one and the same. I mean your
> > PHP application is usually what set the cookie in the first place. Then
> > you receive it in the very same PHP application.
>
> No! Not in this case. The first sentence in my original message was:
>
> "A campus web server (not under my control) returns an
> authentication string in a cookie named AUTH."
>
> Rob, is this why you are giving me such a hard time? Do you think I
> wrote the code which set the cookie?
No, I missed that part and came in when you were complaining that nobody
could give you a reason why PHP does what it does. Then when I gave you
a reason, you complained that nobody had yet given you a link to a
reference doc yet. It hink the use of "giving" you a hard time is
incorrect. A more apt word would "gave", and even then I was still
providing you with information.
> The application which originated the cookie runs on a computer across
> campus, and was written by our ITS department. I work in the CS
> department. I have no access to that application. I don't even know
> which language it is written in. Given this information, would you be
> comfortable asking ITS to change their code just to make my application
> happy? I wouldn't.
No, as you should have noted later in the email I realized that you are
working with a heterogeneous system. Do you respond to an email on first
pass? I always read first then respond after I've read the entire post.
> > > Also, keep in mind that in my case the sender is a third party over
> > > whom I have no control. Given a spec like this, I prefer cooperation
> > > between sender and receiver rather than a decision by fiat made by the
> > > programming language.
> >
> > Ah, so you have a mixed language environment. Well you can use the
> > header() function to send the cookie header yourself.
>
> As I keep trying to say, I am not sending the cookie. I do not have
> that option.
As I said, I missed the beginning of the thread, and when I came into
thread it didn't seem an issue since you were focused on why the
encoding was the way it was.
> > This allows you
> > control over the sending. You can also use apache_request_headers() to
> > get full control over the incoming request headers.
>
> Ah. Interesting. I was not aware of that function. Thanks.
>
> > > Oh. One more thought. If you wish to argue that PHP does provide
> > > for both cases with $_COOKIE and $_SERVER['HTTP_COOKIE'], then I will
> >
> > I'm not aware of a $_SERVER['HTTP_COOKIE'] field. Perhaps you meant
> > $GLOBALS['HTTP_COOKIE_VARS']? If so, it is identical to $_COOKIE with
> > $GLOBALS['HTTP_COOKIE_VARS'] being deprecated.
>
> $_SERVER fields are dependent on your http server. My server (apache)
> provides HTTP_COOKIE. Perhaps yours does not?
I use Apache also. I have no idea what it does, never needed it. But
since it's provided by Apache, it seems the Apache docs are where you
should look.
> > > grudgingly agree with you. See we can agree. :) In that case, all I ask
> > > is for a little documentation. Is the distinction in these two variables
> > > documented somewhere? I have looked and looked and have come up empty.
> > > I am asking this question with humility and sincerity. I am asking it
> > > because I honestly wish to learn. I think you have misjudged my motives
> > > and my character.
> >
> > http://www.php.net/manual/en/function.header.php
> > http://www.php.net/manual/en/function.apache-response-headers.php
>
> Thanks for the pointers, but my request is for documentation of the fact
> that $COOKIE has been urldecoded(). Do you know where that documentation
> lives?
You seem to b lost in confusion. I don't have the documentation you
want, instead I provided you with links to functions that allow you the
control you so vehemently argue PHP has taken away from you.
> Say, I just noticed RFC 2965. It essentially agrees with the Netscape
> document on this matter, but it words it a little more clearly:
>
> The VALUE is opaque to the user agent and may be anything the
> origin server chooses to send, possibly in a server-selected
> printable ASCII encoding.
>
> The server is in control. The encoding, if any, is decided by the server.
> No question about it. In my case, the server decided not to encode.
>
> In my opinion, PHP has done me a disservice by "decoding" (corrupting)
> that value, putting it in the $_COOKIE variable and then not clearly
> documenting it.
PHP has done no such thing. PHP still allows you raw access to headers
and received headers. It's up to you to you to get down and dirty and
use the resources that cut closer to the grain.
> Does anyone else see my point here, or am I way off base here?
You're somewhat in lala land. I don't mean this as an insult, just an
observation. You seem so locked onto arguing the point that you've
failed to see in the last email I sent that I provided you with links to
the tools you need to get at what you say you can get at *sheesh*.
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
--- End Message ---
--- Begin Message ---
Jon Anderson writes:
> I won't argue that this behavior should probably be documented with
> $_COOKIE, but it is documented with it's counterpart, setcookie: "Note
> that the value portion of the cookie will automatically be urlencoded
> when you send the cookie, and when it is received, it is automatically
> decoded and assigned to a variable by the same name as the cookie name.
Bingo! Thank you, thank you, thank you. This is exactly what I have
been missing all along. It is not where I would have looked for it,
but I guess now I'll have to stop complaining it does not exist.
> If you don't want this, you can use setrawcookie()
I wonder why PHP doesn't have a corresponding variable, $_RAWCOOKIE, to be
used with setrawcookie()? That would have solved my problem.
> <http://www.php.net/manual/en/function.setrawcookie.php> instead if you
> are using PHP 5."
>
> In terms of the behavior, I think it makes total sense. The only case
> where it would ever bite you is yours (which is rare because most people
> wouldn't mix perl and PHP in the same system).
I am beginning to understand why I am having so much trouble convincing
folks here that my problem is real. Everyone seems to assume that cookies
are used only to communicate between one web application and a browser.
Perhaps my situation is rare. It doesn't seem very rare to me. :)
> I think some of the negativity aimed at you stems from the fact that the
> behavior has been explained and is quite clear. > There isn't much point
> in arguing what it should be. It is exactly what it is. If you want to
> argue what the behavior should be, try php-dev. (Making that kind of
> argument here is like yelling at your neighbor 'cause Vista
> sucks...assuming Bill Gates isn't your neighbor. :-)
Point taken. Maybe I *should* go to php-dev. However, I fear they would
be an even harder sell than you guys. :) And life is too short for that.
Thanks, Jon, for a very insightful message.
Fletcher
Ps - if I were to go to php-dev, I think I would lobby for the addition of
a new global variable: $_RAWCOOKIE.
--- End Message ---
--- Begin Message ---
Hello all;
Is there a way to un include a file once it has been included in a
script?
I have a situation where I need to include a php file for a variable and
its value. Then I need to open the file and modify it in the same
function
'that included the file. So far the function, as I test it does not
appear
to be making the intended changes to the file that has been included.
And I am not getting any error messages.
Am I asking too much:
$fileToInclude = 'some_file.php';
function edit_included_file( $fileToInclude)
{
include($fileToInclude);
// use some variable in it
$fr = fopen($fileToInclude, 'r');
$str = fread($fr, filesize($fileToInclude))
fclose($fr);
// make alterations to $str
// reopen file and write the changes
// done but in test function I have written changes have not been made
}
looked through the O'Reilly book Programming Php and could not find
a clue.
Thanks in advance
Jeff K
--- End Message ---
--- Begin Message ---
Maybe you could make a separate PHP file, include it there, then pass
the results to the main file?
On 2/10/07, jekillen <[EMAIL PROTECTED]> wrote:
Hello all;
Is there a way to un include a file once it has been included in a
script?
I have a situation where I need to include a php file for a variable and
its value. Then I need to open the file and modify it in the same
function
'that included the file. So far the function, as I test it does not
appear
to be making the intended changes to the file that has been included.
And I am not getting any error messages.
Am I asking too much:
$fileToInclude = 'some_file.php';
function edit_included_file( $fileToInclude)
{
include($fileToInclude);
// use some variable in it
$fr = fopen($fileToInclude, 'r');
$str = fread($fr, filesize($fileToInclude))
fclose($fr);
// make alterations to $str
// reopen file and write the changes
// done but in test function I have written changes have not been made
}
looked through the O'Reilly book Programming Php and could not find
a clue.
Thanks in advance
Jeff K
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
You need to rearchitect your system.
When you include a file, its code executes. Once it has been executed, it is
done. It will never "rewind" itself. You can open and edit the file, but
the code has already executed and that execution has happened, and you cannot
change that.
What exactly are you trying to accomplish? Dollars to donuts there's a much
easier and more logical way than trying to edit an included file.
On Saturday 10 February 2007 10:18 pm, jekillen wrote:
> Hello all;
> Is there a way to un include a file once it has been included in a
> script?
> I have a situation where I need to include a php file for a variable and
> its value. Then I need to open the file and modify it in the same
> function
> 'that included the file. So far the function, as I test it does not
> appear
> to be making the intended changes to the file that has been included.
> And I am not getting any error messages.
> Am I asking too much:
> $fileToInclude = 'some_file.php';
> function edit_included_file( $fileToInclude)
> {
> include($fileToInclude);
> // use some variable in it
> $fr = fopen($fileToInclude, 'r');
> $str = fread($fr, filesize($fileToInclude))
> fclose($fr);
> // make alterations to $str
> // reopen file and write the changes
> // done but in test function I have written changes have not been made
> }
> looked through the O'Reilly book Programming Php and could not find
> a clue.
> Thanks in advance
> Jeff K
--
Larry Garfield AIM: LOLG42
[EMAIL PROTECTED] ICQ: 6817012
"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson
--- End Message ---
--- Begin Message ---
On Sat, 2007-02-10 at 09:47 -0500, tedd wrote:
> >I had been trying some search engines for internal searches within my
> >website. I tried google co-op which failed as the results were showing on
> >supplemental index. The one provided by cpanel does not show more than 2-3
> >URLs in results. Please advice if you know about any php based search engine
> >that can index my pages internally. Certainly an open source one.
> http://sperling.com/examples/search/
>
We have integrated Apache Lucene into our framework, based on the
Zend_Search code found in the Zend Framework. It works really well, and
is pretty easy to use.
--Paul
All Email originating from UWC is covered by disclaimer
http://www.uwc.ac.za/portal/uwc2006/content/mail_disclaimer/index.htm
--- End Message ---
--- Begin Message ---
Chris Carter wrote:
>
> Hi,
>
> I had been trying some search engines for internal searches within my
> website. I tried google co-op which failed as the results were showing on
> supplemental index. The one provided by cpanel does not show more than 2-3
> URLs in results. Please advice if you know about any php based search
> engine that can index my pages internally. Certainly an open source one.
>
> Thanks,
>
> Chris
Mnogosearch can be used either as a cgi or with php functionality
available - may need a recompile of php for the latter.
http://www.mnogosearch.org/
Cheers
--
David Robley
Why get even, when you can get odd?
Today is Boomtime, the 42nd day of Chaos in the YOLD 3173.
--- End Message ---
--- Begin Message ---
Goh Yong Kwang wrote:
Hi,
I am now mulling over writing my PHP web application from scratch or to use
some kind of framework to organize my code.
For Java, Struts and Spring come to mind. But for PHP, there are numerous
frameworks and I can't figure out which one to use.
I would like to describe my constraints as dictated by my server setup
(using a free hosted account, so not a lot of flexibility):
* PHP 5
* Safe mode on
* No database (not even MySQL)
* No shell/SSH login to run commands
* Server running on Linux
* Only allowed to upload my PHP files via FTP or Web browser
* Only allowed to upload files to my account home directory, which is
document root
* Not allowed to tweak the PHP installation
So given the above constraints, most likely I need a simple framework that
* Comes in a bunch of PHP files and classes that I can just upload together
with my other PHP/HTML files
* No additional configuration on the server side
* No change required for the PHP installation such as PEAR installation,
modification of php.ini or installation of extension
Any framework that fits the constraints? Let me know.
Thanks.
---
Goh Yong Kwang
Singapore
[EMAIL PROTECTED]
can you at least write to the local file system with php?
if so, you might look at something that supports sqlite
You could also look at running a separate server running your DB.
--- End Message ---
--- Begin Message ---
Hola a todos. PHP
Bueno, mi consulta es complicada
Normalmente se pasa una variable así:
nombredelarchivo.php?valor=variable
nombredelarchivo.php?id=x
La pagina nombredelarchivo.php recibe la variable de la otra Web page
Hasta hay nop broblem
He visto en los portales como por ejemplo crean un solo archivo para
imprimir un valor como si fuera una carpeta.
Ejemplo:
pagina/usuari_1
pagina/usuari_2
pagina/anuack
pagina/lolita.
Para mi seria lógico que en donde dice anuack es una carpeta... NO???
He visto nombre de archivos {name}.php pero no encuentro como lleva un valor
y convierte a {name}.php en anuack, lolita, usuario... etc.
Como envía un valor o variable a {name}.php y como la recibe {name}.php si
por método GET no funciona????
También he probado en variable de formulario, cookie, variable de sección
"Algo ilógico pero lo probé", variable de servidor y valor introducido y
nada de nada
Claro, puedo hacer que me imprima por ejemplo 18.php, pero no encuentra el
archivo.
Alguna información clara en español.
Espero haberme explicado
--- End Message ---
--- Begin Message ---
Greetings all,
I just want to TRY write a web based strategy game. Lets say a famous ogame
clone.
Is there any paper about to game engine. I feel a bit a lost.
For example, for realtime gaming I need some kind of back size cli based big
game loop. Right ?
Last night I try to write down some thoughts.
Its look like I need a some kind of scheduler. Some kind of event system to
process events..
So, I'm looking for papers to give a clue about these problems
Regards
Sancar
--- End Message ---