Jump to content

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]
Link to comment
https://forums.phpfreaks.com/topic/16322-mysql-and-php/
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.
Link to comment
https://forums.phpfreaks.com/topic/16322-mysql-and-php/#findComment-67801
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?
Link to comment
https://forums.phpfreaks.com/topic/16322-mysql-and-php/#findComment-67811
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.
Link to comment
https://forums.phpfreaks.com/topic/16322-mysql-and-php/#findComment-67816
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????  ???
Link to comment
https://forums.phpfreaks.com/topic/16322-mysql-and-php/#findComment-67823
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.