Koozali.org: home of the SME Server

MySQL --> connecting to database

Offline fpcomputers

  • 8
  • +0/-0
    • http://www.fpcomputers.biz
MySQL --> connecting to database
« on: April 29, 2006, 12:15:49 AM »
Hey guys.

I recently began with php/mysql programming together with a book. But when I got to chapter 4 it wants me to make a database connection so I thought oh cool :) but after trying hours and hours I don't get my code to work. Although the php works just fine

I used the following code:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>multipurpose page outline</title>
</head>

<body>

<?php

$dbcnx = @mysql_connect("192.168.1.4", "root", "rodney28");
if (!$dbcnx) {
   exit('unable to get to the database');
}


if (!@mysql_select_db('ijdb')) {
   exit('<p> unable to locate the joke database at this time</p>');
}

?>

</body>
</html>



and the only thing i get is the "unable to get to the database" I also tried to remove the @ which resulted the same

and used the following code:

<?php
mysql_connect("192.168.1.4", "root", "rodney28") {
or die(mysql_error());
}
?>


and this one resulted in a blank page not displaying anything :s

If anyone could help me with this, I would be really grateful

oh if it might help, I use apache 2.0 mysql 4.1 and php 4.3 on a linux server and i write my php scripts on windows which i upload to my linux server
...

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Re: MySQL --> connecting to database
« Reply #1 on: April 29, 2006, 08:33:59 AM »
Quote from: "fpcomputers"
oh if it might help, I use apache 2.0 mysql 4.1 and php 4.3 on a linux server and i write my php scripts on windows which i upload to my linux server
This forum is for the SMEserver only, problems with PHP scripts and databases are not part of the scope of this forum.

However part of your problem, if you are running a SMEServer, is that the mysql server in that installation is configured to run as a socket and therefore is not (as easily) accesible from other hosts.

For help with PHP, MySQL and database connection just use Google, there are a lot of sites about those subjects, and a lot of sites have a teaching courses or hwoto's on how to connect to (mysql) databases.

Furthermore use newsgroups like: comp.lang.php, alt.comp.lang.php or mailing.database.mysql, a lot of experts are available there to help you.
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)

Offline JonB

  • *
  • 351
  • +0/-0
MySQL --> connecting to database
« Reply #2 on: April 29, 2006, 11:08:33 AM »
Cactus is being a bit harsh here.

He is correct in that mysqld is by default set to listen to a unix socket however mysqld can be configured to listen to a local connection.

From the server console

config setprop mysqld LocalNetworkingOnly no
signal-event post-upgrade
signal-event reboot

You should now be able to connect to the server mysql from the local network on TCP port 3306.

Jon
...

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
MySQL --> connecting to database
« Reply #3 on: April 29, 2006, 11:59:37 AM »
Quote from: "JonB"
Cactus is being a bit harsh here.
Sorry.. you are right on that part... I made the assumption that OP was not using a smeserver and was just trying to get help on php to connect to a mysql database.

A few advices though to fpcomputers and all others: [list=1]
  • NEVER post your root password in your posts... (@fpcomputers: you should be able to edit your post by clickin the edit link in your first post, please remove or obfuscate your root password there)
  • NEVER use the root account for scripts. Create a seperate account as the root account has to many privileges on your mysql server Once the password is known to people with bad intentions it is very easy to do serious harm. See the mysql manual on how ro create users and giving them the proper privileges: http://dev.mysql.com/doc/refman/5.1/en/account-management-sql.html[/list:o]
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)