mysqli 相关问题

mysqli PHP扩展(“MySQL改进”)是PHP数据库驱动程序,包含自PHP 5以来。它利用了MySQL 4.1.3和更新版本中引入的新功能。

如何在codeigniter中使用BETWEEN条件?

代码: $最低工资 = 200000; 最大工资 = 500000; $标题=java; $this->db->select('*'); $this->db->from('工作'); $where = "((salary_range_min='".$salarymin."') 和 (salary_range_max='".$

回答 3 投票 0

如何使 mysql_ 数据库连接与 PHP 8 一起工作运输时间

运输时间 <!doctype html> <html> <head> <meta charset="utf-8"> <title>Transit Times</title> </head> <body style="font-family:'Gill Sans', 'Gill Sans MT', 'Myriad Pro', 'DejaVu Sans Condensed', Helvetica, Arial, sans-serif; margin:0px; padding:0px"> <?php $orig = $_REQUEST['orig']; $dest = $_REQUEST['dest']; $connection = mysqli_connect("localhost","my_user","my_password","my_db"); $result = $mysqli->query("select * from transit where trans_orig = '$orig' and trans_dest = '$dest'"); $row = mysqli_fetch_array($query); ?> <h2>Transit Times between <?=$orig?> and <?=$dest?> </h2> <table cellpadding="2" cellspacing="0" border="1" bordercolor="#EF090D" > <tr style="font-weight:bold; background-color:#050F5B; color:#fff"> <td rowspan="2" align="center">M-F<br> Cutoff</td> <td rowspan="2" align="center">Sun<br> Cutoff</td> <td rowspan="2" valign="bottom">Avail</td> <td rowspan="2" valign="bottom">SVC</td> <td colspan="7" align="center">Ship Day / Recovery</td> </tr> <tr style="font-weight:bold; background-color:#050F5B; color:#fff"> <td>Mon</td> <td>Tue</td> <td>Wed</td> <td>Thu</td> <td>Fri</td> <td>Sat</td> <td>Sun</td> </tr> <tr> <td><?php echo $row['trans_mfcutoff'];?></td> <td><?php echo $row['trans_scutoff'];?></td> <td><?php echo $row['trans_avail'];?></td> <td><?php echo $row['trans_svc'];?></td> <td><?php echo $row['trans_mon'];?></td> <td><?php echo $row['trans_tue'];?></td> <td><?php echo $row['trans_wed'];?></td> <td><?php echo $row['trans_thu'];?></td> <td><?php echo $row['trans_fri'];?></td> <td><?php echo $row['trans_sat'];?></td> <td><?php echo $row['trans_sun'];?></td> </tr> </table> </body> </html> 我正在尝试连接到 PHP 8 上的数据库以在表中显示信息。我知道 mysql_ 已过时,但我不确定如何正确更新它以与 PHP 8 等新版本一起使用。我在连接到较新服务器上的数据库时遇到问题。你能帮忙吗? 您可以使用以下代码 mysqli 来代替: ... $orig = $_REQUEST['orig']; $dest = $_REQUEST['dest']; $sql = "select * from transit where trans_orig = '$orig' and trans_dest = '$dest'"; $dbAuth = new mysqli("localhost", "databaseuser", "databasepassword", "databasename"); $result = mysqli_query($dbAuth, $sql); $results = mysqli_fetch_all($result, MYSQLI_ASSOC); if (count($results) == 0) { die("No Results"); // Or handle the case yourself } $row = $results[0]; ...

回答 1 投票 0

获取下拉数据

问题是当我单击第一类时显示所有类数据。我希望当有人单击任何类时仅显示该类数据。我认为我的查询中的问题是我的代码 $x=$_POST['c_id']; ...

回答 1 投票 0

PDO 和 MySQLi 准备好的语句有什么区别?

这两个准备好的语句有什么区别? 1 $stmt = $pdo->prepare('从员工中选择 * WHERE name = :name'); $stmt->execute(array('name' => $name)); foreach ($stm...

回答 2 投票 0

倒计时数据未显示在 JavaScript php mysqli 中的每个循环卡中

我创建了一张卡片,想要显示同一张表的每一行的时间倒计时,并且循环运行良好,但计时器仅适用于第一个循环,然后它不适用于其他循环而不是...

回答 1 投票 0

未定义常量 MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT [重复]

当我使用 PHP、MySQLI 并激活 SSL 连接到外部 MySQL-DB (MariaDB 10) 时...: /* 创建一个未连接的连接对象 */ $conn = 新的 mysqli(); $conn->init(...

回答 1 投票 0

PHP MySqli、SSL 和 mysqli_real_escape_string 不起作用

当我使用 PHP、MySQLI 并激活 SSL 连接到外部 MySQL-DB (MariaDB 10) 时...: /* 创建一个未连接的连接对象 */ $conn = 新的 mysqli(); $conn->init(...

回答 1 投票 0

如果客户状态发生变化则SQL查询,如果状态没有变化则不需要记录

[为表和输出1添加的图片如下是表结构 id , status 和 datechange ID 英石 成田 123 1 2022年7月1日 123 1 2022年2月7日 123 1 2022年3月7日 123 1 2022年7月1日 145 1 2022年5月7日 ...

回答 1 投票 0

插入 MySql PHP [已关闭]

我正在尝试使用 PHP 将数据添加到 MySql 数据库中。 代码: 我正在尝试使用 PHP 将数据添加到 MySql 数据库中。 代码: <?php session_start(); include('config.php'); if(isset($_POST['Submit'])) { $city = $_POST['city']; $from_station = $_POST['from_station']; $from_date = $_POST['from_date']; // Prepare and execute the SQL query $sql = "INSERT INTO journeys (city, from_station, from_date) VALUES ('$city', '$from_station', '$from_date')"; $result = $conn->query($sql); if (mysqli_query($conn, $sql)) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . mysqli_error($conn); } } ?> <!DOCTYPE html> <html lang="pt_PT"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>IR PLANNER</title> <link rel="stylesheet" href="Styles\general_styles.css"> <link rel="stylesheet" href="Styles\citymanager_styles.css"> </head> <body> <form class="modal" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <label for="city">City:</label> <input type="text" name="city" id="city"> <label for="from_station">From Station:</label> <input type="text" name="from_station" id="from_station"> <label for="from_date">From Date:</label> <input type="date" name="from_date" id="from_date"> <input type="submit" value="Submit" id="Submit"> </form> </body> </html> 按下提交按钮时,不会显示错误。然而,当检查数据库表时,什么也没有出现。 我已阅读文章,并且 sql 连接(config.php)工作正常(在其他页面和文件中工作)并且 sql 查询也很好。 有人遇到这个问题吗? 您需要在提交按钮中传递 name 属性,直到您无法从中获取任何值。在您的条件下,它总是返回 false。所以不会更新任何内容,也不会生成错误。只需更新这里是更新的代码。 <?php session_start(); include('config.php'); if(isset($_POST['Submit'])) { $city = $_POST['city']; $from_station = $_POST['from_station']; $from_date = $_POST['from_date']; // Prepare and execute the SQL query $sql = "INSERT INTO journeys (city, from_station, from_date) VALUES ('$city', '$from_station', '$from_date')"; $result = $conn->query($sql); if (mysqli_query($conn, $sql)) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . mysqli_error($conn); } } ?> <!DOCTYPE html> <html lang="pt_PT"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>IR PLANNER</title> <link rel="stylesheet" href="Styles\general_styles.css"> <link rel="stylesheet" href="Styles\citymanager_styles.css"> </head> <body> <form class="modal" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <label for="city">City:</label> <input type="text" name="city" id="city"> <label for="from_station">From Station:</label> <input type="text" name="from_station" id="from_station"> <label for="from_date">From Date:</label> <input type="date" name="from_date" id="from_date"> <input type="submit" name="Submit" value="Submit" id="Submit"> </form> </body> </html> 您可以采取一些措施来分析问题/优化代码。 1.要调试代码:回显一个值以检查是否进入 if 语句 例如: if(isset($_POST['Submit'])) { var_dump(__LINE__); 现在运行代码以查看到达了哪些行。 2. if 语句中的代码不会被执行,因为: 此代码: <input type="submit" value="Submit" id="Submit"> 需要 name 属性,才能作为数据发送到服务器: <input type="submit" name="Submit" value="Submit" id="Submit"> 3.使用mysqliprepare准备sql语句 代替当前的插入代码,制作它 $stmt = $conn->prepare("INSERT INTO journeys (city, from_station, from_date) VALUES (?, ?, ?)"); $stmt->bind_param("sss", $city, $from_station, $from_date); $stmt->execute(); 这样就不会发生SQL注入了。 4.在您的代码中,您还执行了两次 SQL。 在这些线上: $result = $conn->query($sql); if (mysqli_query($conn, $sql)) { 替换为第 3 点的代码。 生成的代码 <?php session_start(); include('config.php'); if(isset($_POST['Submit'])) { $city = $_POST['city']; $from_station = $_POST['from_station']; $from_date = $_POST['from_date']; // Prepare and execute the SQL query $stmt = $conn->prepare("INSERT INTO journeys (city, from_station, from_date) VALUES (?, ?, ?)"); $stmt->bind_param("sss", $city, $from_station, $from_date); $stmt->execute(); } ?> <!DOCTYPE html> <html lang="pt_PT"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>IR PLANNER</title> <link rel="stylesheet" href="Styles\general_styles.css"> <link rel="stylesheet" href="Styles\citymanager_styles.css"> </head> <body> <form class="modal" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <label for="city">City:</label> <input type="text" name="city" id="city"> <label for="from_station">From Station:</label> <input type="text" name="from_station" id="from_station"> <label for="from_date">From Date:</label> <input type="date" name="from_date" id="from_date"> <input type="submit" name="Submit" value="Submit" id="Submit"> </form> </body> </html>

回答 2 投票 0

在PHP中执行SQL查询时,没有显示错误,但数据库中看不到数据。我应该检查什么?

我正在尝试使用 PHP 将数据添加到 MySql 数据库中。 代码: 我正在尝试使用 PHP 将数据添加到 MySql 数据库中。 代码: <?php session_start(); include('config.php'); if(isset($_POST['Submit'])) { $city = $_POST['city']; $from_station = $_POST['from_station']; $from_date = $_POST['from_date']; // Prepare and execute the SQL query $sql = "INSERT INTO journeys (city, from_station, from_date) VALUES ('$city', '$from_station', '$from_date')"; $result = $conn->query($sql); if (mysqli_query($conn, $sql)) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . mysqli_error($conn); } } ?> <!DOCTYPE html> <html lang="pt_PT"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>IR PLANNER</title> <link rel="stylesheet" href="Styles\general_styles.css"> <link rel="stylesheet" href="Styles\citymanager_styles.css"> </head> <body> <form class="modal" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <label for="city">City:</label> <input type="text" name="city" id="city"> <label for="from_station">From Station:</label> <input type="text" name="from_station" id="from_station"> <label for="from_date">From Date:</label> <input type="date" name="from_date" id="from_date"> <input type="submit" value="Submit" id="Submit"> </form> </body> </html> 按下提交按钮时,不会显示错误。然而,当检查数据库表时,什么也没有出现。 我已阅读文章,并且 sql 连接(config.php)工作正常(在其他页面和文件中工作)并且 sql 查询也很好。 有人遇到这个问题吗? 您需要在提交按钮中传递 name 属性,直到您无法从中获取任何值。在您的条件下,它总是返回 false。所以不会更新任何内容,也不会生成错误。只需更新这里是更新的代码。 <?php session_start(); include('config.php'); if(isset($_POST['Submit'])) { $city = $_POST['city']; $from_station = $_POST['from_station']; $from_date = $_POST['from_date']; // Prepare and execute the SQL query $sql = "INSERT INTO journeys (city, from_station, from_date) VALUES ('$city', '$from_station', '$from_date')"; $result = $conn->query($sql); if (mysqli_query($conn, $sql)) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . mysqli_error($conn); } } ?> <!DOCTYPE html> <html lang="pt_PT"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>IR PLANNER</title> <link rel="stylesheet" href="Styles\general_styles.css"> <link rel="stylesheet" href="Styles\citymanager_styles.css"> </head> <body> <form class="modal" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <label for="city">City:</label> <input type="text" name="city" id="city"> <label for="from_station">From Station:</label> <input type="text" name="from_station" id="from_station"> <label for="from_date">From Date:</label> <input type="date" name="from_date" id="from_date"> <input type="submit" name="Submit" value="Submit" id="Submit"> </form> </body> </html> 以下是您必须采取的基本调试步骤: 执行过程中出现错误。请参阅此答案中的详细说明。 由于程序逻辑不正确,SQL根本没有运行。添加临时调试输出以确保代码到达查询执行的位置(这是提交输入时出现的特定问题,但这不是重点)。 SQL执行成功,但在错误的数据库中查看结果。仔细检查一下 输入的数据与数据库不匹配。以下是一些关于如何检查的建议。

回答 2 投票 0

Laravel 雄辩和简单的数据库查询

Laravel 9.pнp 8.0。 任务是逐行写入一个数组。你能告诉我为什么用这种形式的 eloquent 写法不起作用,而用 DB select 写法却可以正常工作。我的问题是什么?我...

回答 1 投票 0

唯一索引或主键违规,在 Spring Boot JPA 项目中

org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException:唯一索引或主键违规:“PRIMARY KEY ON PUBLIC.CR_BOOK_DTL(BOOK_ID) (/* key:0 */ 0, NULL, NULL, NULL)”; SQL 状态...

回答 1 投票 0

如何在查询中连接 2 列(where)[重复]

我正在使用 _GET 字符串从 1 个表中的 2 列生成产品详细信息 示例 URL ...details.php?string=column1column2 问题就出在这里: $string = $_GET['$string'] ..."SELECT * FROM ...

回答 1 投票 0

如何使用 PDO 实现简单的分页

if (isset($_GET['page_no']) && $_GET['page_no']!="") { $page_no = $_GET['page_no']; } 别的 { $page_no = 1; } $total_records_per_page = 9; $offset = ($page_n...

回答 1 投票 0

MySQLi 中的 SELECT * FROM

我的网站相当广泛,而且我最近刚刚切换到 PHP5(请叫我大器晚成)。 我之前的所有 MySQL 查询都是这样构建的: “SELECT * FROM 表名 WHERE field1 = 'value...

回答 7 投票 0

插入数据库不起作用

当我想从 PHP 表单向我的数据库插入一些数据时遇到问题。 这是我的代码: 当我想从 PHP 表单向我的库插入一些数据时遇到问题。 这是我的代码: <?php $ref=$_POST['ref']; $desig=$_POST['desig']; $ht=$_POST['ht']; $ttc=$_POST['ttc']; $prixfttc=$_POST['prixfttc']; $qte=$_POST['qte']; $rabais=$_POST['rabais']; $caract=$_POST['caract']; $img=$_POST['img']; $connexion=mysqli_connect("localhost","root","","artimaroc"); $query="INSERT INTO artimaroc.produits (`REF`,`DESIGNATION`,`HT`,`TTC`,`pfttc`,`qte`,`rabais`,`caracteristique`,`image`) VALUES ('$ref','$desig','$ht','$ttc','$prixfttc','$qte','$rabais','$caract','$img')"; $rep=mysqli_query($connexion,$query); if($rep==true) echo "done"; ?> 这是代码 <?php $ref=$_POST['ref']; $desig=$_POST['desig']; $ht=$_POST['ht']; $ttc=$_POST['ttc']; $prixfttc=$_POST['prixfttc']; $qte=$_POST['qte']; $rabais=$_POST['rabais']; $caract=$_POST['caract']; $img=$_POST['img']; $connexion=mysqli_connect("localhost","root","","artimaroc"); $query="INSERT INTO artimaroc.produits (`REF`,`DESIGNATION`,`HT`,`TTC`,`pfttc`,`qte`,`rabais`,`caracteristique`,`image`) VALUES ('$ref','$desig','$ht','$ttc','$prixfttc','$qte','$rabais','$caract','$img')"; $rep=mysqli_query($connexion,$query); if($rep==true) echo "done"; ?>

回答 1 投票 0

准备好的查询本地主机将数据插入数据库,但不在实时服务器上

我有下面准备好的语句,它在本地主机上运行良好,但是当它在网络服务器上运行时,它不会在数据库中插入数据而没有任何错误。 $insertbuyer = $conn->准备("

回答 0 投票 0

将 MySQL 中的数据显示为 HTML

` 带数据库的表 ` Table with Database <?php // Replace these credentials with your actual MySQL database details $host = 'localhost'; $username = 'root'; $password = ''; $dbname = 'khb_db'; // Create a new MySQLi connection $conn = new mysqli($host, $username, $password, $dbname); // Check connection if ($conn -> connect_error) { die("Connection failed: ".$conn->connect_error); } // Query to fetch data from the database $sql = "SELECT `Sl.No`, `Site No`, `Site Type`, `Owner's Name`, `Contact Number`, `Address` FROM purchasers_contact_details"; // Execute the query $result = $conn->query($sql); // Check if there are any results if ($result->num_rows > 0) { // Start building the HTML table echo '<table>'; echo '<tr><th>Sl.No</th><th>Site No</th><th>Site Type</th><th>Owner\'s Name</th><th>Contact Number</th><th>Address</th></tr>'; // Loop through the result set and display the data in the table while ($row = $result->fetch_assoc()) { echo '<tr>'; echo '<td>' . $row["Sl.No"] . '</td>'; echo '<td>' . $row["Site No"] . '</td>'; echo '<td>' . $row["Site Type"] . '</td>'; echo '<td>' . $row["Owner's Name"] . '</td>'; echo '<td>' . $row["Contact Number"] . '</td>'; echo '<td>' . $row["Address"] . '</td>'; echo '</tr>'; } // End the table echo '</table>'; } else { // If there are no results, display the "0 results" message echo '0 results'; } // Close the MySQL connection $conn->close(); 我已经尝试了所有可能的解决方案,也尝试了 ChatGPT,但似乎没有任何效果? 只是填补空白,以便我可以发布我的问题。预先感谢您的回复 只是填补空白,以便我可以发布我的问题。预先感谢您的回复 只是填补空白,以便我可以发布我的问题。预先感谢您的回复 只是填补空白,以便我可以发布我的问题。先谢谢您的回复` 只是填补空白,以便我可以发布我的问题。先谢谢您的回复

回答 0 投票 0

如何在 PHP 中根据 root 将用户重定向到不同的页面?

整个网站是用PHP构建的。 我正在研究自己的项目路线。路线链接未正确连接(1)。正确的话,链接将像这样 (2)。但我没能捕捉到迷雾...

回答 0 投票 0

如何在 PHP 中更改 MySQLi 时区

我不知道如何更改报告的时间。我正在使用 PHP 和 MySQLi。我的主机 SiteGround 的 MySQLi 系统记录的时间与我所在时区的时间不同,相差 +2 小时。他们说cann...

回答 0 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.