|
 |
|
รบกวนสอบถามว่า Call to undefined method mysqli::my_sql_select() ต้องแก้ไขอย่างไรค่ะ |
|
 |
|
|
 |
 |
|
รบกวนสอบถาม ว่าต้องแก้ไขโค๊ดนี้ยังไงค่ะ เพิ่งหัดเขียนค่ะ .... -ขอบคุณค่ะ
Fatal error: Call to undefined method mysqli::my_sql_select() in E:\xampp\htdocs\test\index.php on line 48
โค๊ด :
Code (PHP)
<?php
$db_config=array(
"host"=>"localhost", // กำหนด host
"user"=>"root", // กำหนดชื่อ user
"pass"=>"root", // กำหนดรหัสผ่าน
"dbname"=>"student", // กำหนดชื่อฐานข้อมูล
"charset"=>"utf8" // กำหนด charset
);
$mysqli = new mysqli($db_config["host"], $db_config["user"], $db_config["pass"], $db_config["dbname"]);
if(mysqli_connect_error()) {
die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error());
exit;
}
function my_sql_select($field,$table,$event){
if($field == NULL && $event == NULL){
$objQuery=$mysqli->query("SELECT * FROM ".$table);
}else if($field == NULL){
$objQuery=$mysqli->query("SELECT * FROM ".$table." WHERE ".$event);
}else if($event == NULL){
$objQuery=$mysqli->query("SELECT ".$field." FROM ".$table);
}else {
$objQuery=$mysqli->query("SELECT ".$field." FROM ".$table." WHERE ".$event);
}
return $objQuery;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css" />
<title>Test mysqli 1</title>
</head>
<body>
<div class="container">
<br>
<table class="table">
<tr>
<th>#</th>
<th>Name</th>
</tr>
<?php
$aa="admin";
$i=1;
$result = $mysqli->my_sql_select(NULL,"user","name='".addslashes($aa)."'");
while($subject_detail=$result->fetch_object()){ // วนลูปแสดงข้อมูล
?>
<tr>
<td><?php echo $i;?></td>
<td><?php echo $subject_detail->name;?></td>
</tr>
<?php $i++; } ?>
</table>
</div>
<?php
$mysqli->close();
?>
</body>
</html>
Tag : PHP

|
ประวัติการแก้ไข 2017-09-24 12:48:57
|
 |
 |
 |
 |
Date :
2017-09-24 12:48:13 |
By :
kwangz2530 |
View :
2056 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$result = $mysqli->my_sql_select(NULL,"user","name='".addslashes($aa)."'");
สีแดงเองออก my_sql_select เป็น function ที่เขียนขึ้นมาเอง
ไม่ได้อยู่ใน collection ของ mysqli
ปล. ใน function my_sql_select(......) ต้องเพิ่ม ตัวแปร globla $mysqli ด้วย ไม่งั้นก็เออเร่อร์อีก
ศึกษาข้อจำกัดของ ตัวแปรใน และ นอก function ด้วยนะครับ
|
ประวัติการแก้ไข 2017-09-24 14:13:11
 |
 |
 |
 |
Date :
2017-09-24 14:09:33 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|