Koozali.org: home of the SME Server
Obsolete Releases => SME 7.x Contribs => Topic started by: fpcomputers 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
-
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.
-
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
-
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]