The following script is useful for people that want to have a little bit of db functionality. It will be expanded in the near future with a few more functions. Hope you find them useful.
| Code: |
|
<?php // Version Info: DB Info File v 0.0.1A // Original filename: main_db.php // Author: BlueVD (bluevd@gmail.com) // Functions List: // |_> db_conn_exists([bool auto_connect]) -> returns true if a mysql connection exists // | if the connection doesn't exists, but the // | auto_connect param is set to true, it will // | automatically create a connection and it will // | return the link id; otherwise it will return false; // | Note: the auto_connect param is *optional* // |_> db_connect([bool force_new]) -> If no param is specified, it will try to connect to // | the mysql database; If a connection already exists, it will // | return true; Otherwise, it will connect and return the link // | id. If the force_new param is set to true, it will create // | a new connection even if one already exists and it will // | return it's link id. On failure, it will return false; // | Note: the force_new param is *optional* // // Details: Database definitions and functions; // Comments: none define("MYSQLH","localhost"); //MySQL Host define("MYSQLU","user"); //MySQL Username define("MYSQLP","pass"); //MySQL Password define("MYSQLD","database"); //MySQL Database //define("USER_TABLE","users"); //require_once("../security/secure.php"); ignore this line or erase it. //it's part of my security engine, soon to be published. function db_conn_exists(){ @$tmpres=mysql_query("status"); if(!$tmpres){ if(func_num_args()==0){ return false; }else{ $auto_conn=func_get_arg(0); if($auto_conn){ $db=mysql_connect(MYSQLH,MYSQLU,MYSQLP); if(!$db){ return false; }else{ $sdb=mysql_select_db(MYSQLD); if(!$sdb){ mysql_close($db); return false; }else{ return $db; } } } } }else{ return true; } } function db_connect(){ if(func_num_args()==0){ $db=db_conn_exists(true); return $db; }else{ $force_conn=func_get_arg(0); if($force_conn){ $db=mysql_connect(MYSQLH,MYSQLU,MYSQLP); if(!$db){ return false; }else{ $sdb=mysql_select_db(MYSQLD); if(!$sdb){ mysql_close($sdb); return false; }else{ return $db; } } } } } ?> |
