php-general Digest 30 Jan 2005 07:12:52 -0000 Issue 3257
Topics (messages 207684 through 207705):
Re: [PHP-WIN] Random
207684 by: trobi
207698 by: Leif Gregory
Re: Regex help
207685 by: Michael Sims
207696 by: kjohnson.zootweb.com
Permissions on uploaded image don't allow for over writing
207686 by: Dave
207692 by: Hugh Danaher
207697 by: John Hicks
Re: Returning reference problem
207687 by: Jochem Maas
Re: Trying to compile PECL fileinfo on Windows
207688 by: Frank M. Kromann
207693 by: Chris
Regexp stopped working on my site
207689 by: Kristian Hellquist
207690 by: Marek Kilimajer
Re: Looking for ideas on scheduling
207691 by: Marek Kilimajer
best way to handle user authentication, PHP vs. apache
207694 by: Raymond Still
Regular expressions stopped working
207695 by: Kristian Hellquist
Re: Creating a webpage from an HTML form via PHP
207699 by: Marek Kilimajer
Image Creation and Saving
207700 by: NathanielGuy#21
design pattern/code generators
207701 by: robert mena
Is this a mysql_connect() bug?
207702 by: tom soyer
207703 by: trlists.clayst.com
207704 by: tom soyer
207705 by: Michael Sims
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 ---
Leif Gregory wrote / napísal (a):
Hello SargeTron,
Wednesday, January 19, 2005, 10:10:20 AM, you wrote:
S> rand() only returns an int (number), but I would like something
S> like dd75$6*, you know, containing any character. I would like it
S> only to do a certain string ONCE, so there are no duplicates (in a
S> for loop). Hopefully I won't need to do a huge array. Any
S> suggestions?
Take a look at this random e-mail address generator (hasn't everyone
written one of these? <grin>) that I wrote a bit back.
You should be able to see how to do exactly what you want from it.
http://www.devtek.org/software/randmail/index.php
$upperLowerNumber = rand(1,10); controls the so called seed for the
script because I placed constraints on how often uppercase and numbers
could appear.
Cheers,
Leif Gregory
whatabout uniqid()?
trobi
--- End Message ---
--- Begin Message ---
Hello trobi,
Saturday, January 29, 2005, 12:05:33 PM, you wrote:
t> whatabout uniqid()?
He also wanted symbols [EMAIL PROTECTED]&*() etc.
Cheers,
Leif Gregory
--
TB Lists Moderator (and fellow registered end-user)
PCWize Editor / ICQ 216395 / PGP Key ID 0x7CD4926F
Web Site <http://www.PCWize.com>
--- End Message ---
--- Begin Message ---
Bret Hughes wrote:
> On Sat, 2005-01-29 at 08:58, Michael Sims wrote:
>> [EMAIL PROTECTED] wrote:
>>> I need a validation regex that will "pass" a string. The string can
>>> be no longer than some maximum length, and it can contain any
>>> characters except two consecutive ampersands (&) anywhere in the
>>> string.
>>>
>>> I'm stumped - ideas?
>>
>> Yup, use this perl regex:
>>
>> /^(?:(&)(?!&)|[^&]){1,5}$/
>
> Great explanation. Thanks from one who has not had an exam for over
> ten years.
Thanks...I actually just realized that the parentheses around the first
ampersand are unnecessary (that was a leftover from a previous attempt), so
this is simpler and will work just as well:
/^(?:&(?!&)|[^&]){1,5}$/
Or if you don't care about capturing portions of the match and then throwing
them away:
/^(&(?!&)|[^&]){1,5}$/
--- End Message ---
--- Begin Message ---
Michael Sims wrote:
>> I need a validation regex that will "pass" a string. The string can
>> be no longer than some maximum length, and it can contain any
>> characters except two consecutive ampersands (&) anywhere in the
>> string.
>Yup, use this perl regex:
>
> /^(?:(&)(?!&)|[^&]){1,5}$/
[snip]
>Hope this helps you (pass your exam? ;) )
Thanks, Michael! I guess it is time for me to go review those zero-width
negative look-ahead assertions - don't know how I missed them ;)
And no, not an exam - this is real life. My days as a frolicking schoolboy
are quite some distance behind me ;)
Kirk
--- End Message ---
--- Begin Message ---
PHP List,
The Situation:
I am building a content management system where users can, among
other things, upload images into a directory.
The Problem:
The image uploads fine, but once it's there, it can't be over
written. So if a user uploads an image, and then changes his or her mind
and wants to upload a new version over it, the file upload fails.
What I've Tried So far:
I can manually edit the file permissions using chmod and setting the
files to 777. But of course that's not something I want to have to do
every time someone uploads a file. I don't know enough about file
permissions and settings to know how I can set these permissions at the
time that someone makes the upload.
The Question:
How do I allow a user, who is uploading via the web, place an image
on the server with permissions that allow the file to be over written?
--
Dave Gutteridge
[EMAIL PROTECTED]
--- End Message ---
--- Begin Message ---
Use php's ftp commands.
Hugh
----- Original Message -----
From: "Dave" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Saturday, January 29, 2005 11:11 AM
Subject: [PHP] Permissions on uploaded image don't allow for over writing
PHP List,
The Situation:
I am building a content management system where users can, among
other things, upload images into a directory.
The Problem:
The image uploads fine, but once it's there, it can't be over
written. So if a user uploads an image, and then changes his or her mind
and wants to upload a new version over it, the file upload fails.
What I've Tried So far:
I can manually edit the file permissions using chmod and setting the
files to 777. But of course that's not something I want to have to do
every time someone uploads a file. I don't know enough about file
permissions and settings to know how I can set these permissions at the
time that someone makes the upload.
The Question:
How do I allow a user, who is uploading via the web, place an image
on the server with permissions that allow the file to be over written?
--
Dave Gutteridge
[EMAIL PROTECTED]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.7.4 - Release Date: 1/25/2005
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.7.4 - Release Date: 1/25/2005
--- End Message ---
--- Begin Message ---
Dave wrote:
PHP List,
The Situation:
I am building a content management system where users can, among
other things, upload images into a directory.
The Problem:
The image uploads fine, but once it's there, it can't be over
written. So if a user uploads an image, and then changes his or her
mind and wants to upload a new version over it, the file upload fails.
What I've Tried So far:
I can manually edit the file permissions using chmod and setting
the files to 777. But of course that's not something I want to have to
do every time someone uploads a file. I don't know enough about file
permissions and settings to know how I can set these permissions at
the time that someone makes the upload.
The Question:
How do I allow a user, who is uploading via the web, place an image
on the server with permissions that allow the file to be over written?
Check the permissions on the file you have uploaded. Who is the owner?
Does the user running PHP have the 'w' permission?
Try 'chown'ing the image directory to the user that is running PHP.
-John
-John
--- End Message ---
--- Begin Message ---
Jon wrote:
Starting over since my last thread had too little effort put in it. I
have this script that should create a multi-demensional array that would
resemble a directory structure. The problem is that after adding one
element to a "folder" it appears to be creating a new object instead of
adding another item to the current object. So there can only be one
"file" or "folder" in the parent "folder" with the exception of the top
level. My entire script is below.
Thanks, Jon
<?
class dir {
var $name;
var $subdirs;
var $files;
var $num;
var $prio;
function dir($name,$num,$prio) {
$this->name = $name;
$this->num = $num;
$this->prio = $prio;
$this->files = array();
$this->subdirs = array();
}
function addFile($file) {
$this->files[] =& $file;
return $file;
}
a missing ampersand above might being causing you problems...
function &addFile($file) {
^-------
function &addDir($dir) {
$this->subdirs[] =& $dir;
return $dir;
}
function &findDir($name) {
foreach($this->subdirs as $v){
if($v->name == $name)
return $v;
}
return false;
}
function draw($parent) {
echo('d.add('.$this->num.','.$parent.',"'.$this->name."\",".$this->prio.");\n");
foreach($this->subdirs as $v) {
$v->draw($this->num);
}
foreach($this->files as $v)
if(is_object($v)) {
echo("d.add(".$v->num.",".$this->num.",
\"".$v->name."\",".$v->prio.");\n");
}
}
}
class file {
var $name;
var $prio;
var $size;
var $num;
function file($name,$num,$size,$prio) {
$this->name = $name;
$this->num = $num;
$this->size = $size;
$this->prio = $prio;
}
}
$arFiles = array
(
0 => array
(
'path' => array
(
0 => 'folder1',
1 => 'subfolder1',
2 => 'file1.ext'
),
'length' => 5464,
'size' => 8765
),
1 => array
(
'path' => array
(
0 => 'folder1',
1 => 'subfolder1',
2 => 'file2.ext'
),
'length' => 5464,
'size' => 8765
),
2 => array
(
'path' => array
(
0 => 'folder1',
1 => 'subfolder2',
2 => 'file1.ext'
),
'length' => 5464,
'size' => 8765
),
3 => array
(
'path' => array
(
0 => 'folder2',
1 => 'subfolder1',
2 => 'file1.ext'
),
'length' => 5464,
'size' => 8765
)
);
$prio = array();
for($i=0;$i<count($arFiles);$i++)
$prio[$i] = -1;
$dirnum = count($arFiles);
$tree = new dir("/",$dirnum,isset($prio[$dirnum])?$prio[$dirnum]:-1);
foreach( $arFiles as $filenum => $file) {
$depth = count($file['path']);
$branch =& $tree;
for($i=0; $i < $depth; $i++){
if ($i != $depth-1){
$d =& $branch->findDir($file['path'][$i]);
echo "<BR><B>Tree after find dir:</B>";
print_r($tree);
if($d)
$branch =& $d;
else{
$dirnum++;
$d =& $branch->addDir(new dir($file['path'][$i], $dirnum,
(isset($prio[$dirnum])?$prio[$dirnum]:-1)));
echo "<BR><B>Tree after add dir:</B>";
print_r($tree);
$branch =& $d;
}
}else{
$branch->addFile(new
file($file['path'][$i]." (".$file['length'].")",$filenum,$file['size'],
$prio[$filenum]));
echo "<BR><B>Tree after add file:</B>";
print_r($tree);}
}
}
$tree->draw(-1);
?>
--- End Message ---
--- Begin Message ---
FileInfo is not available on win32.
- Frank
> Chris wrote:
> > Hi,
> >
> > Are there any places that might have instructions on compiling PECL
> > extensions on Windows? I tried going the pear install <package> route,
> > but fileinfo is not considered stable yet.
> >
> > Chris
>
> Trying a PEAR or PECL list might do you more good. That being said...
> are you trying to install packages that are listed as unstable when your
> configuration tries to install stable releases?
>
> --
> Teach a man to fish...
>
> NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
> STFA | http://marc.theaimsgroup.com/?l=php-general&w=2
> STFM | http://www.php.net/manual/en/index.php
> STFW | http://www.google.com/search?q=php
> LAZY |
>
http://mycroft.mozdev.org/download.html?name=PHP&submitform=Find+search+plugins
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
Jason Barnett wrote:
Chris wrote:
Hi,
Are there any places that might have instructions on compiling PECL
extensions on Windows? I tried going the pear install <package>
route, but fileinfo is not considered stable yet.
Chris
Trying a PEAR or PECL list might do you more good. That being said...
are you trying to install packages that are listed as unstable when
your configuration tries to install stable releases?
I tried pear install fileinfo, and got the message "No release with
state equal to: 'stable' found for 'fileinfo'". I installed Pear for the
sole purpose attempting to get fileinfo compiled. I know *nothing* about
it. If I'm understanding you correctly there may be a way to modify the
pear config to compile unstable releases? I'll look into that (hadn't
occured to me before)
I am just trying to get a version of fileinfo (preferably the latest)
working on my PHP 5.0.1 on Win2k Pro. This is a test-only server, so I'm
not too picky about what, or how, but, since I'll probably want more
PECL extensions in the future, I may as well learn the proper way to do it.
Thanks,
Chris
--- End Message ---
--- Begin Message ---
Hi!
I had a script for parsing text into html, similar to phpBB. Everything
has been working fine until now. Some of my 'pseudotags' like [b] are
still recognized (parsed into <b>) but some more advanced pattern
matching is not. I haven't changed the code, but the php-version on the
server has changed from "default" on debian-woody to php-4.3.10. I
haven't made the upgrade myself.
The users of the site reported the bug to me this week, but the users
aren't active so I don't really know when then bug was created. Because
I know it has worked before.
Does any of you have a clue or experience of this? Or has my code been
mysterious altered on the server?
Thanks!
Kristian
--- End Message ---
--- Begin Message ---
Kristian Hellquist wrote:
Hi!
I had a script for parsing text into html, similar to phpBB. Everything
has been working fine until now. Some of my 'pseudotags' like [b] are
still recognized (parsed into <b>) but some more advanced pattern
matching is not. I haven't changed the code, but the php-version on the
server has changed from "default" on debian-woody to php-4.3.10. I
haven't made the upgrade myself.
The users of the site reported the bug to me this week, but the users
aren't active so I don't really know when then bug was created. Because
I know it has worked before.
Does any of you have a clue or experience of this? Or has my code been
mysterious altered on the server?
An example of the expressions?
--- End Message ---
--- Begin Message ---
John Nichel wrote:
Chris W. Parker wrote:
Hello,
I'm looking to make a simple scheduler for myself and I'd like to get
some feedback on how to handle the events and their being executed at
the right time.
The two options I've come up with both involve adding a job(s) to
crontab.
1. Individual jobs are added to the users crontab file. This could
result in LOTS of entries in crontab, but less load on the server.
2. There is one job put in the crontab file that is executed every five
minutes. This job will be executing a PHP file that runs through the
database for the current user and checks to see if any events need to go
off at that time. This will result in only one event in crontab with a
greater potential for load on the server.
I'm leaning towards Option 2*. What do you think? What other options do
I have?
I'd go with option 2 also. Option one wouldn't really be less load, as
it would be more for cron to parse, and pretty much execute the same
amount of times.
Option 2 needs cron too, and the parsing is done by php instead of cron,
so this is not really valid point.
Option 1 also brings into question security and
access. To add entries to the users crontab, your script would have to
have permission to do so (suexec?), and giving it that much access could
be dangerous.
This is a valid point if php scripts are executed as apache user.
What about option 3:
Use at command to execute php script when the next event should be
executed. This php script will execute this task and then set itself to
execute at the time of the next event.
--- End Message ---
--- Begin Message ---
Hello;
I'm trying to figure out the best (most secure and most
user friendly, security of primary importance) way to
let a user log-in.
I am setting up a web application (database
application) that will be for private use only and I
want to keep it secure.
As I understand it, using the Apache htaccess method is
secure as there is essentially no communication without
a username and password, but it does lack a little in
flexibility and presentation.
On the other hand, PHP certainly has the edge on
flexibility and presentation, but I have questions
regarding it's security. If you look at the threads
regarding connecting to databases, you often see a
warning to the effect of: store your connection
password etc, outside of the document path in case PHP
fails and your file is displayed unprocessed.
So my question is, how can you count on PHP to log
somebody in, and prevent access to files when PHP may
fail, or the user could just go into the directory
structure and bypass security.
TIA
Ray
--- End Message ---
--- Begin Message ---
Hi!
I had a script for parsing text into html, similar to phpBB. Everything
has been working fine until now. Some of my 'pseudotags' like [b] are
still recognized (parsed into <b>) but some more advanced pattern
matching is not. I haven't changed the code, but the php-version on the
server has changed from "default" on debian-woody to php-4.3.10. I
haven't made the upgrade myself.
The users of the site reported the bug to me this week, but the users
aren't active so I don't really know when then bug was created. Because
I know it has worked before.
Does any of you have a clue or experience of this? Or has my code been
mysterious altered on the server?
Thanks!
Kristian
--- End Message ---
--- Begin Message ---
Mike Milligan wrote:
I'm have a PHP created HTML form that I want a user to be able to enter data
into, then see it as the PHP/HTML will format it, then post it to an HTML file.
I've been trying all day to find something similar on your site, but to no
avail.
I am really new to PHP so I may not have done things the easy way. The code
below outputs the proper data, but it does it without user concent. I'd like
to have the user review what they typed prior to posting it to dates.htm.
Any help would be appreciated.
Thanks.
Mike
code as follows:
<?php
//-------------------------INITIALIZE VARIABLES
$filename = 'dates.htm';
$handle = fopen($filename, "rb");
$old = fread($handle, filesize($filename));
fclose($handle);
$date = $_REQUEST['date'] ;
$title = $_REQUEST['title'] ;
$desc = $_REQUEST['desc'] ;
$place = $_REQUEST['place'] ;
$cost = $_REQUEST['cost'] ;
$info = $_REQUEST['info'] ;
//-------------------------DISPLAY FORM
if (!isset($_REQUEST['date']))
{
?>
<html>
<head>
<title>Add New Event</title>
</head>
<body bgcolor="#FFFFFF">
<form method="get" action="calendar.php">
<table style="border-collapse: collapse;" bordercolor="#000000"
cellspacing="0" cellpadding="2" border="0">
<tr>
<td valign="top" align="left" width="18%">
<div>Event Date: </div></td>
<td valign="top">
<div>
<input type="text" name="date"></div></td>
<td> </td></tr>
<tr>
<td valign="top" align="left" width="18%">
<div>Event Title: </div></td>
<td valign="top">
<div>
<input type="text" name="title"></div></td>
<td> </td></tr>
<tr>
<td valign="top" align="left" width="18%">
<div>Event Description: </div></td>
<td valign="top" colspan="2">
<div><textarea name="desc" rows="15" cols=50%>
</textarea></div></td></tr>
<tr>
<td valign="top" align="left" width="18%">
<div>Location: </div></td>
<td valign="top">
<div>
<input type="text" name="place"></div></td>
<td> </td>
<tr>
<td valign="top" align="left" width="18%">
<div>Cost: </div></td>
<td valign="top">
<div>
<input type="text" name="cost"></div></td>
<td> </td></tr>
<tr>
<td valign="top" align="left" width="18%">
<div>Additional Information: </div></td>
<td valign="top" colspan="2">
<div><textarea name="info" rows="6" cols=50%>
</textarea></div></td></tr>
</table>
<input type="submit" value="Add New Event">
<input type="reset" value="Clear Form" name="reset">
</FORM>
</body>
</html>
<?
}
//CHECK FOR EMPTY FIELDS
elseif (empty($date) || empty($desc))
{
header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
header( "Cache-Control: no-cache, must-revalidate" );
header( "Pragma: no-cache" );
?>
<html>
<head><title>Error</title></head>
<body>
<h1>Incomplete Form</h1>
<p>
The date and description of the event are required fields. Press your BACK
button and try again.</p>
</body>
</html>
<?
}
//-----------------------------------PROCESS FORM
elseif(!empty($date) || !empty($desc))
{
//SET FORM VARIABLES
$a = '<strong><font color="#666699" size="4" face="Arial, Helvetica,
sans-serif">';
$b = '</font></strong></p><blockquote><p><font color="#666699" face="Arial,
Helvetica, sans-serif"><strong><b>';
$c = '</b></strong></font></p><p><font color="#666699" face="Arial,
Helvetica, sans-serif">';
$d = '</font></p><p><font color="#666699" face="Arial, Helvetica,
sans-serif">';
$e = '<br></font><font color="#666699" face="Arial, Helvetica, sans-serif">';
$f = '</font></p></blockquote>';
//JOIN VARIABLES
$all = array($a,$date,$b,$title,$c,$desc,$d,$place,$e,'Price:
',$cost,$d,'Additional Information: ',$info,$f);
$new = implode($all);
$array = array($new,$old);
$joined = implode($array);
//CONFIRM ADDITION
?><html>
<head>
<title>Entry Verification</title>
</head>
<body bgcolor="#FFFFFF">
<h1>Please check your new entry!</h1><p>
Correct errors by hitting your BACK button.<p>
<?
echo $new;
?>
<form method="post" action="calendar.php">
<input type="submit" value="Submit">
Put here this, it will passed to your next page:
<input type="hidden" name="new" value="<?php echo htmlspecialchars($new)
?>">
</FORM>
</body>
</html>
<?
You are writing to your file right after displaying confirmation. You
should have here:
} elseif(isset($_REQUEST['new'])) {
Don't forget to check for (non)existance of $_REQUEST['new'] where
necessary.
//------------------------------------FILE ACCESS & WRITING
//OPEN FILE
if (!$handle = fopen($filename, 'w'))
{
echo "Cannot open file ($filename)";
exit;
}
//WRITE TO FILE
if (fwrite($handle, $joined) === FALSE)
{
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($joined) to file ($filename)";
fclose($handle);
}
?>
--- End Message ---
--- Begin Message ---
Hello everyone,
I have been troubleshooting a problem with one of my scripts for a
while now, its purpose is to allow a user to upload a file, save it to
the server, resize it into a thumbnail, and save the thumbnail as
well. In my script all goes well until it comes to saving the images,
the script throws these errors:
Warning: imagepng(): Unable to open
'/home/blacknut/public_html/picserv/picserv_mysql/pictures/blacknute/15.png'
for writing in /home/blacknut/public_html/picserv_mysql/addpic.php on
line 91
Warning: imagepng(): Unable to open
'/home/blacknut/public_html/picserv/picserv_mysql/pictures/blacknute/15t.png'
for writing in /home/blacknut/public_html/picserv_mysql/addpic.php on
line 95
Picture "ffq" was added to our database! The following is what we have
generated and it is what others will see
Here is the important part of the script, if more is needed i can post
it as well.
if ($mime_type == 'jpeg') {
$new_image = imagecreatefromjpeg($_FILES['new_image']['tmp_name']);
//Create an image refrence
}
elseif ($mime_type == 'png') {
$new_image = imagecreatefrompng($_FILES['new_image']['tmp_name']);
//Create an image refrence
}
elseif ($mime_type == 'gif') {
$new_image = imagecreatefromgif($_FILES['new_image']['tmp_name']);
//Create an image refrence
}
//Image Sizes
list($new_image_width, $new_image_height) =
getimagesize($_FILES['new_image']['tmp_name']);//Get img size
if ($new_image_width > $new_image_height) {//Get thumb size
$percent_image_size = (200 / $new_image_width);
}
elseif ($new_image_width < $new_image_height) {
$percent_image_size = (200 / $new_image_height);
}
else {
$percent_image_size = (200 / $new_image_height);
}
$new_thumb_width = ($percent_image_size * $new_image_width);
$new_thumb_height = ($percent_image_size * $new_image_height);
$new_thumb_file = imagecreatetruecolor($new_image_width,
$new_image_height);
imagepng($new_image,
'/home/blacknut/public_html/picserv/picserv_mysql/pictures/' .
strtolower($_SESSION['user_sn']) . '/' . $new_pic_filename . '.png');
//Copy pic to user dir as pic_id.png
$new_thumb_image = imagecreatetruecolor($new_thumb_width,
$new_thumb_height); // Create Thumb file
imagecopyresampled($new_thumb_image, $new_image, 0, 0, 0, 0,
$new_thumb_width, $new_thumb_height, $new_image_width,
$new_image_height); //Copy resized to new thumb file
imagepng($new_thumb_image,
'/home/blacknut/public_html/picserv/picserv_mysql/pictures/' .
strtolower($_SESSION['user_sn']) . '/' . $new_pic_filename . 't.png');
//Save image thumb
I am very new to file/image manipulation in php so if you see any
errors, or unnecessary code please tell me. I'm not quit sure how
everything works, although I do have a theoretical picture of how it
does. Any comments will be appreciated.
--nathan
--
http://www.blacknute.com/
--- End Message ---
--- Begin Message ---
Hi All,
I am looking for advice regarding design patterns/code generation in PHP5.
I have a simple code generation tool (written in PHP) to interface with
database. It works fine for simple situations but seems a little
"strange" for more complex ones.
Suppose I have a table user (id, name, age) and a table
account(idAccount, idUser, name). My generator creates a class for each
table and a standard db class. Each class basically has a set/get
method for each property and some "standard" insert, delete, update,
search methods
ex.
class user
{
var $db
function setName(..)
function getName()
function insert()
{
$this->db->query("insert into user values...")
}
...
}
I've omited the other methods/constructor but you can get the picture.
The problem comes when I have to access information the comes from 2+
tables. Suppose I have to show all users accounts. Now I end up with
something like this.
$u = new User() ;
$a = new Account() ;
if($u->search())
{
for($i=0;$i<...)
{
$idUser = $u->getId() ; $u->next() ;
$a->setIdUser($idUser) ;
if($a->search())
{
// print
}
}
While this works I feel there must be an easier/cleaner way. If I was just
querying the database a join would give me the result in one pass.
In my case what should I do ? create a new method "showAccounts" ?
Where should I put it, in User or Account class ?
I am interested in advices regarding how to design it better so I can
make the proper adjustments in my generator.
--- End Message ---
--- Begin Message ---
Hi,
I tried mysql_connect() function, and it won't reture FALSE if
connection failed. Instead, the script times out after 30 seconds and
displays an Fatal error message "Maximum execution time of 30 seconds
exceeded". For example:
mysql_connect(' ',' '); returns TRUE because mysql logs in the user as
guest. But mysql_connect('servername','username','wrongpassword');
does not return FALSE. Instead, the script continues until it times
out. Does anyone know if this is a known bug, or can this be fixed by
changing a diretive/setting that I don't know about?
thanks,
Tom
P.S., I am using PHP 4.3.10, Apache 2.0.52(win 32), MSIE 6.0, Mysql
4.0.23-nt, Windows NT 5.1 (XP)
--- End Message ---
--- Begin Message ---
On 29 Jan 2005 tom soyer wrote:
> I tried mysql_connect() function, and it won't reture FALSE if
> connection failed. Instead, the script times out after 30 seconds and
> displays an Fatal error message "Maximum execution time of 30 seconds
> exceeded".
I think the issue here is if the server does not respond it hits the
execution time limit before the function returns.
I use code like this:
$olderr = error_reporting(0);
set_error_handler('ignoreerrhandler');
$dbHandle = mysql_connect($dbHost, $dbUser, $pw);
restore_error_handler();
error_reporting($olderr);
.....
function ignoreerrhandler($errno, $errstr, $errfile, $errline) {
return;
}
You can also control the connection timeout with the
mysql.connect_timeout setting in php.ini.
--
Tom
--- End Message ---
--- Begin Message ---
Thanks for the error handling code. I think PHP still has a basic
problem. If mysql sever connection times out because wrong username or
password was used, then mysql_connect() should return FALSE. But this
is not the case, why? Is it possible that mysql_connect() could not
read the "connection failed" message from mysql server?
On Sat, 29 Jan 2005 23:01:46 -0500, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> On 29 Jan 2005 tom soyer wrote:
>
> > I tried mysql_connect() function, and it won't reture FALSE if
> > connection failed. Instead, the script times out after 30 seconds and
> > displays an Fatal error message "Maximum execution time of 30 seconds
> > exceeded".
>
> I think the issue here is if the server does not respond it hits the
> execution time limit before the function returns.
>
> I use code like this:
>
> $olderr = error_reporting(0);
> set_error_handler('ignoreerrhandler');
> $dbHandle = mysql_connect($dbHost, $dbUser, $pw);
> restore_error_handler();
> error_reporting($olderr);
>
> .....
>
> function ignoreerrhandler($errno, $errstr, $errfile, $errline) {
> return;
> }
>
> You can also control the connection timeout with the
> mysql.connect_timeout setting in php.ini.
>
> --
> Tom
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
tom soyer wrote:
> Thanks for the error handling code. I think PHP still has a basic
> problem. If mysql sever connection times out because wrong username or
> password was used, then mysql_connect() should return FALSE.
It does, at least for me on PHP 4.3.10 connecting to a local MySQL 4.0.23
server on Debian. It returns a boolean false, and a warning is triggered:
Warning: mysql_connect(): Access denied for user: '[EMAIL PROTECTED]' (Using
password: YES) in ...
If I give it a server name it cannot connect to (due to a firewall blocking
the connection, for example) it will hang for about 60 seconds then return
false, triggering a warning:
Warning: mysql_connect(): Can't connect to MySQL server on ...
I was going to suggest that you run a cli test script and trace the system
calls to see what's going on but then I saw that you're using Windows. I'm
not sure if there is an strace/truss equivalent for it (anyone know)?
--- End Message ---