Solved

Fatal error: Call to undefined function mysql_connect() in

Posted on 2007-11-17
20
1,186 Views
Last Modified: 2013-12-13
Been having problems with this for hours I thought I had an installation that fixed it however it never.

I get get the following error cannot seem to get a solution anywhere but I'll keep asking! lol

Fatal error: Call to undefined function mysql_connect() in C:\AppServ\www\sites\Test\PetShop\PetCatalog.php on line 18

Line 18 being...   $connection = mysql_connect($host,$user,$password)    #13
<?php

  /* Program: PetCatalog.php

   * Desc:    Displays a list of pet categories from the

              PetType table. Includes descriptions.

   *          User checks radio button.

   */

   

//...code...

error_reporting(E_ALL); ini_set('display_errors','On'); 
 

?>

<html>

<head><title>Type Of Pets Available In Ryans Pet Store</title></head>

<body>

<?php

  include("misc.inc");                                  #11
 

  $connection = mysql_connect($host,$user,$password)    #13

       or die ("couldn't connect to server");

  $db = mysql_select_db($database,$connection)          #15

       or die ("Couldn't select database");
 

  /* Select all categories from PetType table */

  $query = "SELECT * FROM PetType ORDER BY petType";    #19

  $result = mysql_query($query)

       or die ("Couldn't execute query.");              #21
 

  /* Display text before form */

  echo "<div style='margin-left: .1in'>

  <h1 align='center'>Pet Catalog</h1>

  <h2 align='center'>The following animal friends are 

                     waiting for you.</h2>

   <p align='center'>Find just what you want and hurry in to

         the store to pick up your new friend.

  <p><h3>Which pet are you interested in?</h3>\n";
 

  /* Create form containing selection list */

  echo "<form action='ShowPets.php' method='post'>\n";  #34

  echo "<table cellpadding='5' border='1'>";

  $counter=1;                                           #36

  while ($row = mysql_fetch_array($result))             #37

  {

     extract($row);                                     #39

     echo "<tr><td valign='top' width='15%'>\n";

     echo "<input type='radio' name='interest' 

                  value='$petType'\n";                  #42

     if ( $counter == 1 )                               #43

     {

         echo "checked";

     }

     echo "><font size='+1'><b>$petType</b></font>";    #47

     echo "</td>

           <td>$typeDescription</td>";                  #49

     echo "</tr>";

     $counter++;                                        #51

  }

  echo "</table>";

  echo "<p><input type='submit' value='Select Pet Type'>  

        </form>\n";                                     #55

?>

</div>

</body></html>

Open in new window

0
Comment
Question by:Ryan Bayne
  • 9
  • 4
  • 3
  • +2
20 Comments
 
LVL 5

Expert Comment

by:administradores
ID: 20303693
Make sure the mysql extension is uncommented in your php.ini
0
 
LVL 5

Expert Comment

by:administradores
ID: 20303698
You can go to you windows dir, search for php.ini and then edit with notepad.

When opened just search for ;extension=php_mysql.dll and uncomment it removing the ";" and restart apache.
0
 
LVL 1

Expert Comment

by:mettletechnlogies
ID: 20303723
###########################
<?php
  include("misc.inc");                                  #11
 
  $connection = mysql_connect($host,$user,$password)    #13
       or die ("couldn't connect to server");
  $db = mysql_select_db($database,$connection)          #15
       or die ("Couldn't select database");
###################################################

check "misc.inc"
$host="your host name";\\ e.g localhost or ip adress
$user="root";
$password="";
$database="";

or you can put it in the current page
$host="your host name";\\ e.g localhost or ip adress
$user="root";
$password="";
$database="";
0
 
LVL 9

Expert Comment

by:alex_code
ID: 20304251
first a small thing, set the >>> error_reporting(E_ALL); ini_set('display_errors','On'); <<<  inside to the php.ini file with the notepad and not inside to your code.

take this code for connection and paste it in a new file and name it as myconn.php and then include it in every php that you want to connect to the db.



<?php
 

	$Host      = "localhost";

	$User      = "";

	$Password  = "";

	$DBName    = "";
 

    $Link = mysql_connect($Host, $User, $Password) or die(mysql_errno() . ": ". mysql_error());

    mysql_select_db($DBName, $Link) or die(mysql_errno() . ": ". mysql_error());
 

?>

Open in new window

0
 
LVL 9

Expert Comment

by:alex_code
ID: 20304260
... but before of this you have to create a user that hasall  the privileges to connect with your db.
0
 
LVL 2

Author Comment

by:Ryan Bayne
ID: 20306093
What if there is a whole list of extensions them should I uncomment any others?
;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_gd2.dll

;extension=php_gettext.dll

;extension=php_gmp.dll

;extension=php_ifx.dll

;extension=php_imap.dll

;extension=php_interbase.dll

;extension=php_ldap.dll

;extension=php_mbstring.dll

;extension=php_mcrypt.dll

;extension=php_mhash.dll

;extension=php_mime_magic.dll

;extension=php_ming.dll

;extension=php_msql.dll

