使用PHP从SQL获取行(Get row from SQL with PHP)
我使用以下方法从我的SQL数据库中查询:
function query() { global $link; $debug = false; //get the sql query $args = func_get_args(); $sql = array_shift($args); //secure the input for ($i=0;$i<count($args);$i++) { $args[$i] = urldecode($args[$i]); $args[$i] = mysqli_real_escape_string($link, $args[$i]); } //build the final query $sql = vsprintf($sql, $args); if ($debug) print $sql; //execute and fetch the results $result = mysqli_query($link, $sql); if (mysqli_errno($link)==0 && $result) { $rows = array(); if ($result!==true) while ($d = mysqli_fetch_assoc($result)) { array_push($rows,$d); } //return json return array('result'=>$rows); } else { //error return array('error'=>'Database error'); } } $result = $result = query("SELECT * FROM users WHERE email='$email' limit 1"); $name = (what goes here?)我想从用户那里获取字符串名称,我该怎么做?
I am using the following method to query from my SQL database:
function query() { global $link; $debug = false; //get the sql query $args = func_get_args(); $sql = array_shift($args); //secure the input for ($i=0;$i<count($args);$i++) { $args[$i] = urldecode($args[$i]); $args[$i] = mysqli_real_escape_string($link, $args[$i]); } //build the final query $sql = vsprintf($sql, $args); if ($debug) print $sql; //execute and fetch the results $result = mysqli_query($link, $sql); if (mysqli_errno($link)==0 && $result) { $rows = array(); if ($result!==true) while ($d = mysqli_fetch_assoc($result)) { array_push($rows,$d); } //return json return array('result'=>$rows); } else { //error return array('error'=>'Database error'); } } $result = $result = query("SELECT * FROM users WHERE email='$email' limit 1"); $name = (what goes here?)I am trying to get the string name from users, how can I do this?
最满意答案
如果您的查询是正确的
尝试这个:
function query() { global $link; $debug = false; //get the sql query $args = func_get_args(); $sql = array_shift($args); //secure the input for ($i=0;$i<count($args);$i++) { $args[$i] = urldecode($args[$i]); $args[$i] = mysqli_real_escape_string($link, $args[$i]); } //build the final query $sql = vsprintf($sql, $args); if ($debug) print $sql; //execute and fetch the results $result = mysqli_query($link, $sql); if (mysqli_errno($link)==0 && $result) { $rows = array(); if ($result!==true) while ($d = mysqli_fetch_assoc($result)) { array_push($rows,$d); } //return json return array('result'=>$rows); } else { //error return array('error'=>'Database error'); } } $result = query("SELECT * FROM users WHERE email='$email' limit 1"); $name = $result['result'][0]['name'];If your query is right then
try this:
function query() { global $link; $debug = false; //get the sql query $args = func_get_args(); $sql = array_shift($args); //secure the input for ($i=0;$i<count($args);$i++) { $args[$i] = urldecode($args[$i]); $args[$i] = mysqli_real_escape_string($link, $args[$i]); } //build the final query $sql = vsprintf($sql, $args); if ($debug) print $sql; //execute and fetch the results $result = mysqli_query($link, $sql); if (mysqli_errno($link)==0 && $result) { $rows = array(); if ($result!==true) while ($d = mysqli_fetch_assoc($result)) { array_push($rows,$d); } //return json return array('result'=>$rows); } else { //error return array('error'=>'Database error'); } } $result = query("SELECT * FROM users WHERE email='$email' limit 1"); $name = $result['result'][0]['name'];更多推荐
发布评论