Mysql string gets truncated on select

时间:2017-08-04 13:03:06

标签: php mysql

I can't figure out why when i try to select a string from a database it throws an error and truncated the string. The code I'm using is:

<?php define('something_made_for_security', true); include('mysql.php');
if(!sqlConnect()) die();

echo $_COOKIE['key'];
$currSession = Query('SELECT * FROM {sessioni} WHERE uid = 1 AND key = {0}', $_COOKIE['key']); //Queries the datatabase

if(NumRows($currSession)) { //Get number of rows
    $cuser = Fetch(Query('SELECT * FROM {utenti} WHERE nome = '.$_COOKIE['uid']));
    print_r($cuser);
}

Output of this is: http://prntscr.com/g4bkgs . Looks like the issue is not php-specific, since it does the same in PhpMyAdmin.

So why is the string truncated. Field 'key' is char(128) for a SHA512 hash.

By edit: i forgot that "key" was a keyword and i generally do not encapse strings.

1 个答案:

答案 0 :(得分:0)

试试这个

$currSession = Query('SELECT * FROM {sessioni} WHERE uid = 1 AND `key` = {0}', $_COOKIE['key']); //Queries the datatabase