로컬 데이터베이스에 연결된 기본 등록 페이지를 얻으려고합니다.PHP 변수가 정의되지 않았습니다.
Notice: Undefined variable: dbhost in C:\wamp\www\functions.php on line 19
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\wamp\www\functions.php on line 19
Notice: Undefined variable: con in C:\wamp\www\functions.php on line 19
Warning: mysqli_error() expects parameter 1 to be mysqli, null given in C:\wamp\www\functions.php on line 19
이것은 내가 얻은 오류입니다. function.php 스크립트에서 함수를 참조 할 때 발생합니다.
<?php //functions.php
$dbhost = 'localhost'; //change to webserver ip
$dbname = 'maindb';
$dbuser = 'administrator';
$dbpass = 'password';
$appname = "webapp";
$con = mysqli_connect($dbhost,$dbuser,$dbpass) or die (mysqli_error($con));
mysqli_select_db($con, $dbname) or die (mysqli_error($con));
function createTable($name, $query)
{
queryMysql("CREATE TABLE IF NOT EXISTS $name($query)");
echo "Table '$name' created or already exists<br>";
}
function queryMysql($query)
{
$result = mysqli_query($dbhost, $query) or die(mysqli_error($con));
return $result;
}
나는이 문제가 무엇인지 확실하지 않습니다. 몇 년 전 PHP를 배웠고 2011 년 이후로는 조금 변경된 것으로 보입니다. 어떤 도움을 주시면 감사하겠습니다.
'$ dbhost' 함수에서 잘못된 변수 사용하기 –