Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP and MYSQL

Status
Not open for further replies.

sweetlew

Programmer
Dec 31, 2003
36
0
0
US
I'm having problems with PHP and MYSQL. OK, I'm running apache2 and PHP on a test Ubuntu(Warty) pc at home, I have MySql installed. I can access from other machines and have created tables.

I also have PHP install from what I can tell correctly. I can show the PHP info when I issue the PHPINFO () command from a web page. So it appears that the two are install OK.

The problem comes in when I try to issue code to display a MySql database from PHP. I get this error "Fatal Error: Call to undefined function: mysql_connect()".


I've spent the last two days on the web and have tried all the suggestions,
1. Uncomment the extensions = mysql.so in php.ini.
2. point the dir to the directory of the MySql.so
3. move around web pages etc.... etc....

I've tried everthing and nothing seems to work. Could someone please help!!!!
 
what version of php? Note that version 5 does not have the mysql extension automatically working. You may need to recompile php with the mysqli extention of you have v5 of PHP.

Bastien

I wish my computer would do what I want it to do,
instead of what I tell it to do...
 
Sorry this is Windows, but...

Check that phpinfo() shows a MySQL section, if not then it isn't working.

Check that the PHP.ini is in the path e.g. set PATH=%PATH%;c:\php.

Check that you have added the following to httpd.conf:

LoadModule php5_module "c:/php/php5apache2.dll"
AddType application/x-httpd-php .php

# configure the path to php.ini
PHPIniDir "C:/php"


Sorry that I'm using php/mysql on windows at the moment, though I've used Apache on Unix in the past.

James.
 
Doing a PHPINFO() DOES return my PHP4 setup info. So that seems to be installed correctly.

I also have tried doing all of the above mentioned suggestions and no luck!!!!
 
v4 should have the mysql stuff as default (it was bundled) can you post your code?

Bastien

I wish my computer would do what I want it to do,
instead of what I tell it to do...
 
Here's my code, I filled x's for my IP of my linux box.

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?PHP

/* declare some relevant variables */
$hostname = "xxx.xxx.xxx.xx"; /* This is the hostname on which your MySQL is running */
$dbName = "employees";
$username = "xxx";
$password = "password";
$table = "employee_data"; /* MySQL table created to store the data */
/* Make connection to database */
mysql_connect($hostname, $username, $password) OR DIE("Unable to connect to dat
abase");

/* Select the database to be processed */
@mysql_select_db( "employee_data") or die( "Unable to select database");

/* Prepare the SQL query statement */
$query = "SELECT * FROM $table";

/* Execute the query */
$result = MYSQL_QUERY($query);
/* Now do something with the query result. e.g. print out the number of selected rows. */
$numberofrow = mysql_num_rows($result);
print "$numberofrow";
/* Close the database connection */
MYSQL_CLOSE();
?>

</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top