MySQL Forums
Forum List  »  PHP

Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Group\Apache2\practice\testsql.php on line 17
Posted by: Heidi --
Date: February 13, 2006 12:38PM

I am first time to use MySQL, Apache, and PHP.

I installed both of them. I was doing with the config of Apache include php. I installed MySQL 4.0 but uninstall it because I was not know how to until I was some learned.

I was tested PHP in Apache successfully but PHP is not work with MySQL. My active hard drives: F:\.
I have two hard drives, so
I put libmysql.dll, php_mysql.dll, and php_mysqli.dll to C:\WINDOWS\system32\
F:\WINDOWS\system32\
F:\WINDOWS\system\
C:\php\ext\

then I added php_mysql.dll and php_mysql.dll to php.ini in both C:\WINDOWS\ and F:\WINDOWS\.

;extension=php_mbstring.dll
;extension=php_bz2.dll
;extension=php_curl.dll
;extension=php_dba.dll
;extension=php_dbase.dll
;extension=php_exif.dll
;extension=php_fdf.dll
;extension=php_filepro.dll
;extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_ifx.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
;extension=php_mcrypt.dll
;extension=php_mhash.dll
;extension=php_mime_magic.dll
;extension=php_ming.dll
;extension=php_mssql.dll
;extension=php_msql.dll
;extension=php_mysql.dll <---------added.
;extension=php_mysqli.dll <---------added.
;extension=php_oci8.dll
;extension=php_openssl.dll
;extension=php_oracle.dll
;extension=php_pgsql.dll
;extension=php_shmop.dll
;extension=php_snmp.dll
;extension=php_sockets.dll
;extension=php_sqlite.dll
;extension=php_sybase_ct.dll
;extension=php_tidy.dll
;extension=php_xmlrpc.dll
;extension=php_xsl.dll

I logged in MySQL command, so I used mysql database then I created table:

mysql> CREATE TABLE employees (
--->uname varchar(25) NOT NULL,
--->fname varchar(100) NOT NULL,
--->PRIMARY KEY (uname)
--->);

Query OK, 0 rows affected (0.13 sec)

then

mysql>INSERT INTO employees (uname, fname) VALUES ( 'john', 'John Doe');
Query OK, 1 row affected (0.00 sec)
mysql>INSERT INTO employees (uname, fname) VALUES ( 'sarah', 'Sarah Jane');
Query OK, 1 row affected (0.00 sec)
mysql>INSERT INTO employees (uname, fname) VALUES ( 'tim', 'Tim Shaw');
Query OK, 1 row affected (0.00 sec)
mysql>INSERT INTO employees (uname, fname) VALUES ( 'jane', 'Jane Smith');
Query OK, 1 row affected (0.00 sec)

mysql>SELECT * FROM employees;

+--------+--------------+
| uname | fname |
+----------+------------+
| john | John Doe |
| sarah | Sarah Jane |
| tim | Tim Shaw |
| jane | Jane Smith |
+-----------+-----------+
4 rows in set (0.00 sec)

I closed the my command, but MySQL is still started on.

After I modified with php.ini, I typed my html/php from MySQL book when I used dreamweaver. Here for I show you the code of php:
-----------------------------------------------------------
<html>
<head>
<basefont face="Arial">
</head>

<body>

<?php
// set server access variables
$host = "localhost";
$user = "joe";
$pass = "secret";
$db = "db123";

// open connection to database
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

// select database to use
mysql_select_db($db) or die ("Unable to select database!");

// create SQL query string
$query = "SELECT * FROM employees";

// execute query and obtain result set
$result = mysql_query($query) or die ("Error in guery: $query. " . mysql_error());

// are there any rows in the result?
if (mysql_num_rows($result) > 0)
{
// yes
// iterate through result set
// format query results as table
echo "<table cellpadding=10 border=1>";
while($row = mysql_fetch_row($result))
{
echo "<tr>";
echo "<td>" . $row[0] . "</td>";
echo "<td>" . $row[1] . "</td>";
echo "</tr>";
}
echo "</table>";
}
else
{
// no
// print status message
echo "No rows found!";
}

// free result set memory
mysql_free_result($result);

// close connection
mysql_close($connection);

?>

</body>
</html>

----------------------------------------------------

After I finished type the code, I clicked to opened the Internet Explorer browser, and I typed "http://localhost/testsql.php"; but it's not work:

Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Group\Apache2\practice\testsql.php on line 17

I found $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); in lines 17, but I have no idea how to fix it.


How to fix it? Or Where are installing from?
Or
How do php connect to MySQL?

Why are php connect to mysql are not work well?

Please help me. Thank you.

Heidi.

Options: ReplyQuote


Subject
Written By
Posted
Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Group\Apache2\practice\testsql.php on line 17
February 13, 2006 12:38PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.