php-general Digest 14 Nov 2008 20:45:16 -0000 Issue 5790

Topics (messages 283283 through 283307):

Re: Weird pdo-mysql behavior
        283283 by: Martijn Korse
        283284 by: Thodoris
        283285 by: Thodoris

Re: Weird Syntax Error
        283286 by: Thodoris

Re: standard safe permissions for php scripts in web directory
        283287 by: Thodoris

Re: mySQL query question
        283288 by: Thodoris
        283298 by: Martijn Korse
        283299 by: ceo.l-i-e.com
        283300 by: Bastien Koert
        283301 by: mikesd1.verizon.net
        283304 by: Jim Lucas
        283305 by: Bastien Koert
        283306 by: mikesd1.verizon.net
        283307 by: Jim Lucas

Comparative performance
        283289 by: Richard Heyes
        283290 by: Rene Veerman
        283292 by: Richard Heyes
        283293 by: Rene Veerman
        283302 by: Robert Cummings

Accessing mysql_fetch_object with variable names
        283291 by: Baniz Daymov
        283295 by: Matt Jones
        283296 by: Baniz Daymov

Re: how to implement search on site
        283294 by: tedd
        283297 by: tedd
        283303 by: Al

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 ---
I agree, add some checks in your testcase so you can track exactly what is
happening and see of what type your variables are.
Also, try what happens when you
- switch off persistent-connections (PDO::ATTR_PERSISTENT=> false)
- pass the object by reference (getClientFullName($id,&$dbh))


-----
http://devshed.excudo.net http://devshed.excudo.net 
-- 
View this message in context: 
http://www.nabble.com/Weird-pdo-mysql-behavior-tp20478083p20496495.html
Sent from the PHP - General mailing list archive at Nabble.com.


--- End Message ---
--- Begin Message ---

I agree, add some checks in your testcase so you can track exactly what is
happening and see of what type your variables are.
Also, try what happens when you
- switch off persistent-connections (PDO::ATTR_PERSISTENT=> false)

Tried that using both ways because I saw a similar error in another bug in PHP but still doesn't fetch the data.

- pass the object by reference (getClientFullName($id,&$dbh))

Also did that without making any difference. I am wondering if this has to do with PHP itself or with the way my distro is distributing the package.

-----
http://devshed.excudo.net http://devshed.excudo.net

Thanks anyway though for the suggestions.

--
Thodoris


--- End Message ---
--- Begin Message ---

Perhaps when you try to make the connection you should check the return value 
and use whatever PDO error-checking methods exist to find out what went wrong, 
instead of blindly going forward assuming you have a database connection when 
you don't.

As a said before I have dumped the hander and all the params before passing them into the function and the object has been crated. As I said the exact same code works in the same system using a different (compiled) apache and a different (compiled) version of PHP without any problems. It also works in another system using a compiled apache and PHP.

Ditto for any result of ->query()

What you are doing now is akin to turning the key in a car, not listening to 
see if it started, and asking a mechanic on the phone why the gas pedal doesn't 
work...

:-)



So I will have to assume that the rpm is not behaving as expected or that there is a bug in that specific version of PHP.

--
Thodoris


--- End Message ---
--- Begin Message ---

-----Original Message-----
From: Edgar da Silva (Fly2k) [mailto:[EMAIL PROTECTED]
Sent: Thursday, November 13, 2008 9:39 AM
To: Kyle Terry
Cc: PHP General Mailing List
Subject: Re: [PHP] Weird Syntax Error

Try:

$insert = "INSERT INTO release_file_upload (upl_file_name,
upl_file_type,
upl_file_size, upl_date, upl_by, upl_path, release_id) VALUES
('$filename',
'{$_SESSION['upload']['type']}', '{$_SESSION['upload']['size']}',
now(),
'$username', '$path', '$release_id')";

2008/11/13 Kyle Terry <[EMAIL PROTECTED]>:
I keep getting this syntax error on the following string...

syntax error unexpected T_ENCAPSED_AND_WHITESPACE expecting T_STRING
or
T_VARIABLE or T_NUM_STRING

$insert = "INSERT INTO release_file_upload (upl_file_name,
upl_file_type,
upl_file_size, upl_date, upl_by, upl_path, release_id) VALUES
('$filename',
'$_SESSION['upload']['type']', '$_SESSION['upload']['size']', now(),
'$username', '$path', '$release_id')";

