使用PHP从SQL获取行(Get row from SQL with PHP)

编程入门 行业动态 更新时间:2024-10-25 02:29:42
使用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'];

更多推荐

本文发布于:2023-07-28 23:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1310153.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:PHP   SQL   row

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!