drls2738 2015-01-14 21:16
浏览 32

mysqli_connect不会传递给它的函数

I am conventing old mysql to mysqli and run into a problem, which is that my mysqli_connect will not work in any my functions. after looking on the internet I found that it was a scope problems so i passed the mysqli_connect variable on to the function. which did not work. here are my two error

Notice: Undefined variable: con in C:\xampp\htdocs\bear_mysqli\functions\cart.php on line 44

Warning: Missing argument 1 for products(), called in C:\xampp\htdocs\bear_mysqli\shop.php on line 30 and defined in C:\xampp\htdocs\bear_mysqli\functions\cart.php on line 40

$con = mysqli_connect("localhost","root","","bear") or die ($connect_error);

function products($con)
{


    $get = mysqli_query($con,'SELECT * FROM items WHERE quantity > 0 ORDER BY id DESC ');
}
  • 写回答

1条回答 默认 最新

  • douxunwei7083 2015-03-24 16:53
    关注
    function f1(){
      $get = mysqli_query($GLOBALS['con'], "SELECT * FROM location");
    }
    

    If you write $GLOBALS['con'] then $con variable is treated as global so you can use it now in any function.

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