1

So I'm currently following through some php tutorials and right now I'm learning how to connect the server to a database.

The code I've have type in so far in my text editor is:

<?php

$mysql_host = 'localhost';
$mysql_user = 'root';
$mysql_pass = '';

mysql_connect($mysql_host, $mysql_user, $mysql_pass);
?>

My screen is completely blank so I thought great the code has worked fine. However I thought just to check I'd mess up the code see what response I get. So I changed this:

$mysql_user = 'root'; to $mysql_user = 'alex';

I thought this would throw up an error message on my screen but it didn't, which led me to believe that my code was wrong. Or I have been setting things up wrong, because the user is 'root' not 'alex'.

Just for some information. The text editor I'm using is brackets and the code I have shown is from a file called index.php that is in a folder called databases which sits in the htdocs folder. Oh and I'm using Xampp

  • 1
    Find yourself another tutorial please! `mysql_` functions are deprecated and [will be removed](https://wiki.php.net/rfc/remove_deprecated_functionality_in_php7) in the next PHP release – kero Nov 16 '15 at 11:33
  • 1
    You may want to [read this](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) in conjunction with @kingkero's advice – DavidT Nov 16 '15 at 11:37
  • ok thanks, any good tutorials you know, what should I be using instead of mysql_connect – mike beckett Nov 16 '15 at 11:38
  • Any tutorial that recommends the PDO library would be a good starting point. At least you'll know it's reasonably up-to-date. Try http://phptherightway.com/ for a start. – Simba Nov 16 '15 at 11:54

1 Answers1

0

Add this at begin of file to show warnings:

error_reporting(E_ALL);
ini_set('display_errors', 1);
Nick
  • 9,735
  • 7
  • 59
  • 89