Yup... I was just about to say--you need to wrap your array references with curly braces {}. 
Otherwise, I believe PHP will look for a primitive variable named $_SESSION, not an array whose 
indices are "upload" and "size".

HTH,


Todd Boyd
Web Programmer

You could also use the "." operator instead and quote using the quote method if you are using PDO.

But this is a personal style I guess.

--
Thodoris


--- End Message ---
--- Begin Message ---

Sounds like a weird question though :( what should be standard safe php
script/directory permissions under Apache.

This can vary in some cases. Generally speaking all scripts that ran by apache (using the php module) are using the rights of the user that apache is running as. So this user (that you may find who it is in your httpd.conf like for e.g. "User apache") has to be able to at least read you scripts. In addition to that if you need to upload files you will have to give this user the right to be able to write in the directories you plan to upload the files and read rights to the above directories in order to "see" where they are.

You shouldn't though give the right to this user to write in other directories beside the ones you upload files for security reasons. This is because if someone compromises apache we could in some cases do whatever apache does (meaning that we can write where apache does). Moreover if your project has a flaw and someone can use that flaw he can write were apache writes as well (or perhaps where your script can).

So IMHO it is good to carefully define the rights but test if your scripts run and make the proper changes as needed. This of course probably needs changes to ownership as well.

--
Thodoris


--- End Message ---
--- Begin Message ---

okay I want to pull an integer from a database called confirm_number,
add 1 and repost it back to the database


here's the code I'm using.


$queryconfirm="SELECT confirm_number from contacts ORDER BY contact DESC
LIMIT 1";

I assume that you are already aware that if you set the variable $queryconfirm to this SQL query that the query is not necessarily executed and returns the result into the variable.
$confirmresult=$queryconfirm;

Now what you did is that $confirmresult is now:

"SELECT confirm_number from contacts ORDER BY contact DESC LIMIT 1"

as well as $queryconfirm. Why is that?
now here's the problem
I want to add 1 to confirm_number:

$confirm_number=$confirmresult;
$confirm_number+=1;

I will also assume that you don't think that $confirm_number will magically contain the result.
Now all this does is set the confirm_number record to 1 in the database.
So I assume that $queryconfirm somehow is not being passed to
confirm_number?  But, while we're here the confirm_number is supposed to
be 5 digits long and the +1 should make it 10001, 10002, 10003 etc

how would I set the original number to 1000 to begin with? Or should I
just set that in the database record its self when I'm ready to use the
website?

If what I assume is right (I don't want to disappoint you) but you should start reading some PHP basics on how you make database connection in PHP. Use google to find some tutorial for e.g.

If I am wrong post us the code to see if someone can help.

--
Thodoris


--- End Message ---
--- Begin Message ---
I would create a separate table for this (confirmation_numbers or something)
with an autoincrement primary key. That way you can simply insert a new
record for you contact and then ask (using mysql_insert_id()) what the
confirmation number is.
This approach is much safer as you can be 100% sure the number is unique and
it's much less complicated. (of course you still need to check if the query
didn't fail)

-----
http://devshed.excudo.net http://devshed.excudo.net 
-- 
View this message in context: 
http://www.nabble.com/mySQL-query-question-tp20495466p20501473.html
Sent from the PHP - General mailing list archive at Nabble.com.


--- End Message ---
--- Begin Message ---
> okay I want to pull an integer from a database called confirm_number, 

> add 1 and repost it back to the database



No, you don't want to do that.

:-)



You are introducing a race condition between TWO users who hit the same page at 
the same time.



They each get, say, 42, and they each put back 43, but one of them should have 
been 44.



What you WANT to do is this:

update contacts set confirm_number = confirm_number + 1 order by contact desc 
limit 1



--- End Message ---
--- Begin Message ---
On Fri, Nov 14, 2008 at 9:58 AM, <[EMAIL PROTECTED]> wrote:

>
> > okay I want to pull an integer from a database called confirm_number,
> > add 1 and repost it back to the database
>
> No, you don't want to do that.
> :-)
>
> You are introducing a race condition between TWO users who hit the same
> page at the same time.
>
> They each get, say, 42, and they each put back 43, but one of them should
> have been 44.
>
> What you WANT to do is this:
> update contacts set confirm_number = confirm_number + 1 order by contact
> desc limit 1
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
yep, our current app, designed by 'brighter minds' than mine, refused to
make these auto numbers and now we have problems caused by the race
condition.

-- 

Bastien

