[PHP-DB] MySQL Connection Class
I know this may seem a little vague but I would like to know where a good tutorial on creating database connection class files would be. I have been looking and as of yet I have not found one that deals specifically with this question. Thanks in advance. Jas -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] MySQL Connection Class
A number of connection classes and abstraction toolkits already exist. Your PHP 4.x install probably came with PEAR's DB.php abstraction layer. Save yourself the trouble perhaps? jas said: So all I would need to do is create a file named db_connection.php3 and put in the functions $db = mysql_connection(localhost,username,password) or die(could not connect); and then put an include statement on the top of each page that needs the db connectiong? Please correct me if I am wrong, I have never really used class files for my own scripts before. Thanks again. Gurhan Ozen [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Are you trying to write classes to connect to the database using PHP's native DB connection functions?? If yes, you should only check those database functions' tutorials and just use them inside your class.. Gurhan -Original Message- From: jas [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 30, 2002 12:09 AM To: [EMAIL PROTECTED] Subject: [PHP-DB] MySQL Connection Class I know this may seem a little vague but I would like to know where a good tutorial on creating database connection class files would be. I have been looking and as of yet I have not found one that deals specifically with this question. Thanks in advance. Jas -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] MySQL Connection Class
Ok just to clear it up... our server is not running php4 unfortunately. =) Dave Richardson [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... A number of connection classes and abstraction toolkits already exist. Your PHP 4.x install probably came with PEAR's DB.php abstraction layer. Save yourself the trouble perhaps? jas said: So all I would need to do is create a file named db_connection.php3 and put in the functions $db = mysql_connection(localhost,username,password) or die(could not connect); and then put an include statement on the top of each page that needs the db connectiong? Please correct me if I am wrong, I have never really used class files for my own scripts before. Thanks again. Gurhan Ozen [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Are you trying to write classes to connect to the database using PHP's native DB connection functions?? If yes, you should only check those database functions' tutorials and just use them inside your class.. Gurhan -Original Message- From: jas [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 30, 2002 12:09 AM To: [EMAIL PROTECTED] Subject: [PHP-DB] MySQL Connection Class I know this may seem a little vague but I would like to know where a good tutorial on creating database connection class files would be. I have been looking and as of yet I have not found one that deals specifically with this question. Thanks in advance. Jas -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] MySQL Connection Class
Jas, I can't know whether or not that's right for you. It all depends on what you need to do.. If you only have one database connection with one userid/pass combination, then yes it might be the solution you are looking for. But if you want to be able to reuse your code for different types of databases, userids, then you can write a class with different functions and variables to do so. For example you can something like class myDBConnClass { var $user; var $pass; var $host; var $database; function setUser($username) { $this - user = $username; } function setPass($password) { $this - pass = $password; } function setHost($hostname) { $this - host = $hostname) } function setDatabasename($databasename) { $this - database= $databasename; } function mySQLconn($username, $password, $hostname, $databasename) { mysql_pconnect($username, $password, $hostname); mysql_select_db($databasename); } function mySQL() { mysql_pconnect(($this - host)., .($this - user)., .($this - pass). ); mysql_select_db($this - database); } . . . . } // end of class myDBConnClass Say you have saved this into myDBConnClass.php .. Then in your php pages you would first require this file with require(myDBConnClass.php); statement, and then you would create another class extending this or just an instance of this class (depending upon what you actually have in your class and pages. Keep in mind that this is a very primitive and kind of useless class.. You can always have more properties of the class and more functions.. If you prefer you can hardcode the login, databasename info to the class and call the connection fucntions without arguments, or you can set the variables of the class and use it so, you can also have more functions to connect to the different databases (PostGreSQL, Oracle, etc.) . Does this help??? Gurhan -Original Message- From: jas [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 30, 2002 12:33 AM To: [EMAIL PROTECTED] Subject: Re: [PHP-DB] MySQL Connection Class So all I would need to do is create a file named db_connection.php3 and put in the functions $db = mysql_connection(localhost,username,password) or die(could not connect); and then put an include statement on the top of each page that needs the db connectiong? Please correct me if I am wrong, I have never really used class files for my own scripts before. Thanks again. Gurhan Ozen [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Are you trying to write classes to connect to the database using PHP's native DB connection functions?? If yes, you should only check those database functions' tutorials and just use them inside your class.. Gurhan -Original Message- From: jas [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 30, 2002 12:09 AM To: [EMAIL PROTECTED] Subject: [PHP-DB] MySQL Connection Class I know this may seem a little vague but I would like to know where a good tutorial on creating database connection class files would be. I have been looking and as of yet I have not found one that deals specifically with this question. Thanks in advance. Jas -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] MySQL Connection Class
Yes it does, thanks... now that I have a better understanding of classes now I just need to write one. Thanks again. jas Gurhan Ozen [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Jas, I can't know whether or not that's right for you. It all depends on what you need to do.. If you only have one database connection with one userid/pass combination, then yes it might be the solution you are looking for. But if you want to be able to reuse your code for different types of databases, userids, then you can write a class with different functions and variables to do so. For example you can something like class myDBConnClass { var $user; var $pass; var $host; var $database; function setUser($username) { $this - user = $username; } function setPass($password) { $this - pass = $password; } function setHost($hostname) { $this - host = $hostname) } function setDatabasename($databasename) { $this - database= $databasename; } function mySQLconn($username, $password, $hostname, $databasename) { mysql_pconnect($username, $password, $hostname); mysql_select_db($databasename); } function mySQL() { mysql_pconnect(($this - host)., .($this - user)., .($this - pass). ); mysql_select_db($this - database); } . . . . } // end of class myDBConnClass Say you have saved this into myDBConnClass.php .. Then in your php pages you would first require this file with require(myDBConnClass.php); statement, and then you would create another class extending this or just an instance of this class (depending upon what you actually have in your class and pages. Keep in mind that this is a very primitive and kind of useless class.. You can always have more properties of the class and more functions.. If you prefer you can hardcode the login, databasename info to the class and call the connection fucntions without arguments, or you can set the variables of the class and use it so, you can also have more functions to connect to the different databases (PostGreSQL, Oracle, etc.) . Does this help??? Gurhan -Original Message- From: jas [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 30, 2002 12:33 AM To: [EMAIL PROTECTED] Subject: Re: [PHP-DB] MySQL Connection Class So all I would need to do is create a file named db_connection.php3 and put in the functions $db = mysql_connection(localhost,username,password) or die(could not connect); and then put an include statement on the top of each page that needs the db connectiong? Please correct me if I am wrong, I have never really used class files for my own scripts before. Thanks again. Gurhan Ozen [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Are you trying to write classes to connect to the database using PHP's native DB connection functions?? If yes, you should only check those database functions' tutorials and just use them inside your class.. Gurhan -Original Message- From: jas [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 30, 2002 12:09 AM To: [EMAIL PROTECTED] Subject: [PHP-DB] MySQL Connection Class I know this may seem a little vague but I would like to know where a good tutorial on creating database connection class files would be. I have been looking and as of yet I have not found one that deals specifically with this question. Thanks in advance. Jas -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]