duandu6497 2013-08-30 10:20
浏览 50
已采纳

mysql选择oop php

This is my oop php code for connection for my database. But how can i do the SELECT function. i wanna show data in my page from database. help me with this

class createConnection //create a class for make connection
{
    var $host = "localhost";
    var $username = "root"; // specify the sever details for mysql
    var $password = "";
    var $database = "akpGroup";
    var $myconn;

    function connectToDatabase() // create a function for connect database
    {
        $conn = mysql_connect($this->host, $this->username, $this->password);
        if (!$conn) // testing the connection
        {
            die ("Cannot connect to the database");
        } else {
            $this->myconn = $conn;
            echo "Connection established";
        }

        return $this->myconn;
    }

    function selectDatabase() // selecting the database.
    {
        mysql_select_db($this->database); //use php inbuild functions for select database
        if (mysql_error()) // if error occured display the error message
        {
            echo "Cannot find the database " . $this->database;
        }
        echo "Database selected..";
    }

    function closeConnection() // close the connection
    {
        mysql_close($this->myconn);
        echo "Connection closed";
    }
  • 写回答

2条回答 默认 最新

  • dragon0118 2013-08-30 10:25
    关注

    May be something like this

    $link = mysql_connect('localhost','root','yourPassword')
    mysql_select_db('database_name', $link);
    $sql = 'SELECT column FROM tablename';
    $result = mysql_query($sql, $link) or die(mysql_error());
    $row = mysql_fetch_assoc($result);
    print_r($row);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题