#1  
Old 31st December 2006, 12:34
mphayesuk mphayesuk is offline
Senior Member
 
Join Date: Sep 2005
Location: UK, East Midlands
Posts: 517
Thanks: 1
Thanked 3 Times in 3 Posts
Send a message via MSN to mphayesuk
Default Using MySql

Hi, I have tried looking on google ect... but I cant find a definate answer.

This is what I have:

web4_u2 - username
web4_db2 - database
MainTable - table name

I use this to try and connect from test.php

$hostname = "www.touch-one.co.uk";
$mysql_login = "web4_u2";
$mysql_password = "mypassword";
$database="web4_db2";
$number = "04381003";

print "<p>Data for " .$number;

if (!($dbcon = mysql_pconnect($hostname, $mysql_login , $mysql_password))){
die("Can't connect to database server.");
}else{
// select a database
if (!(mysql_select_db("$database",$dbcon))){
die("Can't connect to database.");
}
// more code commented out
}


All I get is "Cant connect to database server". the server is running because I can access through the portal and also through putty.

Thanks
Reply With Quote
Sponsored Links
  #2  
Old 31st December 2006, 15:46
Craig Craig is offline
Member
 
Join Date: Dec 2006
Posts: 56
Thanks: 1
Thanked 3 Times in 1 Post
Default

I could be wrong but I think you would not use the host/domain for the connection to the MySQL server but instead, since your scripts are on the same box as the MySQL server, that you would instead use either localhost or 127.0.0.1.

Usually 127.0.0.1 is a safe bet to work.

But, if you have phpMyAdmin installed and it does actually work, you could do what I do and that is cheat, take a look at phpMyAdmin's configuration file which should be, if installed as a package through ISPConfig, in
Code:
/home/admispconfig/ispconfig/web/phpmyadmin/config.inc.php
Take a look in there and see what it has listed for the "$hostname" because I think it might work better with either :
Code:
$hostname = "127.0.0.1";
or :
Code:
$hostname = "localhost";
That's just a guess though.
Reply With Quote
  #3  
Old 1st January 2007, 17:04
mphayesuk mphayesuk is offline
Senior Member
 
Join Date: Sep 2005
Location: UK, East Midlands
Posts: 517
Thanks: 1
Thanked 3 Times in 3 Posts
Send a message via MSN to mphayesuk
Default

Excellent thanks that works, but if you could take a look at the enitre code I am using and let me know if there is something obviously wrong, I am very new to mysql so I am still learning.


<html>
<head>
<title>Result of Database Query</title>
</head>
<body>
<h1>Result of Database Query</h1>
<?

$hostname = "localhost";
$mysql_login = "web4_u2";
$mysql_password = "******";
$database="web4_db2";
$number = "04381003";

print "<p>Data for " .$number;

if (!($dbcon = mysql_pconnect($hostname, $mysql_login , $mysql_password))){
die("Can't connect to database server.");
}else{
// select a database
if (!(mysql_select_db("$database",$dbcon))){
die("Can't connect to database.");
}



$sql="SELECT * FROM MainTable WHERE CompanyNumber = "04381003" ";
$result = mysql_query($sql);
$nrows = mysql_num_rows($result);
if($nrows != 0)
{
//print "<p>Data for " . $number;
print "<table border=2><tr><th>Latitude<th>Longitude<th>Easting< th>Northing\n";
for($j=0;$j<$nrows;$j++)
{
$row = mysql_fetch_array($result);
print "<tr><td>" . $row["Type"];
print "<td>" . $row["IncorpDate"];
print "\n";
}
print "</table>\n";
}
else print "<p>No Entry for " . $number;
mysql_close($dbcon);
}
?>
</p>
</body>
</html>

If I just leave in the connection statements, I dont get any errors so I am assuming there are ok, and the select statement works on the command line and returns data so I am pretty sure that works.

Thanks
Reply With Quote
  #4  
Old 1st January 2007, 17:21
mphayesuk mphayesuk is offline
Senior Member
 
Join Date: Sep 2005
Location: UK, East Midlands
Posts: 517
Thanks: 1
Thanked 3 Times in 3 Posts
Send a message via MSN to mphayesuk
 
Default

Sorry I think I have it working now.... thanks for your help....
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Messed up ISPConfig-2.2.8 Upgrade Morons Installation/Configuration 4 29th November 2006 12:17
MySQL Cluster On FC5 : error while unpacking from engine asyadiqin HOWTO-Related Questions 7 28th October 2006 17:37
Can't Remote Access mysql 4.1 dedibox Installation/Configuration 2 24th August 2006 10:32
Mandriva 10.2 Perfect Setup Install Problems... ctroyp Installation/Configuration 12 30th December 2005 16:04
MySQL issue during install of ISPConfig ricbax Installation/Configuration 4 16th September 2005 09:41


All times are GMT +2. The time now is 07:59.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.