Jump to content

Archived

This topic is now archived and is closed to further replies.

yana

MySQL and PHP

Recommended Posts

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):

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

Here is my code:
[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);
?>[/code]

Share this post


Link to post
Share on other sites
When you complided PHP did you put [i]--without-mysql[/i] 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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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:
[code]<?php
phpinfo();
?>[/code]
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.

Share this post


Link to post
Share on other sites
The only thing I found that had to do with MySQL is at the top of the page in the CONFIGURE COMMAND section:
[code]with-mysql=shared,/usr' '--[/code]

Nothing else...though there is a whole section on [b]pgsql[/b] - PostgreSQL Support.

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

Share this post


Link to post
Share on other sites
Prehaps you'll have to use pgSQL. But still ask your IT manager whether its possible to use mysql.

Share this post


Link to post
Share on other sites
Alright! Thanks! I've asked and now waiting for response!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.