Cat, the other other white meat

--- End Message ---
--- Begin Message ---
update contacts set confirm_number = confirm_number + 1 order by
contact
desc limit 1

Here is the php query I've been using to send the record in the first
place

$query="INSERT INTO contacts (first_name, last_name, email, phn_number,
address, city, state, zip, dates, comments, confirm_number) VALUES
('$FirstName', '$LastName', '$Email', '$Phone', '$Address', '$City',
'$selected_state', '$Zip', '$newdate', '$Comments'  ,
'$confirm_number'  )";
[EMAIL PROTECTED] ($query);

(obviously in the script, it's all on one line)

Now, what I need to do, is somehow pull make confirm_number get
submitted as a new record, which will happen once they submit the form,
but I want it to be submitted +1. (12345 should now be 12346 but a new
record entirely)


I was trying this code before the submission query:

$confirmnumber="SELECT confirm_number from contacts ORDER BY contact
DESC LIMIT 1";
$confirm_number=$confirmnumber+1;

Now what this is doing for me so far, is just taking the first numeral
of the record, which happens to be 4 (I originally added the
confirm_number via the rand function, but have since taken that out) and
adding 1 to it and that is it.

So the new $confirm_number=5
So it sort of did the job, but not quite..


The question is how can I make a new record (I know the answer to that
part) BUT with a confirm_number of 1 greater than the previous record.



--
Michael S. Dunsavage

--- End Message ---
--- Begin Message ---
[EMAIL PROTECTED] wrote:
>> update contacts set confirm_number = confirm_number + 1 order by
>> contact
>>> desc limit 1
> 
> Here is the php query I've been using to send the record in the first
> place
> 
> $query="INSERT INTO contacts (first_name, last_name, email, phn_number,
> address, city, state, zip, dates, comments, confirm_number) VALUES
> ('$FirstName', '$LastName', '$Email', '$Phone', '$Address', '$City',
> '$selected_state', '$Zip', '$newdate', '$Comments'  ,
> '$confirm_number'  )";
> [EMAIL PROTECTED] ($query);
> 
> (obviously in the script, it's all on one line)
> 
> Now, what I need to do, is somehow pull make confirm_number get
> submitted as a new record, which will happen once they submit the form,
> but I want it to be submitted +1. (12345 should now be 12346 but a new
> record entirely)
> 
> 
> I was trying this code before the submission query:
> 
> $confirmnumber="SELECT confirm_number from contacts ORDER BY contact
> DESC LIMIT 1";
> $confirm_number=$confirmnumber+1;
> 
> Now what this is doing for me so far, is just taking the first numeral
> of the record, which happens to be 4 (I originally added the
> confirm_number via the rand function, but have since taken that out) and
> adding 1 to it and that is it.
> 
> So the new $confirm_number=5
> So it sort of did the job, but not quite..
> 
> 
> The question is how can I make a new record (I know the answer to that
> part) BUT with a confirm_number of 1 greater than the previous record.
> 
> 
> 

Ok, so just that I am clear, you are SELECTing and pulling all the data that 
you are submitting in the above INSERT statement from the DB initially,
then you are only modifying the confirm_number value and then re-submitting all 
the values, as they originally were, back to the DB and creating a
copy of the original data.  The only difference being that the $confirm_number 
has been altered.  Correct?

-- 
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare


--- End Message ---
--- Begin Message ---
On Fri, Nov 14, 2008 at 1:22 PM, <[EMAIL PROTECTED]> wrote:

> update contacts set confirm_number = confirm_number + 1 order by
>> contact
>>
>>> desc limit 1
>>>
>>
> Here is the php query I've been using to send the record in the first
> place
>
> $query="INSERT INTO contacts (first_name, last_name, email, phn_number,
> address, city, state, zip, dates, comments, confirm_number) VALUES
> ('$FirstName', '$LastName', '$Email', '$Phone', '$Address', '$City',
> '$selected_state', '$Zip', '$newdate', '$Comments'  ,
> '$confirm_number'  )";
> [EMAIL PROTECTED] ($query);
>
> (obviously in the script, it's all on one line)
>
> Now, what I need to do, is somehow pull make confirm_number get
> submitted as a new record, which will happen once they submit the form,
> but I want it to be submitted +1. (12345 should now be 12346 but a new
> record entirely)
>
>
> I was trying this code before the submission query:
>
> $confirmnumber="SELECT confirm_number from contacts ORDER BY contact
> DESC LIMIT 1";
> $confirm_number=$confirmnumber+1;
>
> Now what this is doing for me so far, is just taking the first numeral
> of the record, which happens to be 4 (I originally added the
> confirm_number via the rand function, but have since taken that out) and
> adding 1 to it and that is it.
>
> So the new $confirm_number=5
> So it sort of did the job, but not quite..
>
>
> The question is how can I make a new record (I know the answer to that
> part) BUT with a confirm_number of 1 greater than the previous record.
>
>
>
> --
> Michael S. Dunsavage
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
make that field an autonumber and let the database assign it. much much
cleaner and simple to get the number with mysql_last_insert()

-- 

Bastien

Cat, the other other white meat

--- End Message ---
--- Begin Message ---
>Ok, so just that I am clear, you are SELECTing and pulling all the data 
>that you are submitting in the above INSERT statement from the DB 
>initially,
>then you are only modifying the confirm_number value and then re-
>submitting all the values, as they originally were,

Well, actually when all is said and done, a new record will be created with 
new information (Name, phone, email, etc) and the confirm_number is the 
previous+1


This whole thing is a contact form.

--- End Message ---
--- Begin Message ---
[EMAIL PROTECTED] wrote:
>> Ok, so just that I am clear, you are SELECTing and pulling all the data 
>> that you are submitting in the above INSERT statement from the DB 
>> initially,
>> then you are only modifying the confirm_number value and then re-
>> submitting all the values, as they originally were,
> 
> Well, actually when all is said and done, a new record will be created with 
> new information (Name, phone, email, etc) and the confirm_number is the 
> previous+1
> 
> 
> This whole thing is a contact form.
> 

Well, in that case, you might be able to do something along the lines of this.

I tested this on my server:
        Server version: 5.0.51a-log
        MySQL client version: 5.0.51a
        using phpMyAdmin - 2.11.1.2

I have modified an example from this page:
        http://dev.mysql.com/doc/refman/5.0/en/user-variables.html

<?php
#
# Setup database stuff, process input, get everything ready to do the insert.
#

# Now prepare your statement
$SQL = "
SET @confirm_number=(SELECT (MAX(confirm_number)+1) FROM `contacts`);
INSERT INTO `contacts` (
                      `first_name`,
                      `last_name`,
                      `email`,
                      `phn_number`,
                      `address`,
                      `city`,
                      `state`,
                      `zip`,
                      `dates`,
                      `comments`,
                      `confirm_number`
                      ) VALUES (
                      '{$FirstName}',
                      '{$LastName}',
                      '{$Email}',
                      '{$Phone}',
                      '{$Address}',
                      '{$City}',
                      '{$selected_state}',
                      '{$Zip}',
                      '{$newdate}',
                      '{$Comments}',
                      @confirm_number
                      )
SELECT @confirm_number AS confirm_number;
";
$confirm_number = NULL;
# Run it and get confirm_number to work with now.
if ( ($result = @mysql_query($SQL)) !== FALSE ) {
    list($confirm_number) = mysql_fetch_row($result);
}

if ( is_null($confirm_number) ) {
    echo 'Failed to get number';
}

?>

Obviously, I can't test this without your schema.  So, I hope it works.

In the end, you should have a result set that gets returned that contains the 
'confirm_number' of the newly created entry.

This should also, pretty much, eliminate any chance of a race condition.  Since 
everything is happening within mysql, it should be very hard to end up
with a condition that you start stomping on records.

Let the list know if it works for you.

-- 
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare


--- End Message ---
--- Begin Message ---
Hi,

Can I get input on the following:

Uncompressed library: 15k
Compressed library, but using the PHP engine (ie ob_start()): 3.5k

Which would be better? Obviously from the client perspective
compressed would be better, but from the servers perspective...? An
increase in the amount of time to put the file on the pipe, or an
increase (no matter how small) in load because of the PHP engine and
compression.

Thanks.

-- 
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated November 1st)

