mysql - Cannot connect to local databse using php -


i having trouble connecting localhost database php. feels have followed every tutorial there is.

current php code:

<?php //enter database connection info below: $hostname="localhost"; $database="webutvshop"; $username="dbconnect"; $password="password";  //do not edit below line $link = mysql_connect($hostname, $username, $password); if (!$link) { die('connection failed: ' . mysql_error()); } else{      echo "connection mysql server " .$hostname . " successful! " . php_eol; }  $db_selected = mysql_select_db($database, $link); if (!$db_selected) {     die ('can\'t select database: ' . mysql_error()); } else {     echo 'database ' . $database . ' selected!'; }  mysql_close($link);  ?>  

the issue stands, when acess file locally on computer not answer @ it. i've tried many other, yet not answers them!

i need in order keep working on schoolproject, thanks.

stop using mysql_*, because deprecated officially. use mysqli_* or pdo purpose. example:-

<?php  //enter database connection info below:   $hostname="localhost";   $database="stackquestion";   $username="root";   $password=""; // check once empty password , once password tried  //do not edit below line $link = mysqli_connect($hostname, $username, $password); if (!$link) { die('connection failed: ' . mysqli_connect_error()); } else{      echo "connection mysql server " .$hostname . " successful! " . php_eol; }  $db_selected = mysqli_select_db($link,$database); if (!$db_selected) {     die ('can\'t select database: ' . mysqli_error($link)); } else {     echo 'database ' . $database . ' selected!'; }  mysqli_close($link);  ?>  

output:- http://prntscr.com/7cbr5j


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -