에있는 비 객체의 멤버 함수 query()를 호출하십시오. 치명적 오류 : 온라인에있는 객체가 아닌 객체에 대한 호출 : $ result = $ conn-> query ($ SQL) 또는 die (mysqli_error());치명적 오류 :
무엇이 잘못되었고 어떻게 고쳐야하는지 누가 압니까?
return new mysqli($host, $user, $pwd, $db) or die ('Cannot open database');
do xyz or die()
구조 (즉, 모든 일이 나 표현으로 해석 new mysqli
때문에 한 return
문을 연동 해에 재미 행동에 이르게 :
<?php
function dbConnect($usertype, $connectionType = 'mysqli') {
$host = 'localhost';
$db = 'phpsols';
if ($usertype == 'read') {
$user = 'psread';
$pwd = '123';
} elseif ($usertype == 'write') {
$user = 'pswrite';
$pwd = '123';
} else {
exit('Unrecognized connection type');
}
if ($connectionType == 'mysqli') {
return new mysqli($host, $user, $pwd, $db) or die ('Cannot open database');
} else {
try {
return new PDO("mysql:host=$host;dbname=$db", $user, $pwd);
} catch (PDOException $e) {
echo 'Cannot connect to database';
exit;
}
}
}
// connect to MySQL
$conn = dbConnect('read');
// prepare the SQL query
$sql = 'SELECT * FROM images';
// submit the query and capture the result
**$result = $conn->query($sql) or die(mysqli_error());**
// find out how many records were retrieved
$numRows = $result->num_rows;
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Connecting with MySQLi</title>
</head>
<body>
<p>A total of <?php echo $numRows; ?> records were found.</p>
</body>
</html>
그러나 잘 이해한다면 그 행은 실행되지 않고 있으며, 두 번째 인수없이 함수를 호출하고 있습니다. – AJJ
@AJweb 어떤 라인을 의미합니까? 어떤 기능이 있습니까? –
제 사과, "mysqli"가 기본값으로 설정되었음을 몰랐습니다. – AJJ