jazzman247 Posted November 5, 2009 Share Posted November 5, 2009 Just now making the leap to OOP PHP and trying to connect to a MySQL DB inside the class and set object properties. but the connection fails. I think it must be some variable scope issue or maybe I can't connect inside a class? my code looks something like this... class Application { static $dbServer = "localhost"; static $dbUser = "user"; static $dbPassword = "pass"; static $dbName = 'dbname'; } class User extends Application { public $userId; public $userType; public $db_connection; function __construct($userId) { // fails here $db_connection = mysql_connect($dbServer,$dbUser,$dbPassword) OR die("Could not establish database connection"); // SELECT the database mysql_select_db($dbName,$db_connection) or die("Could not get database"); } My error: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/content/ammaxpub/html/clsUsers.php on line 15 Link to comment https://forums.phpfreaks.com/topic/180440-mysql-connection-error-in-class-def/ Share on other sites More sharing options...
jazzman247 Posted November 5, 2009 Author Share Posted November 5, 2009 May be someone could just give a good example of how to set object property values from a DB for an OOP nubie? Link to comment https://forums.phpfreaks.com/topic/180440-mysql-connection-error-in-class-def/#findComment-951940 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.