Can connect to MYSQL at home but not after uploading...

Codes here !

Moderators: macek, egami, gesf

DrQuincy
New php-forum User
New php-forum User
Posts: 7
Joined: Sat Mar 08, 2003 4:38 am

Can connect to MYSQL at home but not after uploading...

Postby DrQuincy » Sat Mar 08, 2003 4:52 am

Hi all,

I'm new to PHP/MYSQL; I recently got a PHP to MYSQL connection working on my local machine using Apache web server. I used ALL the default parameters for the mysql_connect() function, i.e. localhost and no user name and password. This worked fine.

The code is:

Code: Select all

<html>
<head>
<title>Obtaining field data from a database</title>
</head>
<body>
<?php
$link = mysql_connect();
$db = "test";
if( ! $link )
{
   die( "Couldn't connect to MySQL! Doh!!!" );
}
mysql_select_db( $db, $link );
$result = mysql_query( "select * from people" );
$num_rows = mysql_num_rows( $result );
print "There are currently $num_rows rows in the table<p>";
print  "<table border=1>\n";
while ( $a_row = mysql_fetch_row( $result ) )
{
   print "<tr>\n";
   foreach ( $a_row as $field )
      print "\t<td>$field</td>\n";
   print "</tr>\n";
}
print "<table>\n";
mysql_close( $link );
?>
</body>
</html>


I got some web space that supports PHP4 and activated PHP but when I upload my files it won't connect to MYSQL. I have tried using the php_info() function to check the settings and in the MYSQL section I get the following settings:

MySQL Support enabled
Active Persistent Links 0
Active Links 0
Client API version 3.23.36
MYSQL_MODULE_TYPE external
MYSQL_SOCKET /tmp/mysql.sock
MYSQL_INCLUDE -I/usr/local/mysql/include/mysql
MYSQL_LIBS -L/usr/local/mysql/lib/mysql -lmysqlclient -L/usr -z

Directive Local Value Master Value
mysql.allow_persistent
On On
mysql.default_host
no value no value
mysql.default_password
no value no value
mysql.default_port
no value no value
mysql.default_socket
no value no value
mysql.default_user
no value no value
mysql.max_links
Unlimited Unlimited
mysql.max_persistent
Unlimited Unlimited

Is everything set up ok for a mysql connection? Also, is "localhost" still applicable once it's actually on a web server???

Many thanks.

User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Postby Joan Garnet » Sat Mar 08, 2003 5:56 am

The best way to debug a mysql connection is by using a script like this:

Code: Select all

$server = "localhost";//ask your server administrator just in case it needs a different URL
$db=mysql_connect($server,$login,$pass) or die("<h3>couldn't connect to the Mysql server</h3></BODY></HTML>");     
mysql_select_db($bbdd,$db)or die ("<h3>Couldn't select database</h3></BODY></HTML>");
$sql = "SELECT blah blah blah.........";
$sql_resultado= mysql_query($sql,$db) or die ("<h3>Couldn't query the information</h3></BODY></HTML>");
if ($row = mysql_fetch_array($sql_resultado)){
   do{
      anything...............
   }while   ($row = mysql_fetch_array($sql_resultado));
}else{
   echo "No matches where found.....";
}


You'll get exactly where the error is and you'll be able to find the fix quicker.

bye!


Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 0 guests