gpt4 book ai didi

php - 更新sql查询不会通过php中的mysqli_query()更新记录

转载 作者:行者123 更新时间:2023-11-29 20:56:15 25 4
gpt4 key购买 nike

我通过mysqli_query()在php中执行update查询,但是update查询不更新记录在 php 脚本中,虽然相同的查询在 phpmyadmin 内运行时确实更新记录...为什么?查询结果为1,没有错误。示例:

UPDATE `tarex_yhibu` SET `phone` = '7777777777' 
WHERE url = "http://protechautoglass.com/".

脚本

<?php
$start=microtime(true);
include('../lib.php');
include('../lib/dbconnection.php');

echo '<hr>';
$db_handler = init_db();
echo 'db connection is ok!<br />';
// var_dump($db_handler);
try {
$records = getTableFields($db_handler, 'tarex_yhibu', ['id','url'], 'phone="" limit 1');
// echo '<pre>' . print_r($records, true) . '</pre>';

} catch (Exception $e) {
echo 'exception: ', $e->faultstring;
}

// $res=get_web_page($urls[0]);
$regex='/tel:([+\d]+)/';
echo '<table border=1><tr><th>Url</th><th>Phone</th><th>dump</th><tr>';
foreach($records as $record){
$res=get_web_page($record['url']);
preg_match($regex, $res['content'], $matches);
echo '<tr><td>', $record['url'], '</td><td><b> ' , print_r($matches[1], true), '</b></td><td><b> ' , var_dump($matches[1] ) , '</b></td></tr>';
settype($matches[1], 'string');
$phone = (string)$matches[1];
settype($record['url'], 'string');
UpdateRecord($db_handler, 'tarex_yhibu', 'phone', $phone, 'url = "' . $record['url'] . '" ' );
}
echo '</tr></table>';
echo '<br >Script execution time ' , round((microtime(true) - $start), 1), ' seconds.'; //value in seconds

dbconnection.php

    function UpdateRecord($db_handler, $tableName, $field, $value, $condition = '1 = 0' )// we set the false condition to prevent occasional update of all the records (when WHERE <condition> is missing)
{
$query = "UPDATE `{$tableName}` SET `{$field}` = '{$value}' WHERE {$condition} ";
$result = mysqli_query($db_handler, $query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysqli_error($db_handler));
if (!$result) {
echo '<br />Update query - Could not run query: ' . mysql_error();
exit;
} else
echo '<br />Result: ', $result;
echo '<br />Query: ', $query;
printf("<br />Affected rows (by UPDATE query): ", mysqli_affected_rows($db_handler), '</br>');
}

用户srv50213_igor的用户权限正常,参见截图:http://joxi.net/gmvjN1qsx3Xjbm

有什么问题吗?

更新

我已将 " 更改为 ' 并删除了反引号,但没有效果: http://joxi.ru/bmoOyo7IQygKmy

最佳答案

这应该在 PHP 中工作

$query = "UPDATE tarex_yhibu SET phone = '7777777777' WHERE url = 'http://protechautoglass.com/';";

只需删除反引号即可,PHP 不喜欢它们

关于php - 更新sql查询不会通过php中的mysqli_query()更新记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37607374/

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