Jump to content


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


Can't connect to a database through php

Recommended Posts


I'm trying to get php to work with mysql. If I log onto mysql with my credentials I can look at the database and so some commands.

If I attempt to do the same in php via a script : -


$link = mysql_connect('localhost', 'james', 'password');

if (!$link) {

print('Could not connect: ' . mysql_error());


echo 'Connected successfully';



I don't get to see the success message but neither do I get the error message. Could someone please spread some light on this as I have a long way to go on my php/mysql journey and this is depressingly early roadblock.


Share this post

Link to post
Share on other sites
Use the "or die" clause instead of the "if" statement:
$link = mysql_connect('localhost', 'james', 'password') or die('Could nit connect: ' . mysql_error());
echo 'Connected successfully';


Share this post

Link to post
Share on other sites


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.