Php > Databases
I got tired of typing the connection code for MySQL on every PHP
I got tired of typing the connection code for MySQL on every PHP page, so we built this simple little function. // CONSTANTS define("DBSERVER", "www"); define("DBUSER", "LimitedUser"); define("DBPASS", "N0tAPa55w02d"); $SQL = ""; $LastError = ""; function DatabaseConnect() { global $LastError; $LastError = ""; //----------------------------- // Connect to the mysql server. //----------------------------- $dbHandle = @mysql_connect(DBSERVER, DBUSER, DBPASS); if ($dbHandle == false) { $LastError = "Unable to connect to the database server: " . mysql_error(); return false; } mysql_select_db("test"); return true; } ?>
Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage