Koozali.org: home of the SME Server

PHP & MySQL

burnside

PHP & MySQL
« on: March 02, 2005, 04:32:46 PM »
I have recently set up a SME6.x server and have created a database in MySQL.  I now wish to be able to connect to the database.  Can anyone tell me what the standard connection details would be for connecting using mysql_connect() in PHP.  I have the following code:

define ('DB_HOST', 'localhost');
define ('DB_NAME', 'intranet');
define ('DB_USER', 'root');
define ('DB_PASS', 'password');
 
// Make the connnection and then select the database.
 
$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASS) OR die ('Could not connect to MySQL: ' . mysql_error() );

mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error() );


Cheers.

Quail_Linux

PHP & MySQL
« Reply #1 on: March 02, 2005, 06:07:30 PM »
Hi burnside,

Code: [Select]

<?php
//  Configuration

$dbhost "localhost";
$dbuser "user";  // MySQL Username
$dbpass "pass";  // MySQL Password
$dbname  "dbname"// Database Name

//

// Connect to MySQL Database
mysql_connect&#40;$d_host,$dbuser,$dbpass&#41;;
@mysql_select_db&#40;$dbname&#41; or die&#40;"Unable to select database"&#41;;

?>



HTH

burnside

PHP & MySQL
« Reply #2 on: March 02, 2005, 08:15:43 PM »
Thanks for the reply.

It appears that your code will do the same as mine.  I take it the default username and password for mysql is user and pass respectively?

Cheers.

Quail_Linux

PHP & MySQL
« Reply #3 on: March 02, 2005, 08:40:34 PM »
Quote from: "burnside"

It appears that your code will do the same as mine.  I take it the default username and password for mysql is user and pass respectively?
Cheers.


Hi burnside,

To start off with i don't use root to login to MySQL for MySQL databases that i have created. I create another user and password to access MySQL.

Unless you have changed the root password to MySQL, as i am understand the root password is a random and very long string.

here is a page that might interest you:
http://www.familybrown.org/howtos/mysql-password-howto.html

HTH

Offline Kobus

  • *****
  • 153
  • +0/-0
    • http://www.fullnet.co.uk
PHP & MySQL
« Reply #4 on: March 02, 2005, 10:00:02 PM »
the default password for mysql on sme is no password.

to test that all is ok i would also log in on the console or via putty, login to mysql with user and pass if  pass exist and use the db. that way you rule out any authentication issues.
Kobus............

Offline gelcube

  • ***
  • 55
  • +0/-0
    • http://www.ninetails.net
PHP & MySQL
« Reply #5 on: March 03, 2005, 12:14:30 AM »
Quote from: "kbensch"
the default password for mysql on sme is no password.


No, Quail_Linux is correct.  The default root mysql password on SME is a 76 character string unique to each installation.

Offline Kobus

  • *****
  • 153
  • +0/-0
    • http://www.fullnet.co.uk
PHP & MySQL
« Reply #6 on: March 03, 2005, 12:17:32 AM »
strange as when I started with mysql on sme i had to change the root password from nothing to what it is at the moment.

anyway

burnsaide how your problem?
Kobus............

burnside

PHP & MySQL
« Reply #7 on: March 03, 2005, 01:31:21 PM »
Quote from: "Quail_Linux"


here is a page that might interest you:
http://www.familybrown.org/howtos/mysql-password-howto.html

HTH


Cheers this solved the problem

Quail_Linux

PHP & MySQL
« Reply #8 on: March 03, 2005, 04:32:04 PM »
Quote from: "burnside"
Quote from: "Quail_Linux"


here is a page that might interest you:
http://www.familybrown.org/howtos/mysql-password-howto.html

HTH


Cheers this solved the problem


Hi burnside,

No problem, glad I could be some help to solve your problem.

Offline Kobus

  • *****
  • 153
  • +0/-0
    • http://www.fullnet.co.uk
PHP & MySQL
« Reply #9 on: March 03, 2005, 09:13:05 PM »
thanks for that. coupkle of things makes more sense now.
Kobus............