Jump to content

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";
?>

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.