Jump to content

Newbie Help please connecting to my sql


chaddsuk

Recommended Posts

Hi im new to PHP and am trying to connect to my MYSQL which is setup on my local machine using apache server.

 

I am using the following code to try and connect but all i seem to get is a blank page...

 

<?php

$dbhost = 'localhost';

$dbuser = 'php';

$dbpass = '*****';

 

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die

('Error connecting to mysql');

 

$dbname = 'chadd';

mysql_select_db($dbname);

 

echo "connection made";

 

?>

 

anyone any idea what im doing wrong?

 

cheers

 

chris

Link to comment
https://forums.phpfreaks.com/topic/85048-newbie-help-please-connecting-to-my-sql/
Share on other sites

<?php
$dbhost = 'localhost';
$dbuser = 'php';
$dbpass = '*****';
$dbname = 'chadd';

function connectdb($host, $user, $pass, $db)
{
mysql_connect($host, $user, $pass);
mysql_select_db($db) or die('Unable to select .com database!');

        echo 'Successful Connection';
}

connectdb($dbhost, $dbuser,$dbpass,$db);


?>

 

Not sure why yours won't connect.. .try this one

hi im using MySQL 5.0.45, i added the user correctly and can log in fine through command prompt but just dont seem to be able to connect through PHP?

 

Thanks for your help guys, this is a really great forum, much better than the others ive been on :)

 

 

what is the output from this script:

 

 

<?php
  ini_set('display_errors','on');
  $dbhost = 'localhost';
  $dbuser = 'php';
  $dbpass = '*****';
  $dbname = 'chadd';

  $conn = mysql_connect($dbhost, $dbuser, $dbpass)
    or die('Error connecting to mysql');

  mysql_select_db($dbname)
    or die('Error selecting database');

  echo "connection made";
?>

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.