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

时间:2016-06-03 06:29:05

标签: php mysql sql mysqli

我在php到update执行mysqli_query()查询,但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

1 个答案:

答案 0 :(得分:0)

应该在PHP中运行

double[] imArr = im.getData().getPixels(0, 0, imWidth, imHeight, (double[])null) ;

只需删除反引号,PHP就不喜欢它们了