php - 双引号内的单引号php

标签 php mysql

我正在更新我正在使用的脚本,从使用硬编码日期到使用配置文件中的常量。在我到达以下位之前,一切正常。

原创:

function getDestroyedRelationships($relation){
$owner_user_id = $_REQUEST['owner_user_id'];
$tableName = "";
if($relation=="friends"){
    $tableName = "yst_twitter_following_relationships";
}else if($relation=="followers"){
    $tableName = "yst_twitter_follower_relationships";
}else{
    return false;
}
$twitters = NULL;
$stmt = ulPdoDb::Prepare('log', 'SELECT your_id FROM '.$tableName.' WHERE my_id=? AND updated_on<(SELECT MAX(updated_on) FROM '.$tableName.' WHERE my_id=?)');
if (!ulPdoDb::BindExec(
    $stmt,
    array(      // output
        &$twitters, 'lob'
    ),
    array(      // input
        &$owner_user_id, 'int',
        &$owner_user_id, 'int'
    )
))
{
    ul_db_fail();
    return false;
}

if ($twitters = $stmt->fetchAll(PDO::FETCH_COLUMN))
{
    return $twitters;
}
else
{
    //echo "Nothing";
}
return $twitters;
}

正如您在上面看到的那样,$tablename 定义了表前缀“yst”。我想将“yst”更改为:

'.TABLE_PREFIX'

但是在执行此操作时出现以下错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''.TABLE_PREFIX.'_twitter_following_relationships (my_id, your_id, created_on, up'

我怀疑这与双引号旁边的单引号有关吗?

有什么建议吗? 谢谢

最佳答案

假设 TABLE_PREFIX 是您在某处定义的常量,只需执行以下操作:

    $tableName = TABLE_PREFIX.'_twitter_following_relationships';

关于php - 双引号内的单引号php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20941750/

相关文章:

php - 如何在同一台服务器上内部连接两个不同 mysql 数据库中的两个表?

php - 我应该如何使用 Zend Framework 创建我的 HTML5 Manifest?

php - 如何对单个表中的多行进行分组并获取给定范围内的所有记录

php - codeigniter 传递数组进行查询

php - 如何使用phpStorm从远程服务器删除文件

php - 没有重复字符的Mysql正则表达式搜索

mysql - 如何避免连接表出现重复行。 (如何使用它)?

php - cakephp bake SQLSTATE[HY000] [2002] 没有那个文件或目录

mysql - 如何在MySQL表中选择每1000转

PHP SELECT 表现得很奇怪