Jump to content

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]
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

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

Archived

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

×
×
  • 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.