Question

PHP MySQL Connectivity

Hi there, this is probably a very basic question but I cannot seem to find the answer on google…

I have installed MySQL and Apache on the cloud server and trying to run a PHP program to indicate whether the connection to a database I have created was successful. I have written the PHP (below) on my personal computer and uploaded the file to the web host I use which is godaddy. For some reason every time I reference this PHP file in the URL the page is blank in the web browser (all my other non database PHP files work ok).

Sorry if this is not clear but could someone please help? I am expecting to see the connection to the database in the cloud was successful!

<?php
$host = 'xxx'; //188.166.....
$user = 'root';
$pass = 'yyy';
$db = 'zzz';

$conn=mysqli_connect($host,$user,$pass,$db);

if($conn)
{
	echo "Connection Successful";
}
else
{
	echo "Could not connect";
}
?>

Thanks,

Alex.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

This comment has been deleted

Hello, I tried to insert a simple data into MySql through PHP. It was not add a new record and no error. Any idea? please help. Here is the code

<?php $servername=“localhost”; $dbname=“gxxxxx”; $username=“xxxxxx”; $password=“xxxxxx”;

// Create connection $dbh = new mysqli($servername, $username, $password, $dbname) or die ('I cannot connect to the database because: ’ . mysql_error());

$sql = “INSERT INTO tbl_ghname ( gcode , email) VALUES (‘34234342234’,‘54535trerterterts’);”; // use exec() because no results are returned $dbh->query($sql);

Thank you again for the reply. I have followed the above (creating a new database and commenting out the bind-address line with a #) but unfortunately I am still receiving a blank web page when accessing the the PHP file through the URL (…tal.com/dbTest.php).

I thought I would at least get an “Error” result instead of a blank page?

I am not sure if the below information helps? This is where I am at at this stage.

MySQL Workbench Details for database dbTest Login Name: alexTest Authentication Type: Standard Limit to hosts matching: % Password: alexTest

PHP file (dbTest.PHP):

<?php
$host = 'xxx'; //188.166.....
$user = 'alexTest';
$pass = 'alexTest';
$db = 'dbtest';

$conn=mysqli_connect($host,$user,$pass,$db);

if($conn)
{
	echo "OK";
}
else
{
	echo "Error";
}
?>

Thank you.

Alex.