[PHP-DB] PHP & MySQL High CPU on Query

2012-06-12 Thread David Christensen
I have a situation where a query run from PHP/Zend Framework on a MySQL
database seems to hit the CPU harder than the same query run via the
MySQL command line.

The query is a simple SELECT statement querying 2 tables, 12 columns
with a short WHERE clause that filters the results to less than 100
records.

ZF is using the PDO adapter.  I've seen the query cause mysqld to show a
spike up to 50+% cpu while the query is run from a PHP call, and the
same query from the client barely nudges the process to 1%.

Is there something I can do to gather more data on what's going on and
why this is happening?  I'd expect some overhead, but that much of a
difference seems wrong.

Thanks for your advice,

David Christensen

=

This electronic mail is solely for the use of the intended recipient, 
and may contain information that is privileged, 
confidential and exempt from disclosure under applicable law. 
If the reader of this message is not the intended recipient 
– whether as addressed or as should reasonably be surmised by the reader – 
you are hereby notified that any dissemination, distribution or copying of this 
electronic mail 
or any attachment is strictly prohibited. 
If you have received this communication in error, 
please do not print, copy, retransmit, disseminate or otherwise use the 
information 
contained herein or attached hereto and notify us immediately 
by replying to the electronic mail address listed above. 
After notifying us, please delete the copy you received. 
Thank you.


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Unknown column 'Test' in 'field list'

2002-03-28 Thread David Christensen

Change your query to this and make sure your ID field is set to 
"auto_increment"

INSERT INTO entry (user_name) values ('$name')

That'll work for sure! ;-)


Jennifer Downey wrote:

> Hi All!
> 
> Hope I'm not bothering you nice people too much.
> 
> I have a account called Test, when I click the submit button I get this
> error
> 
> Unknown column 'Test' in 'field list'
> 
> My table only has two fields id and user_name
> 
> I am not trying to insert the data into the field Test but into usre_name.
> I had this problem  once before but I can't remember how I fixed it or if I
> ever did. Any ideas?
> 
> 
>  if($action == "Submit my entry"){
> if (!empty($name)){
> $enter = "insert into entry (id, user_name) values (' ',$name)";
> mysql_query($enter) or die(mysql_error());
> }
> exit;
> }
> $query="SELECT name FROM users WHERE uid=".$session["uid"];
> $ret = mysql_query($query) or die(myasql_error());
> list($name) = mysql_fetch_array($ret);
> ?>
> 
> 
> 
> 
>  print "Username:  name=\"u_name\" size=30>\n";
> print " entry\">";
> ?>
> 
> 
> 
> 
> 
> 
> 
> 



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] Contact Database php_mysql

2002-03-26 Thread David Christensen

Not so sure you need to go to that much detail in the linking of your
tables.  It's a good idea for the states, but the zip is usually just an
integer anyway, so you can just store that with the record.  Next, do
you really need "Full_Name"???  You can extract that from the other two
fields.  As for city, that's going to be a HUGE table.  The only
advantage to making another table out of such is if you had more data
per record and you need to search really fast.  Just store that in with
the Contact info the single table.

The way I'd do it would be like this:

[Contacts]
ID int primary key auto_increment not null
fname varchar(25) not null
lname varchar(35) not null
mname varchar(25)
suffix varchar(5)
addr1 varchar(35)
addr2 varchar(35)
city varchar(35) not null
state int not null
zip int not null

[State]
ID int primary key auto_increment not null
state varchar(25)

The field sizes are arbitrary, so think about what you're gonna need and
size appropriately.


Russell Griechen wrote:
> 
> I am contemplating a Historical Database
> I barely can spel redundant let alone normalize so I am handicapped.
> The aim is to enter a name only once. I am studying linking tables.
> In the [Contact]
> idContact
> First_Name,Last_Name,Middle,Suffix,Full_Name,idCity,idState,City_State,i
> dZip_Code,
> Address_1,Address_2,
> 
> [City]
> id
> Cityname
> 
> id (al, ar etc)
> Statename
> 
> [ZipCode]
> id
> Zip_Code
> 
> Comment please,
> Russell Griechen
> 
> --
> 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




Re: [PHP-DB] Speed Up Code?

2002-03-24 Thread David Christensen

The first thing I see, do you need all of the fields in your "SELECT *" 
statement?

Jeff Oien wrote:

> Here is some code I have for an index page of people who post
> charts on the Web, kind of like Yahoo Photos or something.
> It displays the album title, number of images and date of last
> upload. The page takes about 5-6 seconds to load which is all
> in the queries I'm sure. Is there a way I can make this more efficient?
> http://www.webdesigns1.com/temp/code.txt
> Jeff
> 
> --
> 
> $table_name = "Chart_Users";
> $sql = "SELECT * FROM $table_name order by album_title";
> $result = @mysql_query($sql,$connection) or die(" Couldn't execute query.");
> //if(! $result = mysql_query($sql,$connection)) {
>   //  print("ERROR ".mysql_errno().": 
>".mysql_error()."\n$sql\n");
>   //  }
> 
>   while ($row = mysql_fetch_array($result)) {
>   $id = $row['id'];
>   $username = $row['username'];
>   $title1 = $row['album_title'];
>   $title = stripslashes($title1);
> 
>   $sql1 = "SELECT COUNT(*) FROM Chart_Files where id = '$id'";
>   $result1 = @mysql_query($sql1,$connection) or die(" Couldn't execute 
>query.");
>   //if(! $result = mysql_query($sql1,$connection)) {
>   //print("ERROR ".mysql_errno().": ".mysql_error()."\n$sql\n");
>   //}
>   $count = mysql_result($result1,0,"count(*)");
> 
>   $sql2 = "SELECT date_format(date, '%b. %D, %Y') as 
>date1 FROM Chart_Files where
> id = '$id' order by photoid desc limit 1";
>   $result2 = @mysql_query($sql2,$connection) or die(" 
>Couldn't execute query.");
>   $row = mysql_fetch_array($result2);
>   $date1 = $row['date1'];
> 
>   if ($count > 0) {
> 
>   $display_block .= "   href=\"display_album.php?id=$id\">$title  align=\"left\">$count$date1";
>   }
>   }
> 
> 
> 



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] & update

2002-03-24 Thread David Christensen

Use single quotes around the string!

Chris Payne wrote:

> Looking at the below, I think it might be spaces in the query - how can I
> rectify this?  Thanks :-)
> 
> Chris
> 
> Hi there,
> 
> I have a system for updating whereby you select the country/continent from a
> db then edit the record and update it and it works perfectly - that is until
> there is a & in the update $country set - so if it says Africa it updates
> fine, but if $country = Asia & The Orient it doesn't update, any ideas how I
> can fix this?
> 
> Thanks everyone.
> 
> Chris
> 
> 
> 
> 



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DB] Re: PHP4 & LDAP

2002-03-20 Thread David Christensen

Just in case anyone was wondering, here's a bit more info.  I'm not sure 
why some attributes show up the other way though:


\n";
ldap_close($linkID);

?>

Now (for some reason I haven't figured out yet) if you don't do the 
ldap_first_entry() step, you cannot access all of the attribute values 
returned from the $search!

You can test by commenting it out and changing the $values line to use 
the $search value as the second arg.

I hope that helps someone.  I could have used it for sure.



David Christensen wrote:

> Not sure if this is the right list for this, but I didn't see any others 
> on the PHP web site that made sense...
> 
> I'm using the following packages:
> 
> php-common-4.1.2-1mdk
> php-4.1.2-1mdk
> mod_php-4.1.2-1mdk
> php-ldap-4.1.2-1mdk
> openldap-clients-2.0.21-1.1mdk
> openldap-servers-2.0.21-1.1mdk
> openldap-2.0.21-1.1mdk
> libldap2-2.0.21-1.1mdk
> php-ldap-4.1.2-1mdk
> apache-modules-1.3.23-4mdk
> apache-common-1.3.23-4mdk
> apache-conf-1.3.23-3mdk
> apache-1.3.23-4mdk
> 
> 
> I'm trying to use my LDAP server for privilege access to certain 
> portions of the site.  I'm verifying the user's account information via 
> LDAP and that seems to work ok, because I can bind and do a modify on 
> the user's information.  I'm updating a particular field to hold the 
> sessionID and a time stamp.  The record updates just fine, because I can 
> do a "ldapsearch" from the command line on the server using the same 
> credentials I use in PHP and I can see the update.
> 
> I also have the server WIDE OPEN at the moment to test.  I didn't want 
> any stray ACL's to get in the way of debugging this.
> 
> The problem arises when I try to read back all of the attributes within 
> the PHP script.  I can see only certain attributes: uid, mail, cn (the 
> normal stuff) but if I try to read these fields that I want to use for 
> the session, they don't print in PHP, but the show up from the LDAP 
> command line util.  The fields include: employeeNumber, carLicense, 
> departmentNumber.
> 
> Like I said earlier, I can update them from PHP, just can't read them back.
> 
> Any ideas are greatly appreciated!
> 
> David Christensen
> 



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DB] PHP4 & LDAP

2002-03-20 Thread David Christensen

Not sure if this is the right list for this, but I didn't see any others 
on the PHP web site that made sense...

I'm using the following packages:

php-common-4.1.2-1mdk
php-4.1.2-1mdk
mod_php-4.1.2-1mdk
php-ldap-4.1.2-1mdk
openldap-clients-2.0.21-1.1mdk
openldap-servers-2.0.21-1.1mdk
openldap-2.0.21-1.1mdk
libldap2-2.0.21-1.1mdk
php-ldap-4.1.2-1mdk
apache-modules-1.3.23-4mdk
apache-common-1.3.23-4mdk
apache-conf-1.3.23-3mdk
apache-1.3.23-4mdk


I'm trying to use my LDAP server for privilege access to certain 
portions of the site.  I'm verifying the user's account information via 
LDAP and that seems to work ok, because I can bind and do a modify on 
the user's information.  I'm updating a particular field to hold the 
sessionID and a time stamp.  The record updates just fine, because I can 
do a "ldapsearch" from the command line on the server using the same 
credentials I use in PHP and I can see the update.

I also have the server WIDE OPEN at the moment to test.  I didn't want 
any stray ACL's to get in the way of debugging this.

The problem arises when I try to read back all of the attributes within 
the PHP script.  I can see only certain attributes: uid, mail, cn (the 
normal stuff) but if I try to read these fields that I want to use for 
the session, they don't print in PHP, but the show up from the LDAP 
command line util.  The fields include: employeeNumber, carLicense, 
departmentNumber.

Like I said earlier, I can update them from PHP, just can't read them back.

Any ideas are greatly appreciated!

David Christensen


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php