Just a matter of preference, but instead of db.php, why not create a class
with connection parameters?
public class DB{
const DBSERVER = 'localhost';
const USER = 'xxxxx'
etc, and a few methods, a few listed below
}
Then you can do things like
$db = new DB();
$db->update('table',array('column'=>'value') (returns rows affected)
$db->insert('table',array('column'=>'value') (returns inserted row id)
$db->getRows($query) (returns all rows returned from a query)
It's cleaner, and you don't have to worry about doing
mysql_select_db/mysql_fetch_assoc, and all those other ugly function names
Furthermore your update and insert methods can automatically escape
parameters, columns, and table names so you don't have to worry about SQL
injection.
You can abstract out the configuration data, too, so that you can work with
two databases concurrently and not worry about database resources getting
mixed up.
-Trevor
2009/12/9 Roderick D. Thomas <tho...@ms...>
> Wondering how I should adjust the format below to connect to my work
> ODBC5100 database through PHP5. Ideally, I would like to extract data to
> create tables in MySQL. I believe it will allow for more efficiency.
>
> ?
> $dbserver = "localhost";
> $dbuser = "xxxxxx";
> $dbpass = "xxxxxx";
> $dbdb = "xxxxxx";
> mysql_connect($dbserver, $dbuser, $dbpass);
> mysql_select_db($dbdb);
> ?>
>
> ------------------------------------------------------------------------------
> Return on Information:
> Google Enterprise Search pays you back
> Get the facts.
> http://p.sf.net/sfu/google-dev2dev
> _______________________________________________
> chiPHPug-discuss mailing list
> chi...@li...
> https://lists.sourceforge.net/lists/listinfo/chiphpug-discuss
>
|