使用PDO更新数据库时出错.我是PDO的新手所以也许这个问题很小,我只是不明白. 关于错误的有趣的事情,命令工作正常,数据库确实得到更新. 但它仍然会向我返回一个错误.
码:
try {
$stmt = $pdo->prepare("UPDATE $page SET $section = :new_content WHERE $section = '$old_content'");
$stmt->execute(array(
'new_content' => $new_content
));
$result = $stmt->fetchAll();
echo "Database updated!";
}
catch(PDOException $e) {
echo 'ERROR UPDATING CONTENT: ' . $e->getMessage();
}
Run Code Online (Sandbox Code Playgroud)
错误: ERROR UPDATING CONTENT:SQLSTATE [HY000]:一般错误
我真的不知道问题出在哪里,因为它非常不透明,我无法找到任何有同样问题的人.
我最近配置了 VS code 以使用 xdebug 调试 PHP。它与我的应用程序代码一起可靠地工作,但是当我使用 PHPunit 运行单元测试时,我的断点被忽略。
我的服务器在一个流浪盒子内运行。
我的php.ini文件包含以下几行:
[xdebug]
zend_extension="/usr/lib/xdebug/xdebug-2.2.7/modules/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.remote_connect_back=1
xdebug.remote_autostart=1
Run Code Online (Sandbox Code Playgroud)
我使用PHP 调试VS 代码扩展。
这是我的launch.json配置:
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"pathMappings": {
"/var/www/mysite.local/": "${workspaceFolder}"
},
"port": 9000,
"log": true
}
Run Code Online (Sandbox Code Playgroud)
我的单元测试运行良好,例如,从内部/var/www/mysite.local,我可以运行:
phpunit --filter myTestMethod path/to/my/test/file/myTest.php
Run Code Online (Sandbox Code Playgroud)
但是当测试运行时,测试本身中的断点始终被忽略,我无法弄清楚为什么。
有人遇到过类似的问题吗?在正常应用程序请求和单元测试的上下文中调试的工作方式是否有区别?
这里我有一个简单的PHP脚本,它以json格式显示数据库中的一些值.
$source = $_GET['source'];
$query = mysql_query("SELECT * FROM images WHERE big_thumb = '" . $source . "'");
$results = array();
while($row = mysql_fetch_array($query))
{
$results[] = array(
'title' => $row['title'],
'date' => $row['upload_date'],
'time' => $row['upload_time']
);
}
$json = json_encode($results);
echo $json;
Run Code Online (Sandbox Code Playgroud)
这显示正常,继承人输出示例:
[{"title":"Torus","date":"2012-04-04","time":"23:06:14"}]
Run Code Online (Sandbox Code Playgroud)
然后,当单击图像时,将调用此jquery:
var image_src = $(this).attr("alt"); // <= This works fine
$.ajax({
url: 'inc/get_image_details.php',
data: {source : image_src},
dataType: "json",
success: function(data)
{
title = data.title;
alert(title);
date = data.date;
alert(date);
time = data.time;
alert(time); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Backbone.js将一个集合保存到我的数据库,并在我的服务器上运行SLIM php框架.
这是我的收藏:
var newUser = this.collection.create(
formData,
{
wait: true,
success: $.proxy(function() {
this.collection.currentUser = newUser;
App.Router.navigate('', { trigger: true });
}, this)
}
);
Run Code Online (Sandbox Code Playgroud)
这是我的SLIM路线:
$api->post('/users', function() use($api, $db) {
$request = $api->request()->post();
$api->response()->header('Content-Type', 'application/json');
$result = $db->users()->insert($user);
if( $result ) {
echo json_encode(array(
'id' => $result['id']
));
}
else {
echo json_encode(array(
'status' => false,
'message' => 'error_creating_user'
));
}
});
$api->run();
Run Code Online (Sandbox Code Playgroud)
在调用create()我的集合时,我在服务器的响应中收到了弃用警告:
Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future …
我在尝试反序列化数据时遇到错误.发生以下错误:
unserialize(): Error at offset 46 of 151 bytes
Run Code Online (Sandbox Code Playgroud)
这是序列化数据:
s:151:"a:1:{i:0;a:4:{s:4:"name";s:15:"Chloe O'Gorman";s:6:"gender";s:6:"female";s:3:"age";s:3:"3_6";s:7:"present";s:34:"Something from Frozen or a jigsaw ";}}";
Run Code Online (Sandbox Code Playgroud)
该错误是由数据中的单引号引起的.当我正在使用的站点和数据库已经存在时,如何缓解此问题?不幸的是,我无法重写负责序列化和将数据插入数据库的代码.整个数据库很可能出现此问题.
有没有我可以用来逃避数据的函数?