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

Codes here !

Moderators: egami, macek, gesf

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

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

<title>Obtaining field data from a database</title>
$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 );

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_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
On On
no value no value
no value no value
no value no value
no value no value
no value no value
Unlimited Unlimited
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
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars

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)){
   }while   ($row = mysql_fetch_array($sql_resultado));
   echo "No matches where found.....";

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


Post Reply