Current location: Hot Scripts Forums » Programming Languages » PHP » Fatal error: Call to undefined function mysql_connect() in C:\Core Media\test_mysql.p


Fatal error: Call to undefined function mysql_connect() in C:\Core Media\test_mysql.p

Reply
  #1 (permalink)  
Old 07-24-04, 11:50 AM
phpbeginner phpbeginner is offline
New Member
 
Join Date: Jul 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Angry Fatal error: Call to undefined function mysql_connect() in C:\Core Media\test_mysql.p

I am busy learning PHP/Perl/MySQL, and was told to install a server on my PC to better my understanding and for test purposes.

THe server runs perfectly and PHP 5 has no problems, however I had a problem with MySQL. I found a tutorial by Surjit on WebThang.co.uk and everything worked fine up until I had to test MySQL.

After adding the script into the php file and running it I get the error in the subject line. Could anybody help me with this.
===================================
Here is the Error Message

Fatal error: Call to undefined function mysql_connect() in C:\Core Media\test_mysql.php on line 19

Here is line 19

$connection = mysql_connect($host,$username,$password);

And here is the script:

<?
/************************************************** **********
this script runs only once, it then drops the database before
mysql connection is closed.
************************************************** **********/

/************************************************** *
string values passed on to the following 5 variables.
two of each are assigned to 'ice' and the rest three
tag along into 'mysql_connect'
************************************************** */
$iceCreamOne = "Vanilla"; // Type One Ice Cream
$iceCreamTwo = "Cookie Dough Ice Cream"; // Type Two Ice Cream
$host = "localhost"; // hostname...in our case localhost
$username = "root"; // root is our default
$password = "ranginyoka31"; // your mysql password please

//open connection to the MySQL database server.
$connection = mysql_connect($host,$username,$password);
//if connection fails, display the error involved
if ($connection == false){
echo mysql_errno().": ".mysql_error()."<BR>";
//echo("Your username or password is not correct.");
exit;
}

/************************************************
After supper we will have two kinds of desserts
create the database then select it. Two functions
called mysql_create_db() & mysql_select_db()
if statements to check success of create & select
************************************************/
$create_success = mysql_create_db("aftersupper");
if($create_success)echo("<b><font color=\"blue\">create database: success!</font></b><br>");
$select_success = mysql_select_db("aftersupper");
if($select_success)echo("<b><font color=\"blue\">selected the created database: success!</font></b>");

/************************************************** ***********
your choice for 2 desserts
for me I like vanilla[iceCreamOne] & cookie dough[iceCreamTwo]
************************************************** ***********/
mysql_query("CREATE TABLE desserts(iceCreamOne VARCHAR(25),
iceCreamTwo VARCHAR(25))");

/************************************************** ********
i put my two favorite ice cream types into table desserts: vanilla & cookie dough
remember im using variables that have been assigned with strings up there ^^^.
************************************************** *******/
mysql_query ("INSERT INTO desserts (iceCreamOne, iceCreamTwo) VALUES
('$iceCreamOne', '$iceCreamTwo')");

/************************************************** ******
as long as there is information in the table keep printing.
i have two values in table 'desserts', both rows are passed to variable 'result'
************************************************** ********/
$result = mysql_query ("SELECT * FROM desserts");

//checking to see that select was successfull
//if ($result){echo "<h2>Successfully selected from table desserts!</h2>\n";}

//assign the number of rows from variable $result to $numOfRows
//$numOfRows = mysql_num_rows ($result);

//for ($i = 0; $i < $numOfRows; $i++)
//{
$row = mysql_fetch_array($result);
print ("<h3>My 2 most favorite Ice Cream are:</h3><br>\n");
print($row["iceCreamOne"]." and ");
print($row["iceCreamTwo"]. "<br>");
// }

//Database gets dropped. You can comment the line below if you wish to keep the database
mysql_query("DROP DATABASE aftersupper");

//close the connection to the db with the particular user :: $username
mysql_close();
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-24-04, 01:40 PM
kvnband kvnband is offline
Wannabe Coder
 
Join Date: Jun 2003
Posts: 242
Thanks: 0
Thanked 0 Times in 0 Posts
Please nobody kill me if I'm wrong :-)

open your php.ini (usually in C:\windows)

search for [MySQL]. If it doesn't exist, add it.

Now under MySQL, add the following:

Code:
; Allow or prevent persistent links.
mysql.allow_persistent = On

; Maximum number of persistent links.  -1 means no limit.
mysql.max_persistent = -1

; Maximum number of links (persistent + non-persistent).  -1 means no limit.
mysql.max_links = -1

; Default port number for mysql_connect().  If unset, mysql_connect() will use
; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
; compile-time value defined MYSQL_PORT (in that order).  Win32 will only look
; at MYSQL_PORT.
mysql.default_port =

; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
mysql.default_socket =

; Default host for mysql_connect() (doesn't apply in safe mode).
mysql.default_host = localhost

; Default user for mysql_connect() (doesn't apply in safe mode).
mysql.default_user = root

; Default password for mysql_connect() (doesn't apply in safe mode).
; Note that this is generally a *bad* idea to store passwords in this file.
; *Any* user with PHP access can run 'echo get_cfg_var("mysql.default_password")
; and reveal this password!  And of course, any users with read access to this
; file will be able to reveal the password as well.
mysql.default_password =

; Maximum time (in secondes) for connect timeout. -1 means no limimt
mysql.connect_timeout = -1

; Trace mode. When trace_mode is active (=On), warnings for table/index scans and
; SQL-Erros will be displayed.
mysql.trace_mode = On
I've just copied this straight from my php.ini file, and I'm hoping it'll work for you.

So thererore, your MySQL section of php.ini will look like this

Code:
[MySQL]
; Allow or prevent persistent links.
mysql.allow_persistent = On

; Maximum number of persistent links.  -1 means no limit.
mysql.max_persistent = -1

; Maximum number of links (persistent + non-persistent).  -1 means no limit.
mysql.max_links = -1

; Default port number for mysql_connect().  If unset, mysql_connect() will use
; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
; compile-time value defined MYSQL_PORT (in that order).  Win32 will only look
; at MYSQL_PORT.
mysql.default_port =

; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
mysql.default_socket =

; Default host for mysql_connect() (doesn't apply in safe mode).
mysql.default_host = localhost

; Default user for mysql_connect() (doesn't apply in safe mode).
mysql.default_user = root

; Default password for mysql_connect() (doesn't apply in safe mode).
; Note that this is generally a *bad* idea to store passwords in this file.
; *Any* user with PHP access can run 'echo get_cfg_var("mysql.default_password")
; and reveal this password!  And of course, any users with read access to this
; file will be able to reveal the password as well.
mysql.default_password =

; Maximum time (in secondes) for connect timeout. -1 means no limimt
mysql.connect_timeout = -1

; Trace mode. When trace_mode is active (=On), warnings for table/index scans and
; SQL-Erros will be displayed.
mysql.trace_mode = On
After you make those changes, restart your computer and try the script again.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Error Fairnie PHP 8 06-26-04 08:15 AM
Disable form fields to be submitted RickyRod JavaScript 2 05-24-04 11:15 AM
accessing existing ISP email with a PHP webmail script. nlancaster PHP 1 01-07-04 04:28 AM
Help trim code down TheLaughingBandit JavaScript 0 09-02-03 10:50 AM


All times are GMT -5. The time now is 03:02 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.