;extension=php_mssql.dll

extension=php_mysql.dll

;extension=php_mysqli.dll

;extension=php_oci8.dll

;extension=php_openssl.dll

;extension=php_pdo.dll

;extension=php_pdo_firebird.dll

;extension=php_pdo_mssql.dll

;extension=php_pdo_mysql.dll

;extension=php_pdo_oci.dll

;extension=php_pdo_oci8.dll

;extension=php_pdo_odbc.dll

;extension=php_pdo_pgsql.dll

;extension=php_pdo_sqlite.dll

;extension=php_pgsql.dll

;extension=php_pspell.dll

;extension=php_shmop.dll

;extension=php_snmp.dll

;extension=php_soap.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

;extension=php_zip.dll

Open in new window

0
 
LVL 2

Author Comment

by:Ryan Bayne
ID: 20306107
"misc.inc"  includes...

$host="your host name";\\ e.g localhost or ip adress
$user="root";
$password="";
$database="";

And I've tried the root account and my own created account with neither working.
0
 
LVL 2

Author Comment

by:Ryan Bayne
ID: 20306118
So Alex this code  error_reporting(E_ALL); ini_set('display_errors','On');

goes in the php.ini file yes?
0
 
LVL 2

Author Comment

by:Ryan Bayne
ID: 20306174
So where put I put this code in the page I pasted in my question?  What do I do about my misc.inc?

I'm getting the feeling that installation MySQL essential is now causing a blank page. How come all this software designed to work together is so difficult.
<?php

 

        $Host      = "localhost";

        $User      = "";

        $Password  = "";

        $DBName    = "";

 

    $Link = mysql_connect($Host, $User, $Password) or die(mysql_errno() . ": ". mysql_error());

    mysql_select_db($DBName, $Link) or die(mysql_errno() . ": ". mysql_error());

 

?>

Open in new window

0
 
LVL 2

Author Comment

by:Ryan Bayne
ID: 20306195
I've went through all this already and this is the second time because I used a different installation and its the same result nothing works.

Now I don't even get the error message or data showing on the page its a nightmare.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 2

Author Comment

by:Ryan Bayne
ID: 20306249
Increased points incase I do get that magix fix lol

I've included another example page which only has the purpose of testing SQL with PHP. It will show a blank page unless I enter...

   error_reporting(E_ALL); ini_set('display_errors','On');

and putting it in the php.ini file makes no difference. I inserted your code and it gets the same error Fatal error: Call to undefined function but refers to "$Link = mysql_connect($Host, $User, $Password) or die(mysql_errno()"

Its looking like it just doesnt like anything to do with MySQL.
<html>

<head><title>Test MySQL</title></head>

<body>

<!-- mysql_up.php -->

<?php
 

   error_reporting(E_ALL); ini_set('display_errors','On'); 

   

$host="localhost";

$user="root";

$password="25130217cmt";

$DBName="petcatalogue"; 
 

    $Link = mysql_connect($Host, $User, $Password) or die(mysql_errno() . ": ". mysql_error());

    mysql_select_db($DBName, $Link) or die(mysql_errno() . ": ". mysql_error());
 
 

mysql_connect($host,$user,$password);

$sql="show status";

$result = mysql_query($sql);

if ($result == false)

{

   echo "<b>Error " . mysql_errno() . ": " 

         . mysql_error() . "</b>";

}

else

{

?>

<!-- Table that displays the results -->

<table border=”1”>

  <tr><td><b>Variable_name</b></td><td><b>Value</b>

      </td></tr>

  <?php

    for ($i = 0; $i < mysql_num_rows($result); $i++) {

      echo "<TR>";

      $row_array = mysql_fetch_row($result);

      for ($j = 0; $j < mysql_num_fields($result); $j++) 

      {

        echo "<TD>" . $row_array[$j] . "</td>";

      }

      echo "</tr>";

    }

  ?>

</table>

<?php } ?>

</body></html>

Open in new window

0
 
LVL 5

Expert Comment

by:administradores
ID: 20306393
Hi TycoonMillion

First:

Uncomment these extensions from you php.ini file, when done close it and forget this file.

extension=php_gd2.dll (to be able to work with images, this library is commonly used)
extension=php_mysql.dll (the one you need to e able to run mysql functions)

Second:

Take a look at the code, test it and post the results.






<?php
 

//

// Report all errors

//
 

error_reporting(E_ALL);
 

//

// Output the errors to the browser if any

//
 

ini_set('display_errors', 'On');
 
 

// Connection Information

//

//

// Remember that php is case sensitive, so $host, $Host and $HOST are different variables.

//
 

$host = "localhost";

$user = "root";

$password = "25130217cmt";

$dbname = "petcatalogue";
 

//

// Connect to MYSQL Server

//

$link = mysql_connect($host, $user, $password) or die(mysql_errno() . ": " . mysql_error());
 

//

// Select a database

//

mysql_select_db($dbname, $link) or die(mysql_errno() . ": " . mysql_error());
 
 

//

// SQL Query

//
 

