Updating mysql

// it knows to convert NULL and NOW() from a string// insert() parameters// table name (ideally defined as a constant, but did not for this example)// assoc array with data (does not need escaped)// insert() returns// primary id of the inserted record.

you can collect or ignoreaffected_rows// returns the number of rows in a table affected by your query// can be used after UPDATE query (to see how many rows are updated)// can be used after SELECT query (to see how many rows will be returned)Since it's a singleton, when you "create" your second $db_2 it's just reusing the first object, not opening/creating a new connection.

Not necessarily because this class is inefficient, but because handling multiple master/slave connections and queries requires something different.

The only efficiency caution I have (this applies to everyone) is: fetch_array() retrieves and returns the entire result set so you can store it in an array/memory.

I do have a question though: I have a table (called tbl_globals) where I store several site-wide variables (which are echoed throughout the site and on more than one occasion).

However, if you use multiple database machines (or plan on upgrading to multiple db machines in the future) then you should use a database script written to handle multiple servers.

This particular table only has one row (and no additional rows are ever added) In the past I have queried the table in the database and assigned a variable to each resulting value, which is fine.

I have a script that has the query and then a variable for each returned value.

Is there a way to put the $db at the top of the class so I can use it through the entire class or is that bad practice? BTW, the error I'm getting is: PHP Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in /Users/dengine/Documents/my Webserver/910_develop/classes/kp_classes/images.on line 6 Many thanks in advance!

Jerome You generally put $db=Database::obtain(); inside each function that interacts with the database. If you really want to use it just once in the class, you can declare it in an object contructor (which gets called when you create the Images object) then use $this-Great class!

Leave a Reply