Jump to content

need help please


dreamsofshadow

Recommended Posts

I designed my own database abstraction class that handles all my db needs. Well at first within each function in the class i was opening and closing a connections within each function, but when i plugged the class into my other script, i would get what i believe was an error telling me i had opened to many connetions. (at that point i was entering 10228 entries at a time). I would get that error after about a third of the information ahd been put into the database. So after thinking about it, i changed the way the database opened its connection having it instialized with the class and then utilized in functions within the class by using $this->. Now it runs hella slow and i get about an 1/8th of the data in before i get an error saying the script ran over the 60 second marker. So now im thinking about opening an array of 60 connections when i initialize the script and then having the functions access them at random. Will that work? Any ideas. I;m also doing this on an older laptop, pentium m @ 1.7ghz, 2gigs of ram(upgraded), etc. HELP PLEASE 

Link to comment
Share on other sites

I think I somewhat know what your going through, but could you post your class so I can see what's going on?

 

There's got to be a way to optimize what your doing. 1 connection should suffice most needs

Link to comment
Share on other sites

<?php

class DBA

{

 

    var $sqlresource;

    var $sqlusername;

    var $sqlpassword;

    var $con;

 

 

public function DBA($sqlres, $sqlun, $sqlpass)

  {

    $this->sqlresource = $sqlres;

    $this->sqlusername = $sqlun;

    $this->sqlpassword = $sqlpass;

    $this->con = array();

    for($i = 0; $i < 10; $i++)

    {

    $this->con[$i] = mysql_connect($sqlres, $sqlun, $sqlpass);

    if (!$this->con)

    {

    die('Could not connect: ' . mysql_error());

    }

    }

  }

 

                  ....................

 

    mysql_select_db($database, $this->con[(rand(0, 9))]);

 

thats where i am now, making it use random connections did not help at all. I know nothing about this sort of stuff, ive taught myself everything i know about coding through brute forc. It sucks cause i really want to finish what im working on, but down the raod this could amount to a real problem. anybody have any ideas?

 

 

The thing is im entering 10,000+ (now that i think about it its actually around 20,000) some entries at a time(update table), getting data to perform tests on how to enter it, i mean the raw calculations have got to tear my lil' laptop apart. I just wish it would complete it and not give up cause its taking to long... its ok if its slow it just needs to work...

 

this is a list of some the functions im using...

 

public function DBA($sqlres, $sqlun, $sqlpass)

public function deletedatabase($database)

public function deletetable($database, $table)

public function createdatabase($i)

public function createtable($databasename, $ii, $a, $b)

public function tableinsert($databasename, $ii, $a, $c)

public function displaytable($dbname, $ii)

public function displayedittable($dbname, $ii)

public function gettabledata($database, $table, $row, $field)

public function deletetablerow($database, $table, $row)

public function listdatabases()

public function listtables($dbname)

public function displaytablelength($database, $table)

public function gettablelength($database, $table)

public function getdatabases()

public function gettables($dbname)

public function getfieldnames($database, $table)

public function insertempty($database, $table)

public function updatetable($database, $table, $row, $col, $newdata)

public function addfield($database, $table, $newfield, $newfieldtype)

public function deletecol($database, $table, $col)

public function getcol($database, $table, $col)

 

 

Link to comment
Share on other sites

basically i have a window class that creates html elments based on sql datatables, and i have another class that interprits input and creates entries in the database in a complimentary kind of architecure. Basically doing this means that creating 400 divs means 20,000 entries and a ton of calculations, as well as a huge amount of sql resources just to figure out what goes where and how.

Link to comment
Share on other sites

because it timed out, and i thought opening more and usign them randomly would let me execute more data at a fast rate. I came to that conclusion because so far the way that has worked the fastest and got the most data into the db before crashing was opening a connection inside each function. I realize now that the random conection idea isnt going to work so any ideas?

Link to comment
Share on other sites

because it timed out

 

And you mentioned that where?

 

Your script is timing out I should imagine, not your connection.

 

Have you checked your error logs?

Do you really need to run this many query through a web interface?

Link to comment
Share on other sites

for sure, 1 connection is fine. Only reason you'd need multiple connections is for multiple databases.

 

If what your trying to accomplish is going to be more than php can handle in one shot, you might think about splitting it over multiple requests.

 

Set some sort of upper bounds on your script that your going to reach safely before a timeout. Save some sort of data to make sure your next request knows where to start and it will continue from there, and so on. Kind of like pagination...only very different I suppose =)

 

Never run into a situation like this myself so please share how it goes if you come up with anything...english is nice, but php is better ;)

Link to comment
Share on other sites

yea i do imagine that it is timing out... which is bad.

I dont know how to check the error logs... mysql_error() you mean?

and how do i set it to just wait till its finished,  im ok with it taking ten minutes!

 

Fatal error: Maximum execution time of 60 seconds exceeded in C:\Program Files\xampp\htdocs\new\dba.php on line 284

Link to comment
Share on other sites

php won't let you run till your done for a reason. it's dangerous. endless loops, math gone bad, bad recursion, etc...

 

you can increase max_execution_time in your php.ini

 

there may be other directives that affect the runtime limit, I'm not sure off the top of my head

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.