MySQL PHP XAMPP - Connect to the database

1
Hello, I need to create a webservice, but I have little experience with php and mysql, so I have some questions, I'm using XAMPP and MySQL Workbench, I made the connection test in the workbench and said that it worked, so maybe not is the problem with MySQL. The webService that I am creating is to make the contents of the database available in a JSON, very simple indeed. I'm basing in this link , if anyone has any tutorial for that. I read that maybe I have to use PDO, will it?

<?php
$host="XXXXX"; //replace with database hostname 
$username="XXXXX"; //replace with database username 
$password="XXXXX"; //replace with database password 
$db_name="XXXXXX"; //replace with database name

$con=mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");
$sql = "select * from emp_info"; 
$result = mysql_query($sql);
$json = array();

if(mysql_num_rows($result)){
while($row=mysql_fetch_assoc($result)){
$json['emp_info'][]=$row;
}
}
mysql_close($con);
echo json_encode($json); 
?> 

The database I can create, as well as update the values, but I have this problem and doubt if it is a problem with MySQL, XAMPP, PHP or some configuration is missing. If anyone can give me some direction to know what I should run after to resolve.

    
asked by anonymous 07.09.2017 / 07:03

0 answers