0
MySql에 대한 데이터 연결을 설정하고 준비된 문을 작성하려고합니다. 여기서 query_f 함수는 첫 번째 매개 변수가 SQL 문이고 다른 매개 변수는 값입니다 그것은 준비된 진술에서 대체 될 것입니다.PHP mysqli_bind_param 함수 문제. 준비된 문 구현하기
다음은 내가 가지고있는 것입니다. 첫 번째 오류는 값을 문에 바인딩하려고 할 때 발생합니다.
function query_f(/* query, [...] */){
$user = "root";
$pass = "root";
$host = "localhost";
$database = "mcnair";
$conn = mysqli_connect($host,$user,$pass);
if(!$conn)
{
echo "Cannot connect to Database";
}
else
{
mysqli_select_db($conn, $database);
}
// store query
$query = func_get_arg(0);
$parameters = array_slice(func_get_args(), 1);
$param = "'".implode("','",$parameters)."'";
// Prepare the statement
$stmt = mysqli_prepare($conn, $query);
if ($stmt == false)
{
echo "The statement could not be created";
exit;
}
// Bind the parameters
$bind = mysqli_stmt_bind_param($stmt, 's', $param);
echo mysqli_stmt_error($stmt);
if ($bind == false)
{
echo "Could not bind";
}
else
{
echo "Bind successful";
}
// Execute the statement
$execute = mysqli_stmt_execute($stmt);
if ($execute = false)
{
echo "Could not execute";
}
// fetch the data
$fetch = mysqli_stmt_fetch($stmt)
if ($fetch == false)
{
echo "Could not fetch data";
}
else
{
return $fetch;
}
}
그리고 내가 사용하고 함수 호출은 다음과 같습니다
query_f("SELECT Hash FROM alumni WHERE Username = '?'", "zm123");
"첫 번째 오류가 발생했습니다 ..."오류가 있습니까? –
사용자 지정 함수를 작성하기 전에 원시 API로 연습해야합니다. –
'Username = '?''<='? ' –