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.