$sql ="SHOW STATUS";
 

$result = mysql_query($sql);
 

//

// SQL Query Result to output

//
 

$output  = "<html>

<head><title>Test MySQL</title></head>

<body>

<!-- mysql_up.php -->

<table border=”1”>

	<tr>

	<td>

	<b>Variable_name</b>

	</td>

	<td>

	<b>Value</b>

	</td>

	</tr>

";
 

if ($result === false)

{

   echo "<b>Error " . mysql_errno() . ": "  . mysql_error() . "</b>";

}

else

{

	//

	// Loop thru the results to populate data.

	//

	for ($i = 0; $i < mysql_num_rows($result); $i++)

	{

		$output .= "<tr>";
 

		$row_array = mysql_fetch_row($result);
 

		for ($j = 0; $j < mysql_num_fields($result); $j++) 

		{

			$output .= "<td>" . $row_array[$j] . "</td>";

		}
 

		$output .= "</tr>";

	}

}
 

$output .= '</table></body></html>';
 

//

// Output the result.

//
 

echo $output;
 

?>

Open in new window

0
 
LVL 9

Expert Comment

by:alex_code
ID: 20307140
TycoonMillion i didn't say to take exact the line and put it to the php.ini file.
Inside the ini has a line with the error reports go there and uncomment this line and remove from your code this  >>> error_reporting(E_ALL); ini_set('display_errors','On'); <<<
0
 
LVL 1

Expert Comment

by:nfc036
ID: 20307818
Hi TycoonMillion,
Probably the mysql-extension is not working, because php is not finding the correct libmysql.dll. PHP comes with a libmysql.dll. You could i.e. add your php-rootdirectory (i.e. C:\PHP) to your PATH or (not recommended!) copy libmysql.dll from that directory to c:\windows\system32. Also make sure that extension_dir in php.ini is pointing to the correct directory containing php_mysql.dll.


Cited from http://de2.php.net/manual/en/ref.mysql.php :

PHP 5+

MySQL is no longer enabled by default, so the php_mysql.dll DLL must be enabled inside of php.ini. Also, PHP needs access to the MySQL client library. A file named libmysql.dll is included in the Windows PHP distribution and in order for PHP to talk to MySQL this file needs to be available to the Windows systems PATH. See the FAQ titled "How do I add my PHP directory to the PATH on Windows" for information on how to do this. Although copying libmysql.dll to the Windows system directory also works (because the system directory is by default in the system's PATH), it's not recommended.

As with enabling any PHP extension (such as php_mysql.dll), the PHP directive extension_dir should be set to the directory where the PHP extensions are located. See also the Manual Windows Installation Instructions. An example extension_dir value for PHP 5 is c:\php\ext

    Note: If when starting the web server an error similar to the following occurs: "Unable to load dynamic library './php_mysql.dll'", this is because php_mysql.dll and/or libmysql.dll cannot be found by the system.
0
 
LVL 2

Author Comment

by:Ryan Bayne
ID: 20315411
Alex is that not just the same thing!!!   I done that anyway and the error stops showing so its a little worse. I love that little error to show blank pages scare me lol

And nfc036 what exactly is the "PATH" ?  

My installation was one of those setups where it installs MySQL PHP and Apachi all at the same time. It should really be set up for all that already as far as I was aware. Wouldnt you think this would be the case?
0
 
LVL 5

Expert Comment

by:administradores
ID: 20315599
<< I get get the following error cannot seem to get a solution anywhere but I'll keep asking! lol

Fatal error: Call to undefined function mysql_connect() in C:\AppServ\www\sites\Test\PetShop\PetCatalog.php on line 18

If i stick to your Q and as i tryed to answer before (the first 2 comment on this thread) the above error is because the mysql extension was not loaded, and so , the first step to take whichever is the installation you made is to see if PHP.INI is correctly configured, then if the error "Fatal error: Call to undefined function mysql_connect() " dissapear the issue and Q is other.
0
 
LVL 1

Expert Comment

by:nfc036
ID: 20318496
TycoonMillion, what happens when you copy libmysql.dll from your php directory to your Windows System32-Directory and restart apache?
0
 
LVL 1

Accepted Solution

by:
nfc036 earned 500 total points
ID: 20318686
Regarding "PATH": open "System Properties" (right-Click "My Computer", Properties), Tab "Advanced", Button "Environment Variables", in "System Variables" (bottom part) look for "Path" and Double-Click that entry. Than add your php-directory at the end of this value, i.e. change the entry from "C:\Windows\System32;C:\Windows" to "C:\Windows\System32;C:\Windows;C:\PHP5".
0
 
LVL 2

Author Comment

by:Ryan Bayne
ID: 20320472
The current PATH is...

C:\AppServ\Apache2.2\bin;C:\AppServ\php5;C:\AppServ\MySQL\bin

and I changed it too...

C:\Windows\System32;C:\Windows;C:\PHP5
0
 
LVL 2

Author Comment

by:Ryan Bayne
ID: 20320494
And that fixed the problem it is not communicating with MySQL thanks loads
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now