gpt4 book ai didi

php - ajax环境下mysql迁移到mysqli

转载 作者:行者123 更新时间:2023-11-29 23:49:42 24 4
gpt4 key购买 nike

首先我想说谢谢你让我再次提问。我知道我之前的问题知识水平有点低。今天想问一下ajax中mysql转mysqli的原理和html一样吗?假设这是我的 Connect.php

<?php
$host = "localhost";
$dbusername = "root";
$dbpassword = "765632";
$dbname = "student";
$link_id = mysqli_connect($host,$dbusername,$dbpassword,$dbname) or die("Error " . mysqli_error($link_id));
?>

我的ajax.php是

<?php
//Connect to MySQL Server

include 'Connect.php';
mysql_connect($host, $dbusername, $dbpassword);
//Select Database
mysql_select_db($dbname) or die(mysql_error());
// Escape User Input to help prevent SQL Injection
$first_name = mysql_real_escape_string(trim($_GET['first_name']));
// Retrieve data from Query
$query = "SELECT student_id, LRN, first_name, last_name, grade, section FROM student_information WHERE first_name LIKE '%{$first_name}%'";
$result = mysql_query($query) or die(mysql_error());
//Generate the output
$searchResults = '';
if(!mysql_num_rows($result))

我应该做哪些更改才能将其转换为 mysqli 而不改变其逻辑方案。

最佳答案

你是这个意思吗?

$link_id = mysqli_connect($host, $dbusername, $dbpassword);
//Select Database
mysqli_select_db($link_id, $dbname) or die(mysqli_error($link_id));
// Escape User Input to help prevent SQL Injection
$first_name = mysqli_real_escape_string($link_id, trim($_GET['first_name']));
// Retrieve data from Query
$query = "SELECT student_id, LRN, first_name, last_name, grade, section FROM student_information WHERE first_name LIKE '%{$first_name}%'";
$result = mysqli_query($link_id, $query) or die(mysqli_error($link_id));
//Generate the output
$searchResults = '';
if(!mysqli_num_rows($result))

关于php - ajax环境下mysql迁移到mysqli,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25706662/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com