--- End Message ---
--- Begin Message ---
Richard Heyes wrote:
Hi,

Can I get input on the following:

Uncompressed library: 15k
Compressed library, but using the PHP engine (ie ob_start()): 3.5k

Which would be better? Obviously from the client perspective
compressed would be better, but from the servers perspective...? An
increase in the amount of time to put the file on the pipe, or an
increase (no matter how small) in load because of the PHP engine and
compression.

Thanks.

What do you mean by compressed lib? JS?
If you cache your compressed libs on disk, your total processing on the php end should go down..

--
--------------------------------------------------------------
Rene Veerman, creator of web2.5 CMS http://mediabeez.ws/
--- End Message ---
--- Begin Message ---
> What do you mean by compressed lib? JS?

Javascript minification and HTTP gzip compression. Doing this got a
25k+ library down to 3.5k (!).

-- 
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated November 1st)

--- End Message ---
--- Begin Message ---
Richard Heyes wrote:
What do you mean by compressed lib? JS?

Javascript minification and HTTP gzip compression. Doing this got a
25k+ library down to 3.5k (!).

then definately cache the result (on disk!) (both plaintext and gzip), output the cached result each time you can.
overhead will be reduced to a minimum.

--
--------------------------------------------------------------
Rene Veerman, creator of web2.5 CMS http://mediabeez.ws/
--- End Message ---
--- Begin Message ---
On Fri, 2008-11-14 at 12:12 +0000, Richard Heyes wrote:
> Hi,
> 
> Can I get input on the following:
> 
> Uncompressed library: 15k
> Compressed library, but using the PHP engine (ie ob_start()): 3.5k
> 
> Which would be better? Obviously from the client perspective
> compressed would be better, but from the servers perspective...? An
> increase in the amount of time to put the file on the pipe, or an
> increase (no matter how small) in load because of the PHP engine and
> compression.

Better to use compression. It frees up the webserver process faster to
handle other connections. The longer you have a request being served the
longer the resources allocated to serve the request are unavailable to
other requests. So what benefits the client, small download size, also
benefits the server. Also, if possible, use web server compression
(mod_gzip or mod_deflate) instead of PHP compression.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


--- End Message ---
--- Begin Message ---
So, I have a newbie syntax question, sorry to bother you with noddy stuff.

I have fetched a set of results from a database quesry using
mysql_fetch_object. I want to iterate through a subset of the columns
from each result, as defined by a separate array. I don't seem to be
able to find the correct syntax for referencing the specific property
of the object with a variable name.

Here's my broken code:

$tabarray = array("bio", "research", "publications", "supervision");
$staffdata = mysql_fetch_object( $result );

foreach ( $tabarray as $tab ) {

        echo "<li>$staffdata->$tab</li>\n";

}

Hope that's clear what I'm trying to do. I know I could iterate
through every database column and discard any column not in tabarray
or use eval() to build a line of code that did the trick but I'm sure
there must be a more elegant way to get $staffdata->$tab to
interpolate to $staffdata->bio etc and I'm just too inexperienced to
know what it is.

Thanks in advance for your help folks.

-- 
BD

--- End Message ---
--- Begin Message ---
I have been thumped with the clue bat and now have a solution.

Thanks for your time!

-- 
Matt

--- End Message ---
--- Begin Message ---
I have been thumped with the clue bat and now have a solution.

Thanks for your time!

-- 
BD

--- End Message ---
--- Begin Message ---
At 9:26 AM +0000 11/13/08, Jignesh Thummar wrote:
I have site of around 25 pages (pure HTML pages). I want to implement search
functionality? How can I? i want to avoid database. And Apache Lucene, i
dont't want to use it. Does any PHP framework provide search and indexing
functionality (Exception Zend_Lucene)?

Thanks,
Jignesh

Might consider this:

http://sperling.com/examples/search/

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
At 8:24 AM -0600 11/13/08, Boyd, Todd M. wrote:
If you're mainly worried about indexing public pages, why not implement
a Google custom search? They do all the heavy lifting--you just worry
about maintaining your website. All the same SEO you do for Google will
then apply to your website internally...


Todd Boyd
Web Programmer


I considered that, but it looked like to me to put a Google search into your site, they require ad space.

So, I use this:

http://sperling.com/examples/search/

They don't and it works pretty good.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---


Jignesh Thummar wrote:
I have site of around 25 pages (pure HTML pages). I want to implement search
functionality? How can I? i want to avoid database. And Apache Lucene, i
dont't want to use it. Does any PHP framework provide search and indexing
functionality (Exception Zend_Lucene)?

Thanks,
Jignesh


Is your requirement for Users or as web designer's tool?

A few months ago I wrote a rather complete website search program that is great for techies, but not suitable for users. You are welcome to a copy if your need is technical.

It uses regex matches, with wild cards, for directories, files and text. 
Requires php 5+

--- End Message ---

Reply via email to