Re: Problem with database connection on php
I've used
<?php
$username = "andrew";
$password = "password";
$hostname = "localhost";
//connection to the database
$dbhandle = mysqli_connect($hostname, $username, $password) or exit( mysqli_connect_error() );
echo "Connected to MySQL<br>";
$dbh =
//select a database to work with
$selected = mysql_select_db("jamestesting",$dbhandle)
or die("Could not select examples");
?>
the output is Connected to MySQL
Could not select examples however I managed to solve that problem using
<?php
$link = mysqli_connect("localhost", "andrew", "password", "jamestesting");
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;
mysqli_close($link);
?>
the output is Success: A proper connection to MySQL was made! The my_db database is great. Host information: Localhost via UNIX socket
Subject
Written By
Posted
Re: Problem with database connection on php
July 28, 2016 12:06PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.