0

Currently, I am coding using azure app service and azure database server for mysql.

When the 'select' statement is executed, only '1' is returned.

I don't think it's a connection problem because 'insert' statement works fine.

This is my php code running on azure app service.

error_reporting(E_ALL); 
ini_set('display_errors',1); 
include('dbconnectr.php'); 

$id = $_GET['id'];
$stmt = $con->prepare('select * from contents where id='.$id);
$stmt->execute();
$result = $stmt->fetch();
echo $result; 

What is the problem?

최정태
  • 13
  • 2

1 Answers1

0

This script will help you

error_reporting(E_ALL); 
ini_set('display_errors',1); 
include('dbconnectr.php'); 

$id = $_GET['id'];

$stmt = $con->prepare("select * from contents where id=?");

/* bind parameters */
$stmt->bind_param("i", $id);

/* execute query */
$stmt->execute();

/* bind result variables */
$stmt->bind_result($result);

/* fetch value */
$stmt->fetch();

print_r($result);

I use the bind for protecting myself from sql injection.
So I use bind_param to bind the param, then use execute for execute the command and then bind the result in the bind_result and after that use the fetch and fill the result variable and Done

azibom
  • 1,769
  • 1
  • 7
  • 21