Jump to content

yonta

Members
  • Posts

    70
  • Joined

  • Last visited

    Never

Contact Methods

  • Website URL
    http://sofiacardita.com/codearray/

Profile Information

  • Gender
    Not Telling

yonta's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for your help Jenk I undestand it better now :)
  2. So are you saying that instead of extending the dbmanager in all my models, to avoid the repetition i could in a controller do $db = new DbManager(); $products = new ProductsModel($db); - basically just pass the dbmanager around, and since i only use one controller in a single call to the server there would be uneeded multiple instantiation. It does seem cleaner :) thank you, thank you So pconnect checks if there's already a connection available. I use persistent connections because i read that it's faster but that you also increase the risk of having too many connections open. How is that if pconnect checks if there's already a connection available? 'if it's a database management application, you may very well want multiple connections available' - it is, but i really don't get why i would want multiple connections to the database. If multiple users are asking to see the same or different pages, shouldn't the server use the same connection to mysql? Could you explain this a bit more please? thanks :)
  3. Ok, maybe my post was a bit confusing. If you follow the mvc pattern in your apps, do you have a common database manager for all your models (in my case, it's a wrapper for adodb - http://adodb.sourceforge.net/ ) or not? If not, why not? If you do have a common db manager, how do you avoid multiple attemps to connect to the database when you use more than one model in a controller? Do you simply detect if there's a connection already established or not? I'm thinking i could use something like this: [code] $this->DB = &ADONewConnection('mysql');   if(!$this->DB->IsConnected( ))   {   $this->DB->PConnect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE) or   trigger_error("Não é possível ligar à base de dados. Contacte o administrador.", E_USER_ERROR);   } [/code] Do you do something like this as well?.. I'm still a bit new to the oop scene so if anyone could tell me how they do it, it would help. Thanks
  4. Right now i'm following the mvc pattern in an app i'm building, so i basically have templates, controllers and models. There's one model per mysql table, so if i have a products table i'll have a products_model with all the basic CRUD functionality. A controller can use one or several models. For example, each product can have several documents and so there's a product_docs table and its corresponding model. This means that the product_controller can use the products_model and the product_docs_model. All models extend (inherit from) a common database manager class and it's this common class that's responsible for actually connecting to the database (it has a connect method). Now for my problem: if in a single call to the server more than one model is used, there will be more than one instance of the database manager class created, and so more than one attempt to connect to the database (it's a persistent connection, btw) and there seems to be no need for it. In a single call to the server i only need to connect once to the database. I mean, performance wise it just seems stupid. And so i thought i could use the singleton pattern to ensure that only one attempt to connect to the database was done. something like this: [code] class products_Model extends DbManager { var $select_titles; var $tablename; var $security; function products_Model() { $this->tablename = 'products'; $this->select_titles = 'SELECT prod_id, prod_title, prod_text, prod_ispub FROM '.$this->tablename; if(!singleton::getInstance('DbManager')) //if there's no dbmanager in singleton array, attempt to connect parent::connect();                 //without the singleton pattern it was just like below                 //parent::connect(); $this->security = new Security(); } [/code] But searching around i found this: "The singleton pattern applies to the situation where you need a single, global instance of a class. It fits situations where a factory object returns uniform objects, such as file handles or user sessions. These aren't good candidates for being implemented in a PHP script because the [b]language provides built-in solutions such as persistent database connections[/b]." ( http://www.zend.com/zend/trick/tricks-app-patt-php.php ) which of course got me thinking. Am i thinking about this the totally wrong way? Maybe i should do it another way? Or is it actually ok? Or there's no need to worry about making several calls to pconnect since it's a persistent connection anyway? Or should i use delegation ($db = new DbManager(); ) instead of inheritance (.. extends DbManager ) ? Any input would be a great great help.
  5. It should be okay. Here's a snippet - just check your code against this or if the error persists post your code here [code] //javascript in head section var valid; function validate_form ( ) {       if ( document.form.artistnametxt.value == "If not, write it here" || document.form.artistnametxt.value == "")     {         alert ( "You must select an artist name!!\n\nEither do so from the drop down list or input it manually" );         valid = false;     } else { alert ( "Good boy");//just for testing valid = true; } } //html in body section, notice i have 2 css styles named blue and red <form id="form" name="form" method="post" action=""> Artist &nbsp;<input type="text" name="artistnametxt" id="artistnametxt" value="If not, write it here"/><br/><br/>     <input type="button" name="Submit" class="red" value="Validate" onClick="validate_form();"/><br/> <input type="button" name="Submit" class="red" value="Check" onClick="if(valid==true){this.className='green'} else {this.className='red' };"/> </form> [/code]
  6. Well, if you put it outside of any function, you effectively make it global, and so it is available inside your functions. So when you do valid=true inside a function you are effectively changing the global variable valid from false to true.
  7. Glancing over your queries i noticed the BETWEEN keyword. Normally it's BETWEEN value1 AND value2. You don't specify the 2nd value. Also while debugging it's useful to remove the silencing operator @ from the mysql_query call to get the error message. If it still doens't work post the error message here.
  8. It has to do with variable scope. You defined the valid variable inside the function so it is only available inside that same function. To make it work you need to make the valid variable global. Just do this in the beginning of your script: var valid= false; Check this article http://www.webdevelopersnotes.com/tutorials/javascript/global_local_variables_scope_javascript.php3
  9. You could use something like this to rename a file: [code] function rename_filename($whichfile) { $random_number = rand(100000, 999999); $hour = date ("Hms");//234012                 $info = pathinfo($whichfile); return "usrfile_" . $random_number . "_" . $hour . '.' . $info['extension']; } [/code]
  10. So basically [code] <INPUT TYPE = Button VALUE = "Click Me" OnClick = "document.getElementById('myDivID').innerHTML='Hello World'"> <div id = "myDivID">It will appear here.</div> [/code]
  11. The error is telling you that there should have a php object named my dir ($mydir) and it should have a method read() ($mydir->read() ) but you don't. Somewhere in your script you should have $mydir = new MyClass(); where myclass is the name of the class that handles reading directories. If you can't find it, you'll need a function to read a directory (i can help you there). Either that or ask your friend who first helped you. Best
  12. I was under the impression that not all browsers set HTTP_REFERER, so you can't really rely on it (http://www.php.net/manual/en/reserved.variables.php). Any thoughts?
  13. Think you have an extra ( there try this: if (strlen($file) > 2) instead of if ((strLen($file) > 2)
  14. Not sure but i think you could use the $_SERVER['SCRIPT_FILENAME'] to return the full path to the current script, so if someone asked for news.php and if the login was false, you could use something like header("Location:login.php?url=".$_SERVER['SCRIPT_FILENAME']); and in login.php redirect to the specified $_GET['url'] Hope this helps
  15. How about putting a div below the submit button, and google about javascript's getElementById and innerHTML? Yes, this is really easy. Too easy to give you the full answer. Just google.
×
×
  • 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.