PHP database connection class

后端 未结 6 1984
名媛妹妹
名媛妹妹 2020-12-08 05:29

I am trying to get a users ID from a database within a class, but I have very little to no experience with classes, how could I go about getting the uid from the DB and then

6条回答
  •  旧巷少年郎
    2020-12-08 06:19

    There is a problem with the way your code is written, not with the class. Take a closer look at this line:

    $array = mysql_fetch_array($result);
    

    This is the first time variable $result appears on the function. Therefore, it is not possible to communicate with the database.

    A possible pseudo-code would be:

    • connect to the DB server
    • query the database
    • fetch the results
    • return the uid field.

    Have a look at the relevant documentation first:

    • http://php.net/manual/en/function.mysql-connect.php
    • http://www.php.net/manual/en/function.mysql-query.php
    • http://www.php.net/manual/en/function.mysql-fetch-array.php

提交回复
热议问题