Jump to content


Photo

MySQL and PHP


  • Please log in to reply
10 replies to this topic

#1 yana

yana
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts
  • LocationToronto, Canada

Posted 02 August 2006 - 01:30 PM

I am trying to create a database and table in MySQL using PHP and I get the following error when I run the script (not sure what's wrong with line 2):

Fatal error: Call to undefined function: mysql_connect() in /home/yana/html/online_survey/test.php on line 2

Here is my code:
<?php
$con = mysql_connect("devdbyana","","");

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }// Create database
  
$sql = "CREATE DATABASE online_survey";

if (mysql_query($sql,$con))
  {
  echo "Database online_survey created";
  }
else
  {
  echo "Error creating database: " . mysql_error();
  }// Create table in the online_survey database
  
mysql_select_db("online_survey", $con);

$sql = "CREATE TABLE Survey 
(
CourseName varchar(15),
Trainer varchar(15),
QuestionOne varchar(2),
QuestionTwo varchar(2),
QuestionTwoComments varchar(15),
QuestionThree varchar(2),
QuestionFour varchar(2),
QuestionFive varchar(2),
QuestionSix varchar(2),
QuestionSeven varchar(2),
QuestionEight varchar(2),
QuestionNine varchar(2),
QuestionNineComments varchar(15),
QuestionTen varchar(2),
QuestionEleven varchar(2),
QuestionTwelve varchar(15),
QuestionThirteen varchar(15),
QuestionFourteen varchar(15),
QuestionFifteen varchar(15),
QuestionSixteen varchar(15),
Comments varchar(15)
)";

mysql_query($sql,$con);
mysql_close($con);
?>

Yana

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 02 August 2006 - 01:31 PM

What version of PHP?

Ken

#3 yana

yana
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts
  • LocationToronto, Canada

Posted 02 August 2006 - 01:39 PM

PHP Version 4.3.4
Yana

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 02 August 2006 - 02:11 PM

When you complided PHP did you put --without-mysql command? This the only reason I can think of why its not working with PHP4. As by defualt PHP4 is comipled with the --with-mysql command.

#5 yana

yana
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts
  • LocationToronto, Canada

Posted 02 August 2006 - 02:18 PM

Not sure what you mean or where I would put that line of code in my case. This is a web-based system I am building...so I am running the page online in Internet Explorer.
Yana

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 02 August 2006 - 02:22 PM

Did you compile (install) PHP? Its not to do with your PHP code at all, but how PHP was installed. Or are you hosted by some webhost? If you didnt install PHP and are renting webspace I would contact your host and ask why you cannot use the mysql functions.

#7 yana

yana
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts
  • LocationToronto, Canada

Posted 02 August 2006 - 02:30 PM

I didn't install PHP myself. I am working in IT department...I just wanted to figure out whether or not something is wrong with my code before asking the manager and looking dumb!  ::)

Could a reason for my error be that MySQL is not installed on the server?
Yana

#8 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 02 August 2006 - 02:36 PM

No not really, however if you want to connect to a  MySQL database you obviously want it installed but tihs wont affect PHP.  You'll probably want ask the IT manager to see whats up. For now run this:
<?php
phpinfo();
?>
Look for anythink to do with mysql, about two thirds the way down the page there should be a mysql section. Also scroll to the top of the page and paste whats to the right of the Configure Command box here.

Also make sure you're supposed to used mssql/msql database rather tha mysql.

#9 yana

yana
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts
  • LocationToronto, Canada

Posted 02 August 2006 - 02:41 PM

The only thing I found that had to do with MySQL is at the top of the page in the CONFIGURE COMMAND section:
with-mysql=shared,/usr' '--

Nothing else...though there is a whole section on pgsql - PostgreSQL Support.

Could this mean that PostreSQL is installed and MySQL isn't????  ???
Yana

#10 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 02 August 2006 - 02:46 PM

Prehaps you'll have to use pgSQL. But still ask your IT manager whether its possible to use mysql.

#11 yana

yana
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts
  • LocationToronto, Canada

Posted 02 August 2006 - 02:47 PM

Alright! Thanks! I've asked and now waiting for response!
Yana




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users