Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

strange DB problem

Status
Not open for further replies.

josoers

Programmer
May 13, 2003
17
0
0
NL
Im having a strange problem here. When im reading from my db in my perl script, everything goes fine. However when I write to the db, the perl script goes from 1% CPU load to 60% CPU load, and stays there. This happens every now and then so not every time when writing to the db. What could cause this?

Code:
my $dbh = DBI->connect("DBI:mysql:xxxxx:localhost","root","xxxxx");
my $sth = $dbh->prepare("INSERT INTO contacts VALUES ('','$email','$username')");
$sth->execute();
$dbh->disconnect();
 
I can't really explain your CPU usage but that code isn't going to do what you need. Because you're using single quotes, $email and $username won't be interpolated (i.e. replaced with their values). Since you're using a prepared statement anyway, you should learn about using placeholders:
Code:
my $dbh = DBI->connect("DBI:mysql:xxxxx:localhost","root","xxxxx");
my $sth = $dbh->prepare("INSERT INTO contacts VALUES ('',?, ?)");
$sth->execute( $email, $username);
$dbh->disconnect();
 
ok thanks for that note, anyone knows about the cpu load problem?
 
Run it, then look at the running processes to see who is consuming the resources (task manager on Windows, ps or top on unix).

Also, probably not such a good idea to connect to the DB as root, unless "root" in this case means "a userid that isn't actually root"